[PATCH] D149912: [clangd] downgrade missing-includes diagnostic to Information level

2023-05-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149912/new/

https://reviews.llvm.org/D149912

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-05-12 Thread Jun Zhang via Phabricator via cfe-commits
junaire marked 10 inline comments as done.
junaire added inline comments.



Comment at: clang/include/clang/Interpreter/Value.h:160-162
+  // Interpreter, QualType are stored as void* to reduce dependencies.
+  void *Interp = nullptr;
+  void *OpaqueType = nullptr;

v.g.vassilev wrote:
> sgraenitz wrote:
> > v.g.vassilev wrote:
> > > aaron.ballman wrote:
> > > > junaire wrote:
> > > > > aaron.ballman wrote:
> > > > > > v.g.vassilev wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > v.g.vassilev wrote:
> > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > Why don't forward declares suffice if we're storing the 
> > > > > > > > > > information by pointer?
> > > > > > > > > This is a performance-critical class. We literally measure 
> > > > > > > > > the instruction count for it. We practically cannot include 
> > > > > > > > > anything in this header file because the class needs to 
> > > > > > > > > included as part of the interpreter runtime. For example:
> > > > > > > > > 
> > > > > > > > > ```
> > > > > > > > > #include 
> > > > > > > > > Value ResultV;
> > > > > > > > > gInterpreter->evaluate("float i = 12.3; i++", &V);
> > > > > > > > > printf("Value is %d\n", ResultV.castAs());
> > > > > > > > > ```
> > > > > > > > > 
> > > > > > > > > This is how you can do things in Cling. This not yet there 
> > > > > > > > > but that's our next step.
> > > > > > > > > 
> > > > > > > > > For performance reasons we have the `ValueKind` optimization 
> > > > > > > > > which allows us to perform most of the operations we need 
> > > > > > > > > very fast. There are some operations such as printing the 
> > > > > > > > > concrete type which need the actual `QualType` and so on but 
> > > > > > > > > they are outside of the performance critical paths and it is 
> > > > > > > > > okay to resort back to the real types providing the level of 
> > > > > > > > > accuracy we need.
> > > > > > > > > 
> > > > > > > > That sounds like it's going to lead to maintenance problems in 
> > > > > > > > the long term, right? I can't think of another header file we 
> > > > > > > > say "don't touch this because it may impact runtime 
> > > > > > > > performance", and so I can easily imagine someone breaking your 
> > > > > > > > expectation that this file can't include anything else.
> > > > > > > > 
> > > > > > > > Is there a long-term plan for addressing this?
> > > > > > > We have a few components like the Lexer that are extremely prone 
> > > > > > > to performance regressions.
> > > > > > > 
> > > > > > > In terms for a longer-term plan in addressing this there are some 
> > > > > > > steps could help IMO. First, this component is relatively 
> > > > > > > standalone and very few changes will be required over time, for 
> > > > > > > these I am hoping to be listed as a reviewer. Second, we can add 
> > > > > > > a comment in the include area, making a note that including 
> > > > > > > anything here will degrade the performance of almost all 
> > > > > > > interpreted code. Third, we will find out about this in our 
> > > > > > > downstream use-cases as the things get significantly slower.
> > > > > > > 
> > > > > > > Neither is silver bullet but that's probably the best we could do 
> > > > > > > at that time. Btw, we might be able to add a test that's part of 
> > > > > > > LLVM's performance analysis infrastructure.
> > > > > > > Neither is silver bullet but that's probably the best we could do 
> > > > > > > at that time. Btw, we might be able to add a test that's part of 
> > > > > > > LLVM's performance analysis infrastructure.
> > > > > > 
> > > > > > Yeah, we should probably consider doing that. But to make sure I 
> > > > > > understand the performance concerns... when we change functionality 
> > > > > > in the lexer, we (potentially) slow down the lexing phase of 
> > > > > > compilation. That's straightforward and unsurprising. But in this 
> > > > > > case, it sounds like the act of including another header file in 
> > > > > > this header file will cause a runtime performance concern, even if 
> > > > > > no other changes are made. If I'm correct, I can't think of 
> > > > > > anything else in the compiler that works like that.
> > > > > I believe what @v.g.vassilev means is that the repl itself might 
> > > > > include `Value.h` as a part of *runtime*, so if the header is heavy, 
> > > > > you can notice the repl is slowed down. (That's obvious) So keep in 
> > > > > mind we're breaking the boundary between the compiled code and 
> > > > > interpreted code (It's kinda confusing) here it actually impacts 
> > > > > interpreted code.
> > > > > I believe what @v.g.vassilev means is that the repl itself might 
> > > > > include Value.h as a part of *runtime*, so if the header is heavy, 
> > > > > you can notice the repl is slowed down. (That's obvious) So keep in 
> > > > > mind we're breaking the boundary between the compiled code and 
> > > > > interpreted code (It's kinda c

[PATCH] D128612: RISC-V big-endian support implementation

2023-05-12 Thread Djordje Todorovic via Phabricator via cfe-commits
djtodoro added a comment.
Herald added a subscriber: luke.

Hi! I wondering if someone knows what is the status of this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128612/new/

https://reviews.llvm.org/D128612

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 80a21ea - [clang][analyzer] Cleanup tests of StdCLibraryFunctionsChecker (NFC)

2023-05-12 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2023-05-12T09:54:01+02:00
New Revision: 80a21ea8006fe7bc7ae2b1c9381625aa69b4dace

URL: 
https://github.com/llvm/llvm-project/commit/80a21ea8006fe7bc7ae2b1c9381625aa69b4dace
DIFF: 
https://github.com/llvm/llvm-project/commit/80a21ea8006fe7bc7ae2b1c9381625aa69b4dace.diff

LOG: [clang][analyzer] Cleanup tests of StdCLibraryFunctionsChecker (NFC)

Function declarations are moved into common header that can be reused
to avoid repetitions in different test files.
Some small problems in the tests were found and fixed.

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D149158

Added: 
clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h
clang/test/Analysis/Inputs/std-c-library-functions.h

Modified: 
clang/test/Analysis/std-c-library-functions-POSIX.c
clang/test/Analysis/std-c-library-functions-arg-constraints.c
clang/test/Analysis/std-c-library-functions.c

Removed: 




diff  --git a/clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h 
b/clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h
new file mode 100644
index 0..942c918c3da2f
--- /dev/null
+++ b/clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h
@@ -0,0 +1,181 @@
+#include "std-c-library-functions.h"
+
+typedef int off_t;
+typedef unsigned int mode_t;
+typedef __WCHAR_TYPE__ wchar_t;
+typedef unsigned int dev_t;
+typedef unsigned int uid_t;
+typedef unsigned int gid_t;
+typedef unsigned long socklen_t;
+typedef unsigned long int pthread_t;
+typedef unsigned long time_t;
+typedef unsigned long clockid_t;
+typedef __INT64_TYPE__ off64_t;
+
+typedef struct {
+  int a;
+} DIR;
+struct stat {
+  int a;
+};
+struct timespec { int x; };
+struct timeval { int x; };
+struct sockaddr;
+struct sockaddr_at;
+struct msghdr;
+struct utimbuf;
+struct itimerval;
+typedef union {
+  int x;
+} pthread_cond_t;
+typedef union {
+  int x;
+} pthread_attr_t;
+typedef union {
+  int x;
+} pthread_mutex_t;
+typedef union {
+  int x;
+} pthread_mutexattr_t;
+
+FILE *fopen(const char *restrict pathname, const char *restrict mode);
+FILE *tmpfile(void);
+FILE *freopen(const char *restrict pathname, const char *restrict mode,
+  FILE *restrict stream);
+int fclose(FILE *stream);
+int fseek(FILE *stream, long offset, int whence);
+int fileno(FILE *stream);
+long a64l(const char *str64);
+char *l64a(long value);
+int access(const char *pathname, int amode);
+int faccessat(int dirfd, const char *pathname, int mode, int flags);
+int dup(int fildes);
+int dup2(int fildes1, int filedes2);
+int fdatasync(int fildes);
+int fnmatch(const char *pattern, const char *string, int flags);
+int fsync(int fildes);
+int truncate(const char *path, off_t length);
+int symlink(const char *oldpath, const char *newpath);
+int symlinkat(const char *oldpath, int newdirfd, const char *newpath);
+int lockf(int fd, int cmd, off_t len);
+int creat(const char *pathname, mode_t mode);
+unsigned int sleep(unsigned int seconds);
+int dirfd(DIR *dirp);
+unsigned int alarm(unsigned int seconds);
+int closedir(DIR *dir);
+char *strdup(const char *s);
+char *strndup(const char *s, size_t n);
+wchar_t *wcsdup(const wchar_t *s);
+int mkstemp(char *template);
+char *mkdtemp(char *template);
+char *getcwd(char *buf, size_t size);
+int mkdir(const char *pathname, mode_t mode);
+int mkdirat(int dirfd, const char *pathname, mode_t mode);
+int mknod(const char *pathname, mode_t mode, dev_t dev);
+int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev);
+int chmod(const char *path, mode_t mode);
+int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags);
+int fchmod(int fildes, mode_t mode);
+int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int 
flags);
+int chown(const char *path, uid_t owner, gid_t group);
+int lchown(const char *path, uid_t owner, gid_t group);
+int fchown(int fildes, uid_t owner, gid_t group);
+int rmdir(const char *pathname);
+int chdir(const char *path);
+int link(const char *oldpath, const char *newpath);
+int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag);
+int unlink(const char *pathname);
+int unlinkat(int fd, const char *path, int flag);
+int fstat(int fd, struct stat *statbuf);
+int stat(const char *restrict path, struct stat *restrict buf);
+int lstat(const char *restrict path, struct stat *restrict buf);
+int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int 
flag);
+DIR *opendir(const char *name);
+DIR *fdopendir(int fd);
+int isatty(int fildes);
+FILE *popen(const char *command, const char *type);
+int pclose(FILE *stream);
+int close(int fildes);
+long fpathconf(int fildes, int name);
+long pathconf(const char *path, int name);
+FILE *fdopen(int fd, const char *mode);
+void rewinddir(DIR *dir);
+void seekdir(DIR *dirp, long loc);
+int rand_r(unsigned int *seedp);
+int fileno(FILE *stream);
+int fs

[PATCH] D149158: [clang][analyzer] Cleanup tests of StdCLibraryFunctionsChecker (NFC)

2023-05-12 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG80a21ea8006f: [clang][analyzer] Cleanup tests of 
StdCLibraryFunctionsChecker (NFC) (authored by balazske).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149158/new/

https://reviews.llvm.org/D149158

Files:
  clang/test/Analysis/Inputs/std-c-library-functions-POSIX.h
  clang/test/Analysis/Inputs/std-c-library-functions.h
  clang/test/Analysis/std-c-library-functions-POSIX.c
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions.c

Index: clang/test/Analysis/std-c-library-functions.c
===
--- clang/test/Analysis/std-c-library-functions.c
+++ clang/test/Analysis/std-c-library-functions.c
@@ -50,6 +50,9 @@
 // CHECK-NEXT: Loaded summary for: int isspace(int)
 // CHECK-NEXT: Loaded summary for: int isupper(int)
 // CHECK-NEXT: Loaded summary for: int isxdigit(int)
+// CHECK-NEXT: Loaded summary for: int toupper(int)
+// CHECK-NEXT: Loaded summary for: int tolower(int)
+// CHECK-NEXT: Loaded summary for: int toascii(int)
 // CHECK-NEXT: Loaded summary for: int getc(FILE *)
 // CHECK-NEXT: Loaded summary for: int fgetc(FILE *)
 // CHECK-NEXT: Loaded summary for: int getchar(void)
@@ -59,16 +62,14 @@
 // CHECK-NEXT: Loaded summary for: ssize_t write(int, const void *, size_t)
 // CHECK-NEXT: Loaded summary for: ssize_t getline(char **restrict, size_t *restrict, FILE *restrict)
 // CHECK-NEXT: Loaded summary for: ssize_t getdelim(char **restrict, size_t *restrict, int, FILE *restrict)
+// CHECK-NEXT: Loaded summary for: char *getenv(const char *)
 
+#include "Inputs/std-c-library-functions.h"
 
 void clang_analyzer_eval(int);
 
 int glob;
 
-typedef struct FILE FILE;
-#define EOF -1
-
-int getc(FILE *);
 void test_getc(FILE *fp) {
   int x;
   while ((x = getc(fp)) != EOF) {
@@ -77,17 +78,11 @@
   }
 }
 
-int fgetc(FILE *);
 void test_fgets(FILE *fp) {
   clang_analyzer_eval(fgetc(fp) < 256); // expected-warning{{TRUE}}
   clang_analyzer_eval(fgetc(fp) >= 0); // expected-warning{{UNKNOWN}}
 }
 
-
-typedef typeof(sizeof(int)) size_t;
-typedef signed long ssize_t;
-ssize_t read(int, void *, size_t);
-ssize_t write(int, const void *, size_t);
 void test_read_write(int fd, char *buf) {
   glob = 1;
   ssize_t x = write(fd, buf, 10);
@@ -106,8 +101,6 @@
   }
 }
 
-size_t fread(void *restrict, size_t, size_t, FILE *restrict);
-size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 void test_fread_fwrite(FILE *fp, int *buf) {
 
   size_t x = fwrite(buf, sizeof(int), 10, fp);
@@ -128,8 +121,6 @@
   (void)fread(ptr, sz, nmem, fp); // expected-warning {{1st function call argument is an uninitialized value}}
 }
 
-ssize_t getline(char **restrict, size_t *restrict, FILE *restrict);
-ssize_t getdelim(char **restrict, size_t *restrict, int, FILE *restrict);
 void test_getline(FILE *fp) {
   char *line = 0;
   size_t n = 0;
@@ -139,7 +130,6 @@
   }
 }
 
-int isascii(int);
 void test_isascii(int x) {
   clang_analyzer_eval(isascii(123)); // expected-warning{{TRUE}}
   clang_analyzer_eval(isascii(-1)); // expected-warning{{FALSE}}
@@ -157,7 +147,6 @@
   clang_analyzer_eval(glob); // expected-warning{{TRUE}}
 }
 
-int islower(int);
 void test_islower(int x) {
   clang_analyzer_eval(islower('x')); // expected-warning{{TRUE}}
   clang_analyzer_eval(islower('X')); // expected-warning{{FALSE}}
@@ -165,7 +154,6 @@
 clang_analyzer_eval(x < 'a'); // expected-warning{{FALSE}}
 }
 
-int getchar(void);
 void test_getchar(void) {
   int x = getchar();
   if (x == EOF)
@@ -174,27 +162,23 @@
   clang_analyzer_eval(x < 256); // expected-warning{{TRUE}}
 }
 
-int isalpha(int);
 void test_isalpha(void) {
   clang_analyzer_eval(isalpha(']')); // expected-warning{{FALSE}}
   clang_analyzer_eval(isalpha('Q')); // expected-warning{{TRUE}}
   clang_analyzer_eval(isalpha(128)); // expected-warning{{UNKNOWN}}
 }
 
-int isalnum(int);
 void test_alnum(void) {
   clang_analyzer_eval(isalnum('1')); // expected-warning{{TRUE}}
   clang_analyzer_eval(isalnum(')')); // expected-warning{{FALSE}}
 }
 
-int isblank(int);
 void test_isblank(void) {
   clang_analyzer_eval(isblank('\t')); // expected-warning{{TRUE}}
   clang_analyzer_eval(isblank(' ')); // expected-warning{{TRUE}}
   clang_analyzer_eval(isblank('\n')); // expected-warning{{FALSE}}
 }
 
-int ispunct(int);
 void test_ispunct(int x) {
   clang_analyzer_eval(ispunct(' ')); // expected-warning{{FALSE}}
   clang_analyzer_eval(ispunct(-1)); // expected-warning{{FALSE}}
@@ -204,21 +188,17 @@
 clang_analyzer_eval(x < 127); // expected-warning{{TRUE}}
 }
 
-int isupper(int);
 void test_isupper(int x) {
   if (isupper(x))
 clang_analyzer_eval(x < 'A'); // expected-warning{{FALSE}}
 }
 
-int isgraph(int);
-int isprint(int);
 void test_isgraph_isprint(int x) {
   char y = x;
   if (isgraph(y))
 clang_analyzer_eval(isprint(x)); 

[PATCH] D144943: [clang][Interp] Implement bitcasts (WIP)

2023-05-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 521574.
tbaeder marked 3 inline comments as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144943/new/

https://reviews.llvm.org/D144943

Files:
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Descriptor.h
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/lib/AST/Interp/PrimType.h
  clang/test/AST/Interp/builtin-bit-cast.cpp
  clang/test/AST/Interp/literals.cpp

Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -96,6 +96,11 @@
 static_assert(p != nullptr, "");
 static_assert(*p == 10, "");
 
+constexpr const void *cp = (void *)p;
+// FIXME: This should be an error in the new interpreter.
+constexpr const int *pm = (int*)cp; // ref-error {{ must be initialized by a constant expression}} \
+// ref-note {{cast from 'const void *' is not allowed}}
+
 constexpr const int* getIntPointer() {
   return &m;
 }
Index: clang/test/AST/Interp/builtin-bit-cast.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/builtin-bit-cast.cpp
@@ -0,0 +1,228 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify -std=c++2a -fsyntax-only %s
+// RUN: %clang_cc1 -verify=ref -std=c++2a -fsyntax-only %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple aarch64_be-linux-gnu -fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -verify -std=c++2a -fsyntax-only -triple aarch64_be-linux-gnu -fexperimental-new-constant-interpreter %s
+
+
+/// ref-no-diagnostics
+
+
+/// FIXME: This is a version of clang/test/SemaCXX/builtin-bit-cast.cpp with
+///   the currently supported subset of operations. They should *all* be
+///   supported though.
+
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#  define LITTLE_END 1
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#  define LITTLE_END 0
+#else
+#  error "huh?"
+#endif
+
+template  struct is_same {
+  static constexpr bool value = false;
+};
+template  struct is_same {
+  static constexpr bool value = true;
+};
+
+static_assert(sizeof(int) == 4);
+static_assert(sizeof(long long) == 8);
+
+template 
+constexpr To bit_cast(const From &from) {
+  static_assert(sizeof(To) == sizeof(From));
+  return __builtin_bit_cast(To, from);
+}
+
+template 
+constexpr bool round_trip(const Init &init) {
+  return bit_cast(bit_cast(init)) == init;
+}
+
+static_assert(round_trip((int)-1));
+static_assert(round_trip((int)0x12345678));
+static_assert(round_trip((int)0x87654321));
+static_assert(round_trip((int)0x0C05FEFE));
+static_assert(round_trip((int)0x0C05FEFE));
+
+constexpr unsigned char input[] = {0xCA, 0xFE, 0xBA, 0xBE};
+constexpr unsigned expected = LITTLE_END ? 0xBEBAFECA : 0xCAFEBABE;
+static_assert(bit_cast(input) == expected);
+
+constexpr short S[] = {10, 20};
+constexpr int I = __builtin_bit_cast(int, S);
+static_assert(I == (LITTLE_END ? 1310730 : 655380));
+
+
+struct int_splicer {
+  unsigned x;
+  unsigned y;
+
+  constexpr int_splicer() : x(1), y(2) {}
+  constexpr int_splicer(unsigned x, unsigned y) : x(x), y(y) {}
+
+  constexpr bool operator==(const int_splicer &other) const {
+return other.x == x && other.y == y;
+  }
+};
+
+constexpr int_splicer splice(0x0C05FEFE, 0xCAFEBABE);
+
+static_assert(bit_cast(splice) == (LITTLE_END
+   ? 0xCAFEBABE0C05FEFE
+   : 0x0C05FEFECAFEBABE));
+
+constexpr int_splicer IS = bit_cast(0xCAFEBABE0C05FEFE);
+static_assert(bit_cast(0xCAFEBABE0C05FEFE).x == (LITTLE_END
+  ? 0x0C05FEFE
+  : 0xCAFEBABE));
+
+static_assert(round_trip(splice));
+static_assert(round_trip(splice));
+
+struct base2 {
+};
+
+struct base3 {
+  unsigned z;
+  constexpr base3() : z(3) {}
+};
+
+struct bases : int_splicer, base2, base3 {
+  unsigned doublez;
+  constexpr bases() : doublez(4) {}
+};
+
+struct tuple4 {
+  unsigned x, y, z, doublez;
+
+  constexpr bool operator==(tuple4 const &other) const {
+return x == other.x && y == other.y &&
+   z == other.z && doublez == other.doublez;
+  }
+};
+constexpr bases b;// = {{1, 2}, {}, {3}, 4};
+constexpr tuple4 t4 = bit_cast(b);
+
+// Regardless of endianness, this should hold:
+static_assert(t4.x == 1);
+static_assert(t4.y == 2);
+static_assert(t4.z == 3);
+static_assert(t4.doublez == 4);
+//static_assert(t4 == tuple4{1, 2, 3, 4});
+static_assert(round_trip(b));
+
+
+namespace WithBases

[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

2023-05-12 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler updated this revision to Diff 521577.
ckandeler marked 2 inline comments as done.
ckandeler added a comment.

Addressed review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150124/new/

https://reviews.llvm.org/D150124

Files:
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/lib/Index/IndexBody.cpp
  clang/unittests/Index/IndexTests.cpp


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -218,6 +218,28 @@
   EXPECT_THAT(Index->Symbols, Not(Contains(QName("bar";
 }
 
+TEST(IndexTest, IndexLabels) {
+  std::string Code = R"cpp(
+int main() {
+  goto theLabel;
+  theLabel:
+return 1;
+}
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  Opts.IndexFunctionLocals = true;
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, AllOf(Contains(AllOf(QName("theLabel"),
+   WrittenAt(Position(3, 16)),
+   DeclAt(Position(4, 11));
+
+  Opts.IndexFunctionLocals = false;
+  Index->Symbols.clear();
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, Not(Contains(QName("theLabel";
+}
+
 TEST(IndexTest, IndexExplicitTemplateInstantiation) {
   std::string Code = R"cpp(
 template 
Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -144,6 +144,18 @@
 Parent, ParentDC, Roles, Relations, E);
   }
 
+  bool VisitGotoStmt(GotoStmt *S) {
+return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,
+ParentDC,
+unsigned(SymbolRole::NameReference));
+  }
+
+  bool VisitLabelStmt(LabelStmt *S) {
+if (IndexCtx.shouldIndexFunctionLocalSymbols())
+  return IndexCtx.handleDecl(S->getDecl());
+return true;
+  }
+
   bool VisitMemberExpr(MemberExpr *E) {
 SourceLocation Loc = E->getMemberLoc();
 if (Loc.isInvalid())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -127,6 +127,13 @@
   [Foo [[x]]:2 [[^y]]:4];
 }
   )cpp",
+  R"cpp( // Label
+int main() {
+  goto [[^theLabel]];
+  [[theLabel]]:
+return 1;
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);


Index: clang/unittests/Index/IndexTests.cpp
===
--- clang/unittests/Index/IndexTests.cpp
+++ clang/unittests/Index/IndexTests.cpp
@@ -218,6 +218,28 @@
   EXPECT_THAT(Index->Symbols, Not(Contains(QName("bar";
 }
 
+TEST(IndexTest, IndexLabels) {
+  std::string Code = R"cpp(
+int main() {
+  goto theLabel;
+  theLabel:
+return 1;
+}
+  )cpp";
+  auto Index = std::make_shared();
+  IndexingOptions Opts;
+  Opts.IndexFunctionLocals = true;
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, AllOf(Contains(AllOf(QName("theLabel"),
+   WrittenAt(Position(3, 16)),
+   DeclAt(Position(4, 11));
+
+  Opts.IndexFunctionLocals = false;
+  Index->Symbols.clear();
+  tooling::runToolOnCode(std::make_unique(Index, Opts), Code);
+  EXPECT_THAT(Index->Symbols, Not(Contains(QName("theLabel";
+}
+
 TEST(IndexTest, IndexExplicitTemplateInstantiation) {
   std::string Code = R"cpp(
 template 
Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -144,6 +144,18 @@
 Parent, ParentDC, Roles, Relations, E);
   }
 
+  bool VisitGotoStmt(GotoStmt *S) {
+return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,
+ParentDC,
+unsigned(SymbolRole::NameReference));
+  }
+
+  bool VisitLabelStmt(LabelStmt *S) {
+if (IndexCtx.shouldIndexFunctionLocalSymbols())
+  return IndexCtx.handleDecl(S->getDecl());
+return true;
+  }
+
   bool VisitMemberExpr(MemberExpr *E) {
 SourceLocation Loc = E->getMemberLoc();
 if (Loc.isInvalid())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-

[PATCH] D150430: Implement BufferOverlap check for sprint/snprintf

2023-05-12 Thread Arnaud Bienner via Phabricator via cfe-commits
ArnaudBienner created this revision.
Herald added subscribers: steakhal, martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
ArnaudBienner edited the summary of this revision.
ArnaudBienner added a subscriber: dergachev.a.
ArnaudBienner published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I discussed about this with you @dergachev.a a long time ago on the mailing 
list ("static or dynamic code analysis for undefined behavior in sprintf") and 
finally took the time to implement something :)

Let me know what you think about this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150430

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/buffer-overlap.c

Index: clang/test/Analysis/buffer-overlap.c
===
--- /dev/null
+++ clang/test/Analysis/buffer-overlap.c
@@ -0,0 +1,56 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=alpha.unix.cstring.BufferOverlap
+//
+// RUN: %clang_analyze_cc1 -verify %s -DUSE_BUILTINS \
+// RUN:   -analyzer-checker=alpha.unix.cstring.BufferOverlap
+//
+// RUN: %clang_analyze_cc1 -verify %s -DVARIANT \
+// RUN:   -analyzer-checker=alpha.unix.cstring.BufferOverlap
+//
+// RUN: %clang_analyze_cc1 -verify %s -DVARIANT -DUSE_BUILTINS \
+// RUN:   -analyzer-checker=alpha.unix.cstring.BufferOverlap
+
+// This provides us with four possible sprintf() definitions.
+
+#ifdef USE_BUILTINS
+#define BUILTIN(f) __builtin_##f
+#else /* USE_BUILTINS */
+#define BUILTIN(f) f
+#endif /* USE_BUILTINS */
+
+typedef typeof(sizeof(int)) size_t;
+
+#ifdef VARIANT
+
+#define __sprintf_chk BUILTIN(__sprintf_chk)
+#define __snprintf_chk BUILTIN(__snprintf_chk)
+int __sprintf_chk (char * __restrict str, int flag, size_t os,
+const char * __restrict fmt, ...);
+int __snprintf_chk (char * __restrict str, size_t len, int flag, size_t os,
+const char * __restrict fmt, ...);
+
+#define sprintf(str, ...) __sprintf_chk(str, 0, __builtin_object_size(str, 0), __VA_ARGS__)
+#define snprintf(str, len, ...) __snprintf_chk(str, len, 0, __builtin_object_size(str, 0), __VA_ARGS__)
+
+#else /* VARIANT */
+
+#define sprintf BUILTIN(sprintf)
+int sprintf(char *restrict buffer, const char *restrict format, ... );
+int snprintf(char *restrict buffer, size_t bufsz,
+ const char *restrict format, ... );
+#endif /* VARIANT */
+
+void test_sprintf1() {
+  char a[4] = {0};
+  sprintf(a, "%d/%s", 1, a); // expected-warning{{overlapping}}
+}
+
+void test_snprintf1() {
+  char a[4] = {0};
+  snprintf(a, sizeof(a), "%d/%s", 1, a); // expected-warning{{overlapping}}
+}
+
+void test_snprintf2() {
+  char a[4] = {0};
+  snprintf(a+1, sizeof(a)-1, "%d/%s", 1, a); // expected-warning{{overlapping}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -12,6 +12,7 @@
 //===--===//
 
 #include "InterCheckerAPI.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
@@ -175,6 +176,8 @@
std::bind(&CStringChecker::evalMemcmp, _1, _2, _3, CK_Regular)},
   {{CDF_MaybeBuiltin, {"bzero"}, 2}, &CStringChecker::evalBzero},
   {{CDF_MaybeBuiltin, {"explicit_bzero"}, 2}, &CStringChecker::evalBzero},
+  {{CDF_MaybeBuiltin, {"sprintf"}}, &CStringChecker::evalSprintf},
+  {{CDF_MaybeBuiltin, {"snprintf"}}, &CStringChecker::evalSnprintf},
   };
 
   // These require a bit of special handling.
@@ -228,6 +231,11 @@
   void evalMemset(CheckerContext &C, const CallExpr *CE) const;
   void evalBzero(CheckerContext &C, const CallExpr *CE) const;
 
+  void evalSprintf(CheckerContext &C, const CallExpr *CE) const;
+  void evalSnprintf(CheckerContext &C, const CallExpr *CE) const;
+  void evalSprintfCommon(CheckerContext &C, const CallExpr *CE, bool IsBounded,
+ bool IsBuiltin) const;
+
   // Utility methods
   std::pair
   static assumeZero(CheckerContext &C,
@@ -2352,6 +2360,61 @@
   C.addTransition(State);
 }
 
+void CStringChecker::evalSprintf(CheckerContext &C, const CallExpr *CE) const {
+  CurrentFunctionDescription = "'sprintf'";
+  bool IsBI = CE->getBuiltinCallee() == Builtin::BI__builtin___sprintf_chk;
+  evalSprintfCommon(C, CE, /* IsBounded */ false, IsBI);
+}
+
+void CStringChecker::evalSnprintf(CheckerContext &C, const CallExpr *CE) const {
+  CurrentFunctionDescription = "'snprintf'";
+  bool IsBI = CE->getBuiltinCallee() == Builtin::BI__builtin___snprintf_chk;
+  evalSprintfCommon(C, CE, /* IsBounded */ true, IsBI);
+}
+
+void CStringChecker::evalSprintfCommon(CheckerConte

[PATCH] D103930: [clang][HeaderSearch] Fix implicit module when using header maps

2023-05-12 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko updated this revision to Diff 521580.
ivanmurashko added a comment.

typo fixed + rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103930/new/

https://reviews.llvm.org/D103930

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Modules/implicit-module-header-maps.cpp


Index: clang/test/Modules/implicit-module-header-maps.cpp
===
--- /dev/null
+++ clang/test/Modules/implicit-module-header-maps.cpp
@@ -0,0 +1,54 @@
+// UNSUPPORTED: system-windows
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %hmaptool write a.hmap.json hmap
+//
+// RUN: %clang -Rmodule-build -fmodules -fimplicit-modules 
-fimplicit-module-maps -fmodule-map-file=module.modulemap -fsyntax-only -I hmap 
-fmodules-cache-path=%t test.cpp
+//
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: sed -e "s|OUTPUTS_DIR|%t|g" b.hmap.json > hmap.json
+// RUN: %hmaptool write hmap.json hmap
+//
+// RUN: %clang -Rmodule-build -fmodules -fimplicit-modules 
-fimplicit-module-maps -fmodule-map-file=module.modulemap -fsyntax-only -I hmap 
-fmodules-cache-path=%t test.cpp
+
+//--- After/Mapping.h
+#ifdef FOO
+#error foo
+#endif
+
+//--- a.hmap.json
+{
+  "mappings" :
+{
+ "Before/Mapping.h" : "After/Mapping.h",
+ "After/Mapping.h" : "After/Mapping.h"
+}
+}
+
+//--- b.hmap.json
+{
+  "mappings" :
+{
+ "Before/Mapping.h" : "OUTPUTS_DIR/After/Mapping.h"
+}
+}
+
+//--- module.modulemap
+module a {
+  header "After/Mapping.h"
+}
+
+
+//--- test.cpp
+#define FOO
+// This include will fail if:
+// 1) modules are't used, as the `FOO` define will propagate into the included
+//header and trip a `#error`, or
+// 2) header maps aren't used, as the header name doesn't exist and relies on
+//the header map to remap it to the real header.
+#include "Before/Mapping.h"
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -491,7 +491,8 @@
 
   IsInHeaderMap = true;
 
-  auto FixupSearchPath = [&]() {
+  auto FixupSearchPathAndFindUsableModule =
+  [&](auto File) -> OptionalFileEntryRef {
 if (SearchPath) {
   StringRef SearchPathRef(getName());
   SearchPath->clear();
@@ -501,6 +502,12 @@
   RelativePath->clear();
   RelativePath->append(Filename.begin(), Filename.end());
 }
+if (!HS.findUsableModuleForHeader(
+&File.getFileEntry(), File.getFileEntry().getDir(),
+RequestingModule, SuggestedModule, isSystemHeaderDirectory())) {
+  return std::nullopt;
+}
+return File;
   };
 
   // Check if the headermap maps the filename to a framework include
@@ -513,8 +520,7 @@
   }
 
   if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest, OpenFile)) {
-FixupSearchPath();
-return *Res;
+return FixupSearchPathAndFindUsableModule(*Res);
   }
 
   // Header maps need to be marked as used whenever the filename matches.


Index: clang/test/Modules/implicit-module-header-maps.cpp
===
--- /dev/null
+++ clang/test/Modules/implicit-module-header-maps.cpp
@@ -0,0 +1,54 @@
+// UNSUPPORTED: system-windows
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %hmaptool write a.hmap.json hmap
+//
+// RUN: %clang -Rmodule-build -fmodules -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=module.modulemap -fsyntax-only -I hmap -fmodules-cache-path=%t test.cpp
+//
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: sed -e "s|OUTPUTS_DIR|%t|g" b.hmap.json > hmap.json
+// RUN: %hmaptool write hmap.json hmap
+//
+// RUN: %clang -Rmodule-build -fmodules -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=module.modulemap -fsyntax-only -I hmap -fmodules-cache-path=%t test.cpp
+
+//--- After/Mapping.h
+#ifdef FOO
+#error foo
+#endif
+
+//--- a.hmap.json
+{
+  "mappings" :
+{
+ "Before/Mapping.h" : "After/Mapping.h",
+ "After/Mapping.h" : "After/Mapping.h"
+}
+}
+
+//--- b.hmap.json
+{
+  "mappings" :
+{
+ "Before/Mapping.h" : "OUTPUTS_DIR/After/Mapping.h"
+}
+}
+
+//--- module.modulemap
+module a {
+  header "After/Mapping.h"
+}
+
+
+//--- test.cpp
+#define FOO
+// This include will fail if:
+// 1) modules are't used, as the `FOO` define will propagate into the included
+//header and trip a `#error`, or
+// 2) header maps aren't used, as the header name doesn't exist and relies on
+//the header map to remap it to the real header.
+#include "Before/Mapping.h"
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -491,7 +491,8 @@
 
   IsInHeaderMap = true;
 
-  auto FixupSearchPath = [&]() {
+  auto FixupSearchPathAndFin

[PATCH] D150354: [OpenMP][MLIR][Flang][bbc][Driver] Add fopenmp-version and generate corresponding MLIR attribute

2023-05-12 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

All in all LGTM, but I'm not sure whether Flang should be defaulting to OpenMP 
5.0. AFAIK, that's not supported yet.




Comment at: clang/lib/Driver/ToolChains/Flang.cpp:34
+  Args.AddAllArgs(CmdArgs, {options::OPT_ffixed_form,
+options::OPT_ffree_form,
+options::OPT_ffixed_line_length_EQ,

Is this clang-format? Looks like a big block of unrelated changes (not against 
it).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150354/new/

https://reviews.llvm.org/D150354

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148381: [WIP][Clang] Add element_count attribute

2023-05-12 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added reviewers: rapidsna, fcloutier.
fhahn added a comment.

Adding a few people who have been working on `-fbounds-safety` proposal 
(https://llvm.swoogo.com/2023eurollvm/session/1414468/keynote-“-fbounds-safety”-enforcing-bounds-safety-for-production-c-code)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148381/new/

https://reviews.llvm.org/D148381

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142630: [clang][Interp] Implement virtual function calls

2023-05-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Interp.h:1560
+  // is the furthest we might go up in the hierarchy.
+  ThisPtr = ThisPtr.getDeclPtr();
+}

Just so I don't forget: The assignment to `ThisPtr` here is dead.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142630/new/

https://reviews.llvm.org/D142630

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150191: [clang][Diagnostics] Provide a source range for 'use of undeclared identifier' diagnostics

2023-05-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:2187
 else
-  SemaRef.Diag(TypoLoc, DiagnosticID) << Typo;
+  SemaRef.Diag(TypoRange.getEnd(), DiagnosticID) << Typo;
 return;

aaron.ballman wrote:
> tbaeder wrote:
> > I'm not passing the `TypoRange` here now, which regresses the test case I 
> > posted. Apparently the handling of `-fmacro-backtrace-limit` depends on the 
> > range passed here? That seems weird.
> Is it failing within `checkRangesForMacroArgExpansion()` in 
> DiagnosticRenderer.cpp? It looks like this change effectively undoes the work 
> from ecd36ee80b7a6ac73c84da19f8a75c4c025a7625
Well yes, the test case below simply didn't have any source ranges before 
(`Ranges` was empty), but now it does. The code behaves as expected I assume, 
just that... it doesn't do what I'd expect it to do. And it doesn't do what the 
test case below expects either.

I agree that the output before this patch is better (for the below test case), 
but the output shouldn't be affected by the source range we pass :/


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150191/new/

https://reviews.llvm.org/D150191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-12 Thread Ties Stuij via Phabricator via cfe-commits
stuij accepted this revision.
stuij added a comment.

Regarding this particular change, we at Arm are happy with the name change. I 
saw BFloat16 instead of BF16 as tech debt that we didn't get round to fixing.

I do wonder if we need two bfloat implementations, but for that I'll leave a 
comment on D149573 .

BTW, unfortunately @lenary doesn't work at Arm anymore.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150291/new/

https://reviews.llvm.org/D150291

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-05-12 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> Well that's... a bit shorter... than I would have expected that union to be. 
> (I'm not apologizing for the pun.)

In clang `union x { short x[]; }; static_assert(sizeof(x)==2);` evaluates to '0 
== 2'. That is even shorter, I guess? This is also the reason why

  union A {char x[]; };
  A a = {0};

keeps crashing even after my fix. It feels like we're not even close to be 
compatible with msvc. I would probably prefer submitting the original fix and 
submitting an issue to clean up the mess with this extension. At least this way 
it won't crash in C after issuing an error, like this 
https://godbolt.org/z/5oxYTq5fq


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147626/new/

https://reviews.llvm.org/D147626

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150435: [clang] Fix crash on attempt to initialize union with flexible array member

2023-05-12 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Due to missing check on union, there was a null expression
added to init list that caused crash later.

Fixes https://github.com/llvm/llvm-project/issues/61746


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150435

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/init.c


Index: clang/test/Sema/init.c
===
--- clang/test/Sema/init.c
+++ clang/test/Sema/init.c
@@ -164,3 +164,6 @@
 
 typedef struct { uintptr_t x : 2; } StructWithBitfield;
 StructWithBitfield bitfieldvar = { (uintptr_t)&bitfieldvar }; // 
expected-error {{initializer element is not a compile-time constant}}
+
+// GH61746
+union { char x[]; } r = {0}; // expected-error {{flexible array member 'x' in 
a union is not allowed}}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -811,7 +811,7 @@
   // order to leave them uninitialized, the ILE is expanded and the extra
   // fields are then filled with NoInitExpr.
   unsigned NumElems = numStructUnionElements(ILE->getType());
-  if (RDecl->hasFlexibleArrayMember())
+  if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;
   if (!VerifyOnly && ILE->getNumInits() < NumElems)
 ILE->resizeInits(SemaRef.Context, NumElems);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -395,6 +395,8 @@
   when it had been instantiated from a partial template specialization with 
different
   template arguments on the containing class. This fixes:
   (`#60778 `_).
+- Fix crash on attempt to initialize union with flexible array member.
+  (`#61746 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Sema/init.c
===
--- clang/test/Sema/init.c
+++ clang/test/Sema/init.c
@@ -164,3 +164,6 @@
 
 typedef struct { uintptr_t x : 2; } StructWithBitfield;
 StructWithBitfield bitfieldvar = { (uintptr_t)&bitfieldvar }; // expected-error {{initializer element is not a compile-time constant}}
+
+// GH61746
+union { char x[]; } r = {0}; // expected-error {{flexible array member 'x' in a union is not allowed}}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -811,7 +811,7 @@
   // order to leave them uninitialized, the ILE is expanded and the extra
   // fields are then filled with NoInitExpr.
   unsigned NumElems = numStructUnionElements(ILE->getType());
-  if (RDecl->hasFlexibleArrayMember())
+  if (!RDecl->isUnion() && RDecl->hasFlexibleArrayMember())
 ++NumElems;
   if (!VerifyOnly && ILE->getNumInits() < NumElems)
 ILE->resizeInits(SemaRef.Context, NumElems);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -395,6 +395,8 @@
   when it had been instantiated from a partial template specialization with different
   template arguments on the containing class. This fixes:
   (`#60778 `_).
+- Fix crash on attempt to initialize union with flexible array member.
+  (`#61746 `_).
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147626: [clang] Reject flexible array member in a union in C++

2023-05-12 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

I posted a pure crash fix here - https://reviews.llvm.org/D150435 .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147626/new/

https://reviews.llvm.org/D147626

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150352: [clang][dataflow] Don't analyze templated declarations.

2023-05-12 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 521603.
mboehme added a comment.

Changes in response to review comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150352/new/

https://reviews.llvm.org/D150352

Files:
  clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
  clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -68,7 +68,7 @@
   assert(Body != nullptr);
 
   auto CFCtx = llvm::cantFail(
-  ControlFlowContext::build(nullptr, *Body, AST->getASTContext()));
+  ControlFlowContext::build(Func, *Body, AST->getASTContext()));
 
   AnalysisT Analysis = MakeAnalysis(AST->getASTContext());
   DataflowAnalysisContext DACtx(std::make_unique());
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -39,13 +39,14 @@
 using BuiltinOptions = DataflowAnalysisContext::Options;
 
 template 
-void runDataflow(llvm::StringRef Code, Matcher Match,
- DataflowAnalysisOptions Options,
- LangStandard::Kind Std = LangStandard::lang_cxx17,
- llvm::StringRef TargetFun = "target") {
+llvm::Error
+runDataflowReturnError(llvm::StringRef Code, Matcher Match,
+   DataflowAnalysisOptions Options,
+   LangStandard::Kind Std = LangStandard::lang_cxx17,
+   llvm::StringRef TargetFun = "target") {
   using ast_matchers::hasName;
   llvm::SmallVector ASTBuildArgs = {
-  "-fsyntax-only", "-fno-delayed-template-parsing",
+  "-fsyntax-only",
   "-std=" +
   std::string(LangStandard::getLangStandardForKind(Std).getName())};
   AnalysisInputs AI(
@@ -61,13 +62,21 @@
   AI.ASTBuildArgs = ASTBuildArgs;
   if (Options.BuiltinOpts)
 AI.BuiltinOptions = *Options.BuiltinOpts;
+  return checkDataflow(
+  std::move(AI),
+  /*VerifyResults=*/
+  [&Match](
+  const llvm::StringMap> &Results,
+  const AnalysisOutputs &AO) { Match(Results, AO.ASTCtx); });
+}
+
+template 
+void runDataflow(llvm::StringRef Code, Matcher Match,
+ DataflowAnalysisOptions Options,
+ LangStandard::Kind Std = LangStandard::lang_cxx17,
+ llvm::StringRef TargetFun = "target") {
   ASSERT_THAT_ERROR(
-  checkDataflow(
-  std::move(AI),
-  /*VerifyResults=*/
-  [&Match](const llvm::StringMap>
-   &Results,
-   const AnalysisOutputs &AO) { Match(Results, AO.ASTCtx); }),
+  runDataflowReturnError(Code, Match, Options, Std, TargetFun),
   llvm::Succeeded());
 }
 
@@ -2534,31 +2543,34 @@
   });
 }
 
-TEST(TransferTest, DerefDependentPtr) {
+TEST(TransferTest, CannotAnalyzeFunctionTemplate) {
   std::string Code = R"(
 template 
-void target(T *Foo) {
-  T &Bar = *Foo;
-  /*[[p]]*/
-}
+void target() {}
   )";
-  runDataflow(
-  Code,
-  [](const llvm::StringMap> &Results,
- ASTContext &ASTCtx) {
-ASSERT_THAT(Results.keys(), UnorderedElementsAre("p"));
-const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
-
-const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
-ASSERT_THAT(FooDecl, NotNull());
-
-const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
-ASSERT_THAT(BarDecl, NotNull());
+  ASSERT_THAT_ERROR(
+  runDataflowReturnError(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {},
+  {BuiltinOptions()}),
+  llvm::FailedWithMessage("Cannot analyze templated declarations"));
+}
 
-const auto *FooVal = cast(Env.getValue(*FooDecl));
-const auto *BarLoc = Env.getStorageLocation(*BarDecl);
-EXPECT_EQ(BarLoc, &FooVal->getPointeeLoc());
-  });
+TEST(TransferTest, CannotAnalyzeMethodOfClassTemplate) {
+  std::string Code = R"(
+template 
+struct A {
+  void target() {}
+};
+  )";
+  ASSERT_THAT_ERROR(
+  runDataflowReturnError(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {},
+  {BuiltinOptions()}),
+  llvm::FailedWithMessage("Cannot analyze templated declarations"));
 }
 
 TEST(TransferTest, VarDeclInitAssignConditionalOperator) {
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===

[PATCH] D150352: [clang][dataflow] Don't analyze templated declarations.

2023-05-12 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked an inline comment as done.
mboehme added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h:36
+  /// `S` resides. `D.isTemplated()` must be false.
+  static llvm::Expected build(const Decl &D, Stmt &S,
+  ASTContext &C);

gribozavr2 wrote:
> Maybe this is too much for a drive-by fix, but since you are changing this 
> API anyway, I have to ask - now that D is nonnull, isn't S strictly 
> redundant? Isn't D always a FunctionDecl, and S its body?
> Isn't D always a FunctionDecl, and S its body?

This is true for all of the callsites that I've seen, but I think I remember 
talking to someone who said the intent was that you might also use this to 
analyze the initializer of a global variable (where `D` would be the variable 
declaration and `S` would be the initializer). It seems telling, at least, that 
the interface expects only a `Decl`, not a `FunctionDecl`.

So I'm hesitant to remove this API entirely without more investigation. It 
certainly makes sense though to add an overload that takes a `FunctionDecl` and 
no `Stmt`, which will cover the vast majority of use cases. I'd like to do that 
in a separate patch though.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:2537
 
-TEST(TransferTest, DerefDependentPtr) {
   std::string Code = R"(

gribozavr2 wrote:
> This `DerefDependentPtr` test was originally added in 
> https://reviews.llvm.org/D117567 and re-landed in 
> https://github.com/llvm/llvm-project/commit/acd4b0359097dd8ad166d569a4566879e82a2793
> 
> Could you try to revert the effects of those commits? Specifically:
> 
> - remove reference skipping from the transfer function for `UO_Deref` (and 
> the comment),
> 
> - remove the `-fno-delayed-template-parsing` flag from 
> `clang/unittests/Analysis/FlowSensitive/TransferTest.cpp`.
Thanks for pointing this out! Done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150352/new/

https://reviews.llvm.org/D150352

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149838: [clang][dataflow] Eliminate `SkipPast::ReferenceThenPointer`.

2023-05-12 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 521607.
mboehme added a comment.

Eliminate unnecessary `else`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149838/new/

https://reviews.llvm.org/D149838

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -372,8 +372,7 @@
   auto *Object = E->getImplicitObjectArgument();
   assert(Object != nullptr);
 
-  auto *ObjectLoc =
-  Env.getStorageLocation(*Object, SkipPast::ReferenceThenPointer);
+  auto *ObjectLoc = getImplicitObjectLocation(*E, Env);
   assert(ObjectLoc != nullptr);
 
   auto &ConstructorVal = *Env.createValue(Object->getType());
@@ -532,8 +531,7 @@
   auto *Object = E->getArg(0);
   assert(Object != nullptr);
 
-  auto *ObjectLoc =
-  Env.getStorageLocation(*Object, SkipPast::ReferenceThenPointer);
+  auto *ObjectLoc = Env.getStorageLocation(*Object, SkipPast::Reference);
   assert(ObjectLoc != nullptr);
 
   auto &ConstructorVal = *Env.createValue(Object->getType());
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -542,10 +542,7 @@
   }
 }
 
-// The receiver can be either a value or a pointer to a value. Skip past the
-// indirection to handle both cases.
-auto *BaseLoc = cast_or_null(
-Env.getStorageLocation(*S->getBase(), SkipPast::ReferenceThenPointer));
+AggregateStorageLocation *BaseLoc = getBaseObjectLocation(*S, Env);
 if (BaseLoc == nullptr)
   return;
 
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -372,10 +372,26 @@
   return HasValueVal != nullptr && Env.flowConditionImplies(*HasValueVal);
 }
 
+StorageLocation *maybeSkipPointer(StorageLocation *Loc,
+  const Environment &Env) {
+  if (Loc == nullptr)
+return nullptr;
+  if (auto *Val = dyn_cast_or_null(Env.getValue(*Loc)))
+return &Val->getPointeeLoc();
+  return Loc;
+}
+
+Value *getValueBehindPossiblePointer(const Expr &E, const Environment &Env) {
+  Value *Val = Env.getValue(E, SkipPast::Reference);
+  if (auto *PointerVal = dyn_cast_or_null(Val))
+return Env.getValue(PointerVal->getPointeeLoc());
+  return Val;
+}
+
 void transferUnwrapCall(const Expr *UnwrapExpr, const Expr *ObjectExpr,
 LatticeTransferState &State) {
   if (auto *OptionalVal =
-  State.Env.getValue(*ObjectExpr, SkipPast::ReferenceThenPointer)) {
+  getValueBehindPossiblePointer(*ObjectExpr, State.Env)) {
 if (State.Env.getStorageLocation(*UnwrapExpr, SkipPast::None) == nullptr)
   if (auto *Loc = maybeInitializeOptionalValueMember(
   UnwrapExpr->getType(), *OptionalVal, State.Env))
@@ -396,8 +412,8 @@
   const MatchFinder::MatchResult &,
   LatticeTransferState &State) {
   if (auto *HasValueVal = getHasValue(
-  State.Env, State.Env.getValue(*CallExpr->getImplicitObjectArgument(),
-SkipPast::ReferenceThenPointer))) {
+  State.Env, getValueBehindPossiblePointer(
+ *CallExpr->getImplicitObjectArgument(), State.Env))) {
 auto &CallExprLoc = State.Env.createStorageLocation(*CallExpr);
 State.Env.setValue(CallExprLoc, *HasValueVal);
 State.Env.setStorageLocation(*CallExpr, CallExprLoc);
@@ -419,8 +435,7 @@
   ->getImplicitObjectArgument();
 
   auto *HasValueVal = getHasValue(
-  State.Env,
-  State.Env.getValue(*ObjectArgumentExpr, SkipPast::ReferenceThenPointer));
+  State.Env, getValueBehindPossiblePointer(*ObjectArgumentExpr, State.Env));
   if (HasValueVal == nullptr)
 return;
 
@@ -472,8 +487,8 @@
 
 void assignOptionalValue(const Expr &E, Environment &Env,
  BoolValue &HasValueVal) {
-  if (auto *OptionalLoc =
-  Env.getStorageLocation(E, SkipPast::ReferenceThenPointer)) {
+  if (auto *OptionalLoc = maybeSkipPointer(
+  Env.getStorageLocati

[PATCH] D149838: [clang][dataflow] Eliminate `SkipPast::ReferenceThenPointer`.

2023-05-12 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked an inline comment as done.
mboehme added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp:840
+return nullptr;
+  } else {
+return cast(Loc);

ymandel wrote:
> nit: no need for `else` since `if` branch always returns
Good point -- done. (Also below.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149838/new/

https://reviews.llvm.org/D149838

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names and introduce Bfloat16 arithmetic type.

2023-05-12 Thread Ties Stuij via Phabricator via cfe-commits
stuij added a comment.

I made a comment on the RFC 

 to understand if we really need/want a new bfloat16 type.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149573/new/

https://reviews.llvm.org/D149573

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150258: [clang][parser] Fix namespace dropping after malformed declarations

2023-05-12 Thread Alejandro Álvarez Ayllón via Phabricator via cfe-commits
alejandro-alvarez-sonarsource updated this revision to Diff 521625.
alejandro-alvarez-sonarsource added a comment.

Applied suggested changes.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150258/new/

https://reviews.llvm.org/D150258

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp
  clang/test/Parser/cxx-template-recovery.cpp

Index: clang/test/Parser/cxx-template-recovery.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-template-recovery.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template 
+void Foo::Bar(void* aRawPtr) { // expected-error {{no template named 'Foo'}}
+(void)(aRawPtr);
+}
+
+namespace baz {
+  class klass {};
+}
+
+int *variable = 0; // ok
+const baz::klass object; // ok
Index: clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-namespace-after-missing-semicolon.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+UNKNOWN_MACRO_1("z", 1) // expected-error {{a type specifier is required for all declarations}}
+// expected-error@-1 {{expected ';' after top level declarator}}
+
+namespace foo {
+  class bar {};
+}
+
+int variable = 0; // ok
+foo::bar something; // ok
+
+UNKNOWN_MACRO_2(void) // expected-error {{a type specifier is required for all declarations}}
+// expected-error@-1 {{expected ';' after top level declarator}}
+
+namespace baz {
+  using Bool = bool;
+}
+
+int variable2 = 2; // ok
+const baz::Bool flag = false;  // ok
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -275,10 +275,7 @@
 
   // Error parsing the declarator?
   if (!DeclaratorInfo.hasName()) {
-// If so, skip until the semi-colon or a }.
-SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
-if (Tok.is(tok::semi))
-  ConsumeToken();
+SkipMalformedDecl();
 return nullptr;
   }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2176,13 +2176,16 @@
   return Actions.ConvertDeclToDeclGroup(TheDecl);
 }
 
-if (isDeclarationSpecifier(ImplicitTypenameContext::No)) {
-  // If there is an invalid declaration specifier right after the
-  // function prototype, then we must be in a missing semicolon case
-  // where this isn't actually a body.  Just fall through into the code
-  // that handles it as a prototype, and let the top-level code handle
-  // the erroneous declspec where it would otherwise expect a comma or
-  // semicolon.
+if (isDeclarationSpecifier(ImplicitTypenameContext::No) ||
+Tok.is(tok::kw_namespace)) {
+  // If there is an invalid declaration specifier or a namespace
+  // definition right after the function prototype, then we must be in a
+  // missing semicolon case where this isn't actually a body.  Just fall
+  // through into the code that handles it as a prototype, and let the
+  // top-level code handle the erroneous declspec where it would
+  // otherwise expect a comma or semicolon. Note that
+  // isDeclarationSpecifier already covers 'inline namespace', since
+  // 'inline' can be a declaration specifier.
 } else {
   Diag(Tok, diag::err_expected_fn_body);
   SkipUntil(tok::semi);
@@ -2303,10 +2306,8 @@
 // Okay, there was no semicolon and one was expected.  If we see a
 // declaration specifier, just assume it was missing and continue parsing.
 // Otherwise things are very confused and we skip to recover.
-if (!isDeclarationSpecifier(ImplicitTypenameContext::No)) {
-  SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
-  TryConsumeToken(tok::semi);
-}
+if (!isDeclarationSpecifier(ImplicitTypenameContext::No))
+  SkipMalformedDecl();
   }
 
   return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -449,6 +449,8 @@
 Bug Fixes to AST Handling
 ^
 
+- Preserve ``namespace`` definitions that follow malformed declarations.
+
 Miscellaneous Bug Fixes
 ^^^
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150258: [clang][parser] Fix namespace dropping after malformed declarations

2023-05-12 Thread Alejandro Álvarez Ayllón via Phabricator via cfe-commits
alejandro-alvarez-sonarsource added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:2306-2310
 // Otherwise things are very confused and we skip to recover.
 if (!isDeclarationSpecifier(ImplicitTypenameContext::No)) {
-  SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
-  TryConsumeToken(tok::semi);
+  SkipMalformedDecl();
 }
   }

aaron.ballman wrote:
> Changes for our coding style.
> 
> There seems to be some unfortunate interplay here though. Consider:
> ```
> void bar() namespace foo { int i; }
> 
> int main() {
>   foo::i = 12;
> }
> ```
> Calling `SkipMalformedDecl()` changes the behavior for this test case because 
> we don't recover as well. With your patch applied, this gives us two 
> diagnostics:
> ```
> C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp:1:11: error: 
> expected ';' after top level declarator
> void bar() namespace foo { int i; }
>   ^
>   ;
> C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp:4:3: error: 
> use of undeclared identifier 'foo'
>   foo::i = 12;
>   ^
> 2 errors generated.
> ```
> If the `namespace` keyword is on its own line, then we recover gracefully and 
> don't emit the "use of undeclared identifier" warning.
> 
> While this is technically a regression in behavior for this test case, I 
> think the overall changes are still an improvement. I suspect not a whole lot 
> of code puts `namespace` somewhere other than the start of a line (same for 
> `inline namespace` which has the same behavior with your patch).
> Calling SkipMalformedDecl() changes the behavior for this test case because 
> we don't recover as well. With your patch applied, this gives us two 
> diagnostics:

True. This can also be recovered by removing `Tok.isAtStartOfLine()` in line 
2050. However, this has been around for a long time and would change the 
behavior of 
two tests inside `test/Parser/recovery.cpp`, although only because the broken 
comments contain the namespace keyword.

Either case seems unlikely to me, so I think I'd lean toward not modifying 
`SkipMalformedDecl`. What do you think?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150258/new/

https://reviews.llvm.org/D150258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149997: [clang] [test] Narrow down MSVC specific behaviours from "any windows" to only MSVC/clang-cl

2023-05-12 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a subscriber: rnk.
mstorsjo added a comment.

So, the reason why this failed, is that when invoked as `%clang_cc1` in a 
MSVC/clang-cl style build, `_MSC_VER` isn't predefined, while `_WIN32` is. When 
invoked via the Clang driver instead of directly going at `-cc1`, `_MSC_VER` 
does get defined.

@rnk @hans @thakis - who know the intricacies of the MSVC target - do you 
happen to know why that is? How do I distinguish between MSVC-style behaviour 
and other cases (in particular, mingw) in a `%clang_cc1` test? Currently it 
uses `#idef _WIN32` but that's incorrect for mingw.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149997/new/

https://reviews.llvm.org/D149997

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150446: [analyzer] Check ArraySubscriptExprs in ArrayBoundCheckerV2

2023-05-12 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy created this revision.
donat.nagy added reviewers: dkrupp, gamesh411, steakhal.
Herald added subscribers: manas, ASDenysPetrov, martong, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
donat.nagy requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The checker alpha.security.ArrayBoundV2 was implemented with a 
`check::Location` callback, so it triggered on memory read or write operations 
(and checked access to ElementRegions).

The generality of this solution was elegant, but I'm replacing it with an 
implementation based on `check::PreStmt`, because that's 
closer to the intuition of the users. (I'm planning to improve the error 
messages and it'd be good to connect each bug report with a concrete operator 
that triggers it.)

Note that the logic for simplifying expressions is unchanged and this commit 
doesn't modify the behavior of the checker under common circumstances (e.g. all 
unit tests pass without changes).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150446

Files:
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp

Index: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -31,7 +31,7 @@
 
 namespace {
 class ArrayBoundCheckerV2 :
-public Checker {
+public Checker> {
   mutable std::unique_ptr BT;
   mutable std::unique_ptr TaintBT;
 
@@ -45,8 +45,9 @@
   static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
 
 public:
-  void checkLocation(SVal l, bool isLoad, const Stmt *S,
- CheckerContext &C) const;
+  void checkPreStmt(const ArraySubscriptExpr *ASE, CheckerContext &C) const;
+  // void checkLocation(SVal l, bool isLoad, const Stmt *S,
+  //CheckerContext &C) const;
 };
 
 // FIXME: Eventually replace RegionRawOffset with this class.
@@ -63,7 +64,7 @@
   const SubRegion *getRegion() const { return baseRegion; }
 
   static std::optional
-  computeOffset(ProgramStateRef State, SValBuilder &SVB, SVal Location);
+  computeOffset(ProgramStateRef State, SValBuilder &SVB, const LocationContext *LCtx, const ArraySubscriptExpr *ASE);
 
   void dump() const;
   void dumpToStream(raw_ostream &os) const;
@@ -86,8 +87,8 @@
   APSIntType(extent.getValue()).convert(SIE->getRHS());
   switch (SIE->getOpcode()) {
   case BO_Mul:
-// The constant should never be 0 here, since it the result of scaling
-// based on the size of a type which is never 0.
+// In a SymIntExpr multiplication the constant cannot be 0, because
+// then the enginge would've replaced it with a constant 0 value.
 if ((extent.getValue() % constant) != 0)
   return std::pair(offset, extent);
 else
@@ -140,44 +141,41 @@
   return {nullptr, nullptr};
 }
 
-void ArrayBoundCheckerV2::checkLocation(SVal location, bool isLoad,
-const Stmt* LoadS,
-CheckerContext &checkerContext) const {
-
+void ArrayBoundCheckerV2::checkPreStmt(const ArraySubscriptExpr *ASE,
+   CheckerContext &C) const {
   // NOTE: Instead of using ProgramState::assumeInBound(), we are prototyping
   // some new logic here that reasons directly about memory region extents.
   // Once that logic is more mature, we can bring it back to assumeInBound()
   // for all clients to use.
-  //
-  // The algorithm we are using here for bounds checking is to see if the
-  // memory access is within the extent of the base region.  Since we
-  // have some flexibility in defining the base region, we can achieve
-  // various levels of conservatism in our buffer overflow checking.
 
   // The header ctype.h (from e.g. glibc) implements the isX() macros as
   //   #define isX(arg) (LOOKUP_TABLE[arg] & BITMASK_FOR_X)
   // and incomplete analysis of these leads to false positives. As even
   // accurate reports would be confusing for the users, just disable reports
   // from these macros:
-  if (isFromCtypeMacro(LoadS, checkerContext.getASTContext()))
+  if (isFromCtypeMacro(ASE, C.getASTContext()))
 return;
 
-  ProgramStateRef state = checkerContext.getState();
+  ProgramStateRef state = C.getState();
+
+  SValBuilder &svalBuilder = C.getSValBuilder();
+
+  const LocationContext *LCtx = C.getLocationContext();
 
-  SValBuilder &svalBuilder = checkerContext.getSValBuilder();
   const std::optional &RawOffset =
-  RegionRawOffsetV2::computeOffset(state, svalBuilder, location);
+  RegionRawOffsetV2::computeOffset(state, svalBuilder, LCtx, ASE);
 
   if (!RawOffset)
 return;
 
   NonLoc ByteOffset = RawOffset->getByteOffset();
+  const

[PATCH] D149986: AMDGPU: Force sc0 and sc1 on stores for gfx940 and gfx941

2023-05-12 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/TargetParser/TargetParser.cpp:330-332
 case GK_GFX940:
+  Features["force-store-sc0-sc1"] = true;
+  [[fallthrough]];

I don't see a reason to set this here. There's no need to expose this to the 
IR. We already leak too many target details here as it is 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149986/new/

https://reviews.llvm.org/D149986

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150446: [analyzer] Check ArraySubscriptExprs in ArrayBoundCheckerV2

2023-05-12 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

After some thinking and internal discussion I decided that it'd be better to 
replace the callback used by this checker. This is a clean but rough draft of 
this concept; for a final version I'd consider:

- adding  a secondary callback that handles `*ptr` equivalently to `ptr[0]`;
- including a special case that it's valid to form an after-the-end pointer as 
`&arr[N]` where `N` is the length of the array;
- including a check::Location callback that creates bug reports when these 
after-the-end pointers are dereferenced.

@steakhal What do you think about this design direction?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150446/new/

https://reviews.llvm.org/D150446

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150446: [analyzer] Check ArraySubscriptExprs in ArrayBoundCheckerV2

2023-05-12 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy updated this revision to Diff 521640.
donat.nagy added a comment.

//(Re-uploaded patch to apply clang-format changes and remove a stray temporary 
comment.)//


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150446/new/

https://reviews.llvm.org/D150446

Files:
  clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp

Index: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp
@@ -30,8 +30,7 @@
 using namespace taint;
 
 namespace {
-class ArrayBoundCheckerV2 :
-public Checker {
+class ArrayBoundCheckerV2 : public Checker> {
   mutable std::unique_ptr BT;
   mutable std::unique_ptr TaintBT;
 
@@ -45,8 +44,7 @@
   static bool isFromCtypeMacro(const Stmt *S, ASTContext &AC);
 
 public:
-  void checkLocation(SVal l, bool isLoad, const Stmt *S,
- CheckerContext &C) const;
+  void checkPreStmt(const ArraySubscriptExpr *ASE, CheckerContext &C) const;
 };
 
 // FIXME: Eventually replace RegionRawOffset with this class.
@@ -63,7 +61,8 @@
   const SubRegion *getRegion() const { return baseRegion; }
 
   static std::optional
-  computeOffset(ProgramStateRef State, SValBuilder &SVB, SVal Location);
+  computeOffset(ProgramStateRef State, SValBuilder &SVB,
+const LocationContext *LCtx, const ArraySubscriptExpr *ASE);
 
   void dump() const;
   void dumpToStream(raw_ostream &os) const;
@@ -86,8 +85,8 @@
   APSIntType(extent.getValue()).convert(SIE->getRHS());
   switch (SIE->getOpcode()) {
   case BO_Mul:
-// The constant should never be 0 here, since it the result of scaling
-// based on the size of a type which is never 0.
+// In a SymIntExpr multiplication the constant cannot be 0, because
+// then the enginge would've replaced it with a constant 0 value.
 if ((extent.getValue() % constant) != 0)
   return std::pair(offset, extent);
 else
@@ -140,44 +139,41 @@
   return {nullptr, nullptr};
 }
 
-void ArrayBoundCheckerV2::checkLocation(SVal location, bool isLoad,
-const Stmt* LoadS,
-CheckerContext &checkerContext) const {
-
+void ArrayBoundCheckerV2::checkPreStmt(const ArraySubscriptExpr *ASE,
+   CheckerContext &C) const {
   // NOTE: Instead of using ProgramState::assumeInBound(), we are prototyping
   // some new logic here that reasons directly about memory region extents.
   // Once that logic is more mature, we can bring it back to assumeInBound()
   // for all clients to use.
-  //
-  // The algorithm we are using here for bounds checking is to see if the
-  // memory access is within the extent of the base region.  Since we
-  // have some flexibility in defining the base region, we can achieve
-  // various levels of conservatism in our buffer overflow checking.
 
   // The header ctype.h (from e.g. glibc) implements the isX() macros as
   //   #define isX(arg) (LOOKUP_TABLE[arg] & BITMASK_FOR_X)
   // and incomplete analysis of these leads to false positives. As even
   // accurate reports would be confusing for the users, just disable reports
   // from these macros:
-  if (isFromCtypeMacro(LoadS, checkerContext.getASTContext()))
+  if (isFromCtypeMacro(ASE, C.getASTContext()))
 return;
 
-  ProgramStateRef state = checkerContext.getState();
+  ProgramStateRef state = C.getState();
+
+  SValBuilder &svalBuilder = C.getSValBuilder();
+
+  const LocationContext *LCtx = C.getLocationContext();
 
-  SValBuilder &svalBuilder = checkerContext.getSValBuilder();
   const std::optional &RawOffset =
-  RegionRawOffsetV2::computeOffset(state, svalBuilder, location);
+  RegionRawOffsetV2::computeOffset(state, svalBuilder, LCtx, ASE);
 
   if (!RawOffset)
 return;
 
   NonLoc ByteOffset = RawOffset->getByteOffset();
+  const SubRegion *Reg = RawOffset->getRegion();
 
   // CHECK LOWER BOUND
-  const MemSpaceRegion *SR = RawOffset->getRegion()->getMemorySpace();
-  if (!llvm::isa(SR)) {
-// A pointer to UnknownSpaceRegion may point to the middle of
-// an allocated region.
+  const MemSpaceRegion *Space = Reg->getMemorySpace();
+  if (!(isa(Reg) && isa(Space))) {
+// Symbolic regions in unknown spaces are used for modelling unknown
+// pointers, so they may point to the middle of an array.
 
 auto [state_precedesLowerBound, state_withinLowerBound] =
 compareValueToThreshold(state, ByteOffset,
@@ -185,7 +181,7 @@
 
 if (state_precedesLowerBound && !state_withinLowerBound) {
   // We know that the index definitely precedes the lower bound.
-  reportOOB(checkerContext, state_precedesLowerBound, OOB_Precedes);
+  reportOOB(C, state_precedesLowerBound, OOB_Precedes);
   re

[PATCH] D148094: [clang][CodeGen] Break up TargetInfo.cpp [8/8]

2023-05-12 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 521642.
barannikov88 added a comment.

Undo reformatting in arch-specific files
This should help in resolving merge conflicts downstream


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148094/new/

https://reviews.llvm.org/D148094

Files:
  clang/docs/UsersManual.rst
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/CodeGen/ABIInfo.cpp
  clang/lib/CodeGen/ABIInfo.h
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/CMakeLists.txt
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/Targets/AArch64.cpp
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/lib/CodeGen/Targets/ARC.cpp
  clang/lib/CodeGen/Targets/ARM.cpp
  clang/lib/CodeGen/Targets/AVR.cpp
  clang/lib/CodeGen/Targets/BPF.cpp
  clang/lib/CodeGen/Targets/CSKY.cpp
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Lanai.cpp
  clang/lib/CodeGen/Targets/LoongArch.cpp
  clang/lib/CodeGen/Targets/M68k.cpp
  clang/lib/CodeGen/Targets/MSP430.cpp
  clang/lib/CodeGen/Targets/Mips.cpp
  clang/lib/CodeGen/Targets/NVPTX.cpp
  clang/lib/CodeGen/Targets/PNaCl.cpp
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/lib/CodeGen/Targets/SPIR.cpp
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/SystemZ.cpp
  clang/lib/CodeGen/Targets/TCE.cpp
  clang/lib/CodeGen/Targets/VE.cpp
  clang/lib/CodeGen/Targets/WebAssembly.cpp
  clang/lib/CodeGen/Targets/X86.cpp
  clang/lib/CodeGen/Targets/XCore.cpp
  clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp
  llvm/utils/gn/secondary/clang/lib/CodeGen/BUILD.gn

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150191: [clang][Diagnostics] Provide a source range for 'use of undeclared identifier' diagnostics

2023-05-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:2187
 else
-  SemaRef.Diag(TypoLoc, DiagnosticID) << Typo;
+  SemaRef.Diag(TypoRange.getEnd(), DiagnosticID) << Typo;
 return;

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > I'm not passing the `TypoRange` here now, which regresses the test case I 
> > > posted. Apparently the handling of `-fmacro-backtrace-limit` depends on 
> > > the range passed here? That seems weird.
> > Is it failing within `checkRangesForMacroArgExpansion()` in 
> > DiagnosticRenderer.cpp? It looks like this change effectively undoes the 
> > work from ecd36ee80b7a6ac73c84da19f8a75c4c025a7625
> Well yes, the test case below simply didn't have any source ranges before 
> (`Ranges` was empty), but now it does. The code behaves as expected I assume, 
> just that... it doesn't do what I'd expect it to do. And it doesn't do what 
> the test case below expects either.
> 
> I agree that the output before this patch is better (for the below test 
> case), but the output shouldn't be affected by the source range we pass :/
Yeah, but I think you'll have to solve this issue before we can land these 
changes.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150191/new/

https://reviews.llvm.org/D150191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150364: [clang][Interp] Add 'Invalid' opcode and use it for throw/asm stmts

2023-05-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/test/AST/Interp/records.cpp:341
+
+/// FIXME: Wrong source location below.
+return 12; // expected-note {{in call to '&S{}->~S()'}}

tbaeder wrote:
> aaron.ballman wrote:
> > Oh interesting -- does the old constexpr interpreter think the destructor 
> > is called at the end of the block as opposed to at the end of the full 
> > expression with the temporary?
> I think it's the other way around and the new one does that (`expected` is 
> the new one). Need to investigate that.
Ah oops, you're right, I did have that backwards. That makes more sense, 
thanks. :-)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150364/new/

https://reviews.llvm.org/D150364

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149133: [clang][Interp] BaseToDerived casts

2023-05-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149133/new/

https://reviews.llvm.org/D149133

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144164: [clang][Interp] Handle PtrMemOps

2023-05-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144164/new/

https://reviews.llvm.org/D144164

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149550: [clang][Interp] Fix compound assign operator evaluation order

2023-05-12 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149550/new/

https://reviews.llvm.org/D149550

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: clang-language-wg, aaron.ballman.
Herald added a project: All.
erichkeane requested review of this revision.
Herald added a subscriber: MaskRay.

Now that we've updated to C++23, we need to add C++26/C++2c command line
flags, as discussed in
https://discourse.llvm.org/t/rfc-lets-just-call-it-c-26-and-forget-about-the-c-2c-business-at-least-internally/70383


https://reviews.llvm.org/D150450

Files:
  clang/docs/CommandGuide/clang.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangStandard.h
  clang/include/clang/Basic/LangStandards.def
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Driver/unknown-std.cpp
  clang/test/Preprocessor/init.c
  clang/www/OpenProjects.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -65,6 +65,11 @@
  -std=c++23
  Partial
 
+
+ C++2c
+ -std=c++2c
+ Partial
+
 
 
 The Clang community is continually striving to improve C++ standards
@@ -1560,6 +1565,25 @@
 
 
 
+C++2c implementation status
+
+
+Clang has support for some of the features of the C++ standard following
+C++23, informally referred to as C++26.
+
+You can use Clang in C++2c mode with the -std=c++2c option.
+
+
+List of features and minimum Clang version with support
+
+ 
+Language Feature
+C++26 Proposal
+Available in Clang?
+ 
+ 
+ 
+
 Defect reports
 
 Clang generally aims to implement resolutions to Defect Reports (bug fixes
Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -123,7 +123,7 @@
 
 
 
-Continue work on C++20, C++23, and C2x support:
+Continue work on C++20, C++23, C++26, and C2x support:
   There are still several C++20 features to complete, and work has begun on
   supporting the latest language standards. Please see the
   C++ status report page to find out what is
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -8,8 +8,18 @@
 // BLOCKS:#define __BLOCKS__ 1
 // BLOCKS:#define __block __attribute__((__blocks__(byref)))
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+//
+// CXX26:#define __GNUG__ 4
+// CXX26:#define __GXX_EXPERIMENTAL_CXX0X__ 1
+// CXX26:#define __GXX_RTTI 1
+// CXX26:#define __GXX_WEAK__ 1
+// CXX26:#define __cplusplus 202102L
+// CXX26:#define __private_extern__ extern
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
 //
 // CXX2B:#define __GNUG__ 4
 // CXX2B:#define __GXX_EXPERIMENTAL_CXX0X__ 1
@@ -133,7 +143,16 @@
 // RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+//
+// GXX26:#define __GNUG__ 4
+// GXX26:#define __GXX_WEAK__ 1
+// GXX26:#define __cplusplus 202102L
+// GXX26:#define __private_extern__ extern
+//
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
 //
 // GXX2B:#define __GNUG__ 4
 // GXX2B:#define __GXX_WEAK__ 1
Index: clang/test/Driver/unknown-std.cpp
===
--- clang/test/Driver/unknown-std.cpp
+++ clang/test/Driver/unknown-std.cpp
@@ -19,6 +19,8 @@
 // CHECK-NEXT: note: use 'gnu++20' for 'ISO C++ 2020 DIS with GNU extensions' standard
 // CHECK-NEXT: note: use 'c++23' for 'ISO C++ 2023 DIS' standard
 // CHECK-NEXT: note: use 'gnu++23' for 'ISO C++ 2023 DIS with GNU extensions' standard
+// CHECK-NEXT: note: use 'c++2c' or 'c++26' for 'Working draft for ISO C++ 2026 DIS' standard
+// CHECK-NEXT: note: use 'gnu++2c' or 'gnu++26' for 'Working draft for ISO C++ 2026 DIS with GNU extensions' standard
 // CUDA-NEXT: note: use 

[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticGroups.td:310
   DiagGroup<"pre-c++23-compat-pedantic", [CXXPre23Compat]>;
+def CXXPre26Compat : DiagGroup<"pre-c++26-compat">;
+def CXXPre26CompatPedantic :

Aaron: note the names of the diag groups: would you prefer this to be `c++2c`?



Comment at: clang/include/clang/Basic/LangOptions.def:101
 LANGOPT(CPlusPlus23   , 1, 0, "C++23")
+LANGOPT(CPlusPlus26   , 1, 0, "C++26")
 LANGOPT(ObjC  , 1, 0, "Objective-C")

It isn't clear to me what the string here is used to output, so not sure if 
this should be 2c.



Comment at: clang/include/clang/Basic/LangStandards.def:170
+ CPlusPlus20 | CPlusPlus23 | CPlusPlus26 | Digraphs | HexFloat)
+LANGSTANDARD_ALIAS(cxx26, "c++26")
+

Note I made the c++26/gnu++26 values an alias, when we come to update this for 
C++26's release, this will be added to the LANGSTANDARD, and c++2c/gnu++2c 
should become an ALIAS_DEPR



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:456
+  // FIXME: Use correct value for C++26.
+  Builder.defineMacro("__cplusplus", "202102L");
+// FIXME: Use correct value for C++23, and update C++26 to be 'one more'.

At the moment, I just chose '1 more than c++23', but that hasn't been set yet.  
Once we have the final value, we should make this 1 more than 23's official 
value.



Comment at: clang/www/OpenProjects.html:126
 
-Continue work on C++20, C++23, and C2x support:
+Continue work on C++20, C++23, C++26, and C2x support:
   There are still several C++20 features to complete, and work has begun on

Should this spot in the docs be `C++2c`?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145343: [AMDGPU] Emit predefined macro `__AMDGCN_CUMODE__`

2023-05-12 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:121-123
+def warn_drv_unsupported_option_for_processor : Warning<
+  "ignoring '%0' option as it is not currently supported for processor '%1'">,
+  InGroup;

I'm surprised there already isn't a warning for this?



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:146
+return false;
+  return TargetFeature == "no-cumode";
+}

I don't understand the use of "no-cumode". Where is this defined?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145343/new/

https://reviews.llvm.org/D145343

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Similar PR here https://reviews.llvm.org/D149875




Comment at: clang/docs/ReleaseNotes.rst:114
+^
+- Compiler flags -std=c++2c and -std=gnu++2c have been added for experimental 
C++26 implementation work.
+

This should be 2c



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:456
+  // FIXME: Use correct value for C++26.
+  Builder.defineMacro("__cplusplus", "202102L");
+// FIXME: Use correct value for C++23, and update C++26 to be 'one more'.

erichkeane wrote:
> At the moment, I just chose '1 more than c++23', but that hasn't been set 
> yet.  Once we have the final value, we should make this 1 more than 23's 
> official value.
A value lesser than 202401L seems super confusing to me



Comment at: clang/www/OpenProjects.html:126
 
-Continue work on C++20, C++23, and C2x support:
+Continue work on C++20, C++23, C++26, and C2x support:
   There are still several C++20 features to complete, and work has begun on

erichkeane wrote:
> Should this spot in the docs be `C++2c`?
I think so


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:456
+  // FIXME: Use correct value for C++26.
+  Builder.defineMacro("__cplusplus", "202102L");
+// FIXME: Use correct value for C++23, and update C++26 to be 'one more'.

cor3ntin wrote:
> erichkeane wrote:
> > At the moment, I just chose '1 more than c++23', but that hasn't been set 
> > yet.  Once we have the final value, we should make this 1 more than 23's 
> > official value.
> A value lesser than 202401L seems super confusing to me
In the DIS __cplusplus is 202302L


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146054: [RISCV] Add --print-supported-extensions and -march=help support

2023-05-12 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

GCC ins't implement yet, but planed, so add it later I think?

@4vtomat already drop -march=help, @MaskRay did you mind take a look again?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146054/new/

https://reviews.llvm.org/D146054

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145343: [AMDGPU] Emit predefined macro `__AMDGCN_CUMODE__`

2023-05-12 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticDriverKinds.td:121-123
+def warn_drv_unsupported_option_for_processor : Warning<
+  "ignoring '%0' option as it is not currently supported for processor '%1'">,
+  InGroup;

arsenm wrote:
> I'm surprised there already isn't a warning for this?
I am surprised too. Before this patch, there is no check and no handling of 
unsupported target features in Clang. clang just blindly adds target features 
specified in the command line and relies on the backend to handle them properly.

This patch enables Clang to warn and ignore unsupported target features.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:146
+return false;
+  return TargetFeature == "no-cumode";
+}

arsenm wrote:
> I don't understand the use of "no-cumode". Where is this defined?
This function is called by clang driver. The argument TargetFeature is the 
target feature command line option to be checked, with `-m` removed, e.g. 
`-mcumode` or `-mno-cumode` passed to this function as "cumode" or "no-cumode".


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145343/new/

https://reviews.llvm.org/D145343

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150258: [clang][parser] Fix namespace dropping after malformed declarations

2023-05-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! Do you need me to commit on your behalf? If so, what name and email 
address would you like used for patch attribution?




Comment at: clang/lib/Parse/ParseDecl.cpp:2306-2310
 // Otherwise things are very confused and we skip to recover.
 if (!isDeclarationSpecifier(ImplicitTypenameContext::No)) {
-  SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
-  TryConsumeToken(tok::semi);
+  SkipMalformedDecl();
 }
   }

alejandro-alvarez-sonarsource wrote:
> aaron.ballman wrote:
> > Changes for our coding style.
> > 
> > There seems to be some unfortunate interplay here though. Consider:
> > ```
> > void bar() namespace foo { int i; }
> > 
> > int main() {
> >   foo::i = 12;
> > }
> > ```
> > Calling `SkipMalformedDecl()` changes the behavior for this test case 
> > because we don't recover as well. With your patch applied, this gives us 
> > two diagnostics:
> > ```
> > C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp:1:11: 
> > error: expected ';' after top level declarator
> > void bar() namespace foo { int i; }
> >   ^
> >   ;
> > C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp:4:3: error: 
> > use of undeclared identifier 'foo'
> >   foo::i = 12;
> >   ^
> > 2 errors generated.
> > ```
> > If the `namespace` keyword is on its own line, then we recover gracefully 
> > and don't emit the "use of undeclared identifier" warning.
> > 
> > While this is technically a regression in behavior for this test case, I 
> > think the overall changes are still an improvement. I suspect not a whole 
> > lot of code puts `namespace` somewhere other than the start of a line (same 
> > for `inline namespace` which has the same behavior with your patch).
> > Calling SkipMalformedDecl() changes the behavior for this test case because 
> > we don't recover as well. With your patch applied, this gives us two 
> > diagnostics:
> 
> True. This can also be recovered by removing `Tok.isAtStartOfLine()` in line 
> 2050. However, this has been around for a long time and would change the 
> behavior of 
> two tests inside `test/Parser/recovery.cpp`, although only because the broken 
> comments contain the namespace keyword.
> 
> Either case seems unlikely to me, so I think I'd lean toward not modifying 
> `SkipMalformedDecl`. What do you think?
I also lean towards not modifying `SkipMalformedDecl()`; I think it's recovery 
strategy is sensible.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150258/new/

https://reviews.llvm.org/D150258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150452: [clang-format] Recognize nested blocks

2023-05-12 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
sstwcw requested review of this revision.

Now a block gets recognized as a block if it contains a block.

The special cases we added don't have additional tests because they
are already tested for example in FormatTest.FormatsLambdas and
FormatTestJS.ContainerLiterals.

Fixes https://github.com/llvm/llvm-project/issues/33891


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150452

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -40,6 +40,8 @@
   EXPECT_EQ((FormatTok)->getType(), Type) << *(FormatTok)
 #define EXPECT_TOKEN_PRECEDENCE(FormatTok, Prec)   \
   EXPECT_EQ((FormatTok)->getPrecedence(), Prec) << *(FormatTok)
+#define EXPECT_BRACE_KIND(FormatTok, Kind) \
+  EXPECT_EQ(FormatTok->getBlockKind(), Kind)
 #define EXPECT_TOKEN(FormatTok, Kind, Type)\
   do { \
 EXPECT_TOKEN_KIND(FormatTok, Kind);\
@@ -1783,6 +1785,22 @@
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {
+  // The closing braces are not annotated.  It doesn't seem to cause a
+  // problem.  So we only test for the opening braces.
+  auto Tokens = annotate("{\n"
+ "  {\n"
+ "{ int a = 0; }\n"
+ "  }\n"
+ "  {}\n"
+ "}");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[0], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[1], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[2], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[10], BK_Block);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -55,6 +55,15 @@
 
 TEST_F(FormatTest, FormatsNestedBlockStatements) {
   EXPECT_EQ("{\n  {\n{}\n  }\n}", format("{{{}}}"));
+  // The innermost block is on a single line because a block with only 1
+  // statement is hard-coded to be squeezed into one line in
+  // ContinuationIndenter, not because it is recognized as an initializer list.
+  verifyFormat("int main() {\n"
+   "  {\n"
+   "{ int a = 0; }\n"
+   "  }\n"
+   "  {}\n"
+   "}");
 }
 
 TEST_F(FormatTest, FormatsNestedCall) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -488,10 +488,17 @@
   unsigned StoredPosition = Tokens->getPosition();
   FormatToken *Tok = FormatTok;
   const FormatToken *PrevTok = Tok->Previous;
+  // A rough guess at whether a block is a lambda expression.
+  bool ProbablyLambda = false;
   // Keep a stack of positions of lbrace tokens. We will
   // update information about whether an lbrace starts a
   // braced init list or a different block during the loop.
-  SmallVector LBraceStack;
+  struct StackEntry {
+FormatToken *Tok;
+const FormatToken *PrevTok, *NextTok;
+bool ProbablyLambda;
+  };
+  SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
 // Get next non-comment token.
@@ -521,12 +528,13 @@
   } else {
 Tok->setBlockKind(BK_Unknown);
   }
-  LBraceStack.push_back(Tok);
+  LBraceStack.push_back({Tok, PrevTok, NextTok, ProbablyLambda});
   break;
 case tok::r_brace:
   if (LBraceStack.empty())
 break;
-  if (LBraceStack.back()->is(BK_Unknown)) {
+  switch (LBraceStack.back().Tok->getBlockKind()) {
+  case BK_Unknown: {
 bool ProbablyBracedList = false;
 if (Style.Language == FormatStyle::LK_Proto) {
   ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square);
@@ -554,7 +562,7 @@
 
   // If we already marked the opening brace as braced list, the closing
   // must also be part of it.
-  ProbablyBracedList = LBraceStack.back()->is(TT_BracedListLBrace);
+  ProbablyBracedList = LBraceStack.back().Tok->is(TT_BracedListLBrace);
 
   ProbablyBracedList = ProbablyBracedList ||
(Style.isJavaScript() &&
@@ -595,15 +603,43 @@
   

[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-05-12 Thread John Brawn via Phabricator via cfe-commits
john.brawn planned changes to this revision.
john.brawn added a comment.

The clang-tidy failures in pre-merge are because

- clang-tidy tests use the compile database from building llvm (though you have 
to manually copy it otherwise the tests silently pass without actually running 
the test, which is why I wasn't seeing this locally)
- this has -D_GNU_SOURCE because llvm/cmake/config-ix.cmake adds it to the 
defines
- clang predefines _GNU_SOURCE when compiling C++ (for certain targets)
- therefore we get the warning for a redefined builtin

I'm not sure yet what the best fix is here. gcc has the same behaviour of 
defining _GNU_SOURCE for C++, but does it by adding -D_GNU_SOURCE to the cc1 
command line so it doesn't give a warning on redefine, but it doesn't look like 
copying this behaviour in clang would be easy. I'll think about this some more.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144654/new/

https://reviews.llvm.org/D144654

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 4 inline comments as done.
erichkeane added a subscriber: Mordante.
erichkeane added a comment.

In D150450#4337858 , @cor3ntin wrote:

> Similar PR here https://reviews.llvm.org/D149875

Ah! I'd not noticed that one (or maybe someone mentioned it?).  If @Mordante 
wants to take this over/change his to meet our RFC, I'm all for it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149562: [clang-format] Stop comment disrupting indentation of Verilog ports

2023-05-12 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

> I agree if the brace doesn't start a block, but clang-format sometimes got it 
> wrong and misannotates a block as a braced list. (See 
> https://github.com/llvm/llvm-project/issues/33891 for an example.)

This patch isn't affected by the problem.  The Verilog port list is not as 
ambiguous as braced blocks.

> I'll go along with other reviewers on this one.

So what do the other reviewers think about this patch?  The braced 
initialization list thing was added a long time ago by DJasper, so that 
behavior probably has to stay.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149562/new/

https://reviews.llvm.org/D149562

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 521661.
erichkeane added a comment.

Update based on @cor3ntin s feedback.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

Files:
  clang/docs/CommandGuide/clang.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangStandard.h
  clang/include/clang/Basic/LangStandards.def
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Driver/unknown-std.cpp
  clang/test/Preprocessor/init.c
  clang/www/OpenProjects.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -65,6 +65,11 @@
  -std=c++23
  Partial
 
+
+ C++2c
+ -std=c++2c
+ Partial
+
 
 
 The Clang community is continually striving to improve C++ standards
@@ -1560,6 +1565,25 @@
 
 
 
+C++2c implementation status
+
+
+Clang has support for some of the features of the C++ standard following
+C++23, informally referred to as C++26.
+
+You can use Clang in C++2c mode with the -std=c++2c option.
+
+
+List of features and minimum Clang version with support
+
+ 
+Language Feature
+C++26 Proposal
+Available in Clang?
+ 
+ 
+ 
+
 Defect reports
 
 Clang generally aims to implement resolutions to Defect Reports (bug fixes
Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -123,7 +123,7 @@
 
 
 
-Continue work on C++20, C++23, and C2x support:
+Continue work on C++20, C++23, C++2c, and C2x support:
   There are still several C++20 features to complete, and work has begun on
   supporting the latest language standards. Please see the
   C++ status report page to find out what is
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -8,8 +8,18 @@
 // BLOCKS:#define __BLOCKS__ 1
 // BLOCKS:#define __block __attribute__((__blocks__(byref)))
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+//
+// CXX26:#define __GNUG__ 4
+// CXX26:#define __GXX_EXPERIMENTAL_CXX0X__ 1
+// CXX26:#define __GXX_RTTI 1
+// CXX26:#define __GXX_WEAK__ 1
+// CXX26:#define __cplusplus 202102L
+// CXX26:#define __private_extern__ extern
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
 //
 // CXX2B:#define __GNUG__ 4
 // CXX2B:#define __GXX_EXPERIMENTAL_CXX0X__ 1
@@ -133,7 +143,16 @@
 // RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+//
+// GXX26:#define __GNUG__ 4
+// GXX26:#define __GXX_WEAK__ 1
+// GXX26:#define __cplusplus 202102L
+// GXX26:#define __private_extern__ extern
+//
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
 //
 // GXX2B:#define __GNUG__ 4
 // GXX2B:#define __GXX_WEAK__ 1
Index: clang/test/Driver/unknown-std.cpp
===
--- clang/test/Driver/unknown-std.cpp
+++ clang/test/Driver/unknown-std.cpp
@@ -19,6 +19,8 @@
 // CHECK-NEXT: note: use 'gnu++20' for 'ISO C++ 2020 DIS with GNU extensions' standard
 // CHECK-NEXT: note: use 'c++23' for 'ISO C++ 2023 DIS' standard
 // CHECK-NEXT: note: use 'gnu++23' for 'ISO C++ 2023 DIS with GNU extensions' standard
+// CHECK-NEXT: note: use 'c++2c' or 'c++26' for 'Working draft for ISO C++ 2026 DIS' standard
+// CHECK-NEXT: note: use 'gnu++2c' or 'gnu++26' for 'Working draft for ISO C++ 2026 DIS with GNU extensions' standard
 // CUDA-NEXT: note: use 'cuda' for 'NVIDIA CUDA(tm)' standard
 
 // Make sure that no other output is present.
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreproces

[clang] fd55636 - [clang] Restores some -std=c++2b tests.

2023-05-12 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2023-05-12T17:44:59+02:00
New Revision: fd556368a1a85eda27c2490331646b2913f16527

URL: 
https://github.com/llvm/llvm-project/commit/fd556368a1a85eda27c2490331646b2913f16527
DIFF: 
https://github.com/llvm/llvm-project/commit/fd556368a1a85eda27c2490331646b2913f16527.diff

LOG: [clang] Restores some -std=c++2b tests.

These tests should have added -std=c++23 instead of replacing -std=c++2b
in D149553.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D150063

Added: 


Modified: 
clang/test/Preprocessor/init.c

Removed: 




diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index f4d4a5793b080..9d27f12b9861c 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -10,6 +10,7 @@
 //
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix CXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix CXX2B %s
 //
 // CXX2B:#define __GNUG__ 4
 // CXX2B:#define __GXX_EXPERIMENTAL_CXX0X__ 1
@@ -134,6 +135,7 @@
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null 
| FileCheck -match-full-lines -check-prefix GXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null 
| FileCheck -match-full-lines -check-prefix GXX2B %s
 //
 // GXX2B:#define __GNUG__ 4
 // GXX2B:#define __GXX_WEAK__ 1



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150063: [clang] Restores some -std=c++2b tests.

2023-05-12 Thread Mark de Wever via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd556368a1a8: [clang] Restores some -std=c++2b tests. 
(authored by Mordante).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150063/new/

https://reviews.llvm.org/D150063

Files:
  clang/test/Preprocessor/init.c


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -10,6 +10,7 @@
 //
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix CXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix CXX2B %s
 //
 // CXX2B:#define __GNUG__ 4
 // CXX2B:#define __GXX_EXPERIMENTAL_CXX0X__ 1
@@ -134,6 +135,7 @@
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null 
| FileCheck -match-full-lines -check-prefix GXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null 
| FileCheck -match-full-lines -check-prefix GXX2B %s
 //
 // GXX2B:#define __GNUG__ 4
 // GXX2B:#define __GXX_WEAK__ 1


Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -10,6 +10,7 @@
 //
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
 //
 // CXX2B:#define __GNUG__ 4
 // CXX2B:#define __GXX_EXPERIMENTAL_CXX0X__ 1
@@ -134,6 +135,7 @@
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
 //
 // GXX2B:#define __GNUG__ 4
 // GXX2B:#define __GXX_WEAK__ 1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150452: [clang-format] Recognize nested blocks

2023-05-12 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 521667.
sstwcw added a comment.

- Remove the special case for operator[], it isn't necessary.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150452/new/

https://reviews.llvm.org/D150452

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -40,6 +40,8 @@
   EXPECT_EQ((FormatTok)->getType(), Type) << *(FormatTok)
 #define EXPECT_TOKEN_PRECEDENCE(FormatTok, Prec)   \
   EXPECT_EQ((FormatTok)->getPrecedence(), Prec) << *(FormatTok)
+#define EXPECT_BRACE_KIND(FormatTok, Kind) \
+  EXPECT_EQ(FormatTok->getBlockKind(), Kind)
 #define EXPECT_TOKEN(FormatTok, Kind, Type)\
   do { \
 EXPECT_TOKEN_KIND(FormatTok, Kind);\
@@ -1783,6 +1785,22 @@
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {
+  // The closing braces are not annotated.  It doesn't seem to cause a
+  // problem.  So we only test for the opening braces.
+  auto Tokens = annotate("{\n"
+ "  {\n"
+ "{ int a = 0; }\n"
+ "  }\n"
+ "  {}\n"
+ "}");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[0], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[1], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[2], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[10], BK_Block);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -55,6 +55,15 @@
 
 TEST_F(FormatTest, FormatsNestedBlockStatements) {
   EXPECT_EQ("{\n  {\n{}\n  }\n}", format("{{{}}}"));
+  // The innermost block is on a single line because a block with only 1
+  // statement is hard-coded to be squeezed into one line in
+  // ContinuationIndenter, not because it is recognized as an initializer list.
+  verifyFormat("int main() {\n"
+   "  {\n"
+   "{ int a = 0; }\n"
+   "  }\n"
+   "  {}\n"
+   "}");
 }
 
 TEST_F(FormatTest, FormatsNestedCall) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -488,10 +488,17 @@
   unsigned StoredPosition = Tokens->getPosition();
   FormatToken *Tok = FormatTok;
   const FormatToken *PrevTok = Tok->Previous;
+  // A rough guess at whether a block is a lambda expression.
+  bool ProbablyLambda = false;
   // Keep a stack of positions of lbrace tokens. We will
   // update information about whether an lbrace starts a
   // braced init list or a different block during the loop.
-  SmallVector LBraceStack;
+  struct StackEntry {
+FormatToken *Tok;
+const FormatToken *PrevTok, *NextTok;
+bool ProbablyLambda;
+  };
+  SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
 // Get next non-comment token.
@@ -521,12 +528,13 @@
   } else {
 Tok->setBlockKind(BK_Unknown);
   }
-  LBraceStack.push_back(Tok);
+  LBraceStack.push_back({Tok, PrevTok, NextTok, ProbablyLambda});
   break;
 case tok::r_brace:
   if (LBraceStack.empty())
 break;
-  if (LBraceStack.back()->is(BK_Unknown)) {
+  switch (LBraceStack.back().Tok->getBlockKind()) {
+  case BK_Unknown: {
 bool ProbablyBracedList = false;
 if (Style.Language == FormatStyle::LK_Proto) {
   ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square);
@@ -554,7 +562,7 @@
 
   // If we already marked the opening brace as braced list, the closing
   // must also be part of it.
-  ProbablyBracedList = LBraceStack.back()->is(TT_BracedListLBrace);
+  ProbablyBracedList = LBraceStack.back().Tok->is(TT_BracedListLBrace);
 
   ProbablyBracedList = ProbablyBracedList ||
(Style.isJavaScript() &&
@@ -595,15 +603,43 @@
 }
 if (ProbablyBracedList) {
   Tok->setBlockKind(BK_BracedInit);
-  LBraceStack.back()->setBlockKind(BK_BracedInit);
+  LBraceStack.back().Tok->setBlockKind(BK_BracedInit);
 } else {
   Tok->setBlockKind(BK_Block);
-  LBraceStack.back()->setBlockKind(BK_Block);
+   

[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D150450#4337952 , @erichkeane 
wrote:

> In D150450#4337858 , @cor3ntin 
> wrote:
>
>> Similar PR here https://reviews.llvm.org/D149875
>
> Ah! I'd not noticed that one (or maybe someone mentioned it?).  If @Mordante 
> wants to take this over/change his to meet our RFC, I'm all for it.

I've mentioned it in 
https://discourse.llvm.org/t/rfc-lets-just-call-it-c-26-and-forget-about-the-c-2c-business-at-least-internally/70383/3
 to avoid duplicated effort.

It seems, as expected. the patches have a large overlap, but you added a bit 
more of the status page and I updated the clang-cl driver.

I just updated my patch before I saw this update in the mail.




Comment at: clang/lib/Frontend/InitPreprocessor.cpp:457
+  Builder.defineMacro("__cplusplus", "202402L");
+g/ FIXME: Use correct value for C++23, and update C++26 to be 'one more'.
+else if (LangOpts.CPlusPlus23)

Note this has been committed in the draft for N4950.
https://github.com/cplusplus/draft/commit/4e4de1df8ee941255b653b61d0a62050b34cf8c9#diff-1b14eeb3be43fba46b5d0ff51fe0695c9a856544d1f45b1d486f98f5e1b889bf



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 521675.
erichkeane marked an inline comment as done.
erichkeane added a comment.

fix init-preprocessor, remove fixme.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

Files:
  clang/docs/CommandGuide/clang.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangStandard.h
  clang/include/clang/Basic/LangStandards.def
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Driver/unknown-std.cpp
  clang/test/Preprocessor/init.c
  clang/www/OpenProjects.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -65,6 +65,11 @@
  -std=c++23
  Partial
 
+
+ C++2c
+ -std=c++2c
+ Partial
+
 
 
 The Clang community is continually striving to improve C++ standards
@@ -1560,6 +1565,25 @@
 
 
 
+C++2c implementation status
+
+
+Clang has support for some of the features of the C++ standard following
+C++23, informally referred to as C++26.
+
+You can use Clang in C++2c mode with the -std=c++2c option.
+
+
+List of features and minimum Clang version with support
+
+ 
+Language Feature
+C++26 Proposal
+Available in Clang?
+ 
+ 
+ 
+
 Defect reports
 
 Clang generally aims to implement resolutions to Defect Reports (bug fixes
Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -123,7 +123,7 @@
 
 
 
-Continue work on C++20, C++23, and C2x support:
+Continue work on C++20, C++23, C++2c, and C2x support:
   There are still several C++20 features to complete, and work has begun on
   supporting the latest language standards. Please see the
   C++ status report page to find out what is
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -8,8 +8,18 @@
 // BLOCKS:#define __BLOCKS__ 1
 // BLOCKS:#define __block __attribute__((__blocks__(byref)))
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+//
+// CXX26:#define __GNUG__ 4
+// CXX26:#define __GXX_EXPERIMENTAL_CXX0X__ 1
+// CXX26:#define __GXX_RTTI 1
+// CXX26:#define __GXX_WEAK__ 1
+// CXX26:#define __cplusplus 202102L
+// CXX26:#define __private_extern__ extern
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
 //
 // CXX2B:#define __GNUG__ 4
 // CXX2B:#define __GXX_EXPERIMENTAL_CXX0X__ 1
@@ -133,7 +143,16 @@
 // RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+//
+// GXX26:#define __GNUG__ 4
+// GXX26:#define __GXX_WEAK__ 1
+// GXX26:#define __cplusplus 202102L
+// GXX26:#define __private_extern__ extern
+//
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
 //
 // GXX2B:#define __GNUG__ 4
 // GXX2B:#define __GXX_WEAK__ 1
Index: clang/test/Driver/unknown-std.cpp
===
--- clang/test/Driver/unknown-std.cpp
+++ clang/test/Driver/unknown-std.cpp
@@ -19,6 +19,8 @@
 // CHECK-NEXT: note: use 'gnu++20' for 'ISO C++ 2020 DIS with GNU extensions' standard
 // CHECK-NEXT: note: use 'c++23' for 'ISO C++ 2023 DIS' standard
 // CHECK-NEXT: note: use 'gnu++23' for 'ISO C++ 2023 DIS with GNU extensions' standard
+// CHECK-NEXT: note: use 'c++2c' or 'c++26' for 'Working draft for ISO C++ 2026 DIS' standard
+// CHECK-NEXT: note: use 'gnu++2c' or 'gnu++26' for 'Working draft for ISO C++ 2026 DIS with GNU extensions' standard
 // CUDA-NEXT: note: use 'cuda' for 'NVIDIA CUDA(tm)' standard
 
 // Make sure that no other output is present.
Index: clang/lib/Frontend/InitPreprocessor.cpp

[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D150450#4338034 , @Mordante wrote:

> In D150450#4337952 , @erichkeane 
> wrote:
>
>> In D150450#4337858 , @cor3ntin 
>> wrote:
>>
>>> Similar PR here https://reviews.llvm.org/D149875
>>
>> Ah! I'd not noticed that one (or maybe someone mentioned it?).  If @Mordante 
>> wants to take this over/change his to meet our RFC, I'm all for it.
>
> I've mentioned it in 
> https://discourse.llvm.org/t/rfc-lets-just-call-it-c-26-and-forget-about-the-c-2c-business-at-least-internally/70383/3
>  to avoid duplicated effort.
>
> It seems, as expected. the patches have a large overlap, but you added a bit 
> more of the status page and I updated the clang-cl driver.
>
> I just updated my patch before I saw this update in the mail.

Woops, looks like that was long enough ago I completely forgot about it :)

Completely up to you if you want to just steal my stuff and we can go with your 
review, or you want to just help me fill in anything I missed here.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 521680.
erichkeane added a comment.

Added clang-cl versioning as stolen from @Mordante


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

Files:
  clang/docs/CommandGuide/clang.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangStandard.h
  clang/include/clang/Basic/LangStandards.def
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Driver/unknown-std.cpp
  clang/test/Preprocessor/init.c
  clang/www/OpenProjects.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -65,6 +65,11 @@
  -std=c++23
  Partial
 
+
+ C++2c
+ -std=c++2c
+ Partial
+
 
 
 The Clang community is continually striving to improve C++ standards
@@ -1560,6 +1565,25 @@
 
 
 
+C++2c implementation status
+
+
+Clang has support for some of the features of the C++ standard following
+C++23, informally referred to as C++26.
+
+You can use Clang in C++2c mode with the -std=c++2c option.
+
+
+List of features and minimum Clang version with support
+
+ 
+Language Feature
+C++26 Proposal
+Available in Clang?
+ 
+ 
+ 
+
 Defect reports
 
 Clang generally aims to implement resolutions to Defect Reports (bug fixes
Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -123,7 +123,7 @@
 
 
 
-Continue work on C++20, C++23, and C2x support:
+Continue work on C++20, C++23, C++2c, and C2x support:
   There are still several C++20 features to complete, and work has begun on
   supporting the latest language standards. Please see the
   C++ status report page to find out what is
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -8,8 +8,18 @@
 // BLOCKS:#define __BLOCKS__ 1
 // BLOCKS:#define __block __attribute__((__blocks__(byref)))
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+//
+// CXX26:#define __GNUG__ 4
+// CXX26:#define __GXX_EXPERIMENTAL_CXX0X__ 1
+// CXX26:#define __GXX_RTTI 1
+// CXX26:#define __GXX_WEAK__ 1
+// CXX26:#define __cplusplus 202102L
+// CXX26:#define __private_extern__ extern
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
 //
 // CXX2B:#define __GNUG__ 4
 // CXX2B:#define __GXX_EXPERIMENTAL_CXX0X__ 1
@@ -133,7 +143,16 @@
 // RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+//
+// GXX26:#define __GNUG__ 4
+// GXX26:#define __GXX_WEAK__ 1
+// GXX26:#define __cplusplus 202102L
+// GXX26:#define __private_extern__ extern
+//
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
 //
 // GXX2B:#define __GNUG__ 4
 // GXX2B:#define __GXX_WEAK__ 1
Index: clang/test/Driver/unknown-std.cpp
===
--- clang/test/Driver/unknown-std.cpp
+++ clang/test/Driver/unknown-std.cpp
@@ -19,6 +19,8 @@
 // CHECK-NEXT: note: use 'gnu++20' for 'ISO C++ 2020 DIS with GNU extensions' standard
 // CHECK-NEXT: note: use 'c++23' for 'ISO C++ 2023 DIS' standard
 // CHECK-NEXT: note: use 'gnu++23' for 'ISO C++ 2023 DIS with GNU extensions' standard
+// CHECK-NEXT: note: use 'c++2c' or 'c++26' for 'Working draft for ISO C++ 2026 DIS' standard
+// CHECK-NEXT: note: use 'gnu++2c' or 'gnu++26' for 'Working draft for ISO C++ 2026 DIS with GNU extensions' standard
 // CUDA-NEXT: note: use 'cuda' for 'NVIDIA CUDA(tm)' standard
 
 // Make sure that no other output is present.
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/

[PATCH] D145343: [AMDGPU] Emit predefined macro `__AMDGCN_CUMODE__`

2023-05-12 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:146
+return false;
+  return TargetFeature == "no-cumode";
+}

yaxunl wrote:
> arsenm wrote:
> > I don't understand the use of "no-cumode". Where is this defined?
> This function is called by clang driver. The argument TargetFeature is the 
> target feature command line option to be checked, with `-m` removed, e.g. 
> `-mcumode` or `-mno-cumode` passed to this function as "cumode" or 
> "no-cumode".
Can this use something like


```
  if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
  options::OPT_fno_gpu_sanitize, true))
return true;
```

to make it clear this is checking the flag? At a minimum this needs to be 
renamed to indicate it's a flag and not the actual subtarget feature name 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145343/new/

https://reviews.llvm.org/D145343

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-12 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann requested changes to this revision.
tahonermann added a comment.
This revision now requires changes to proceed.

> I do wonder if we need two bfloat implementations, but for that I'll leave a 
> comment on D149573 .

Given the discussions occurring in D149573 , 
let's hold off on landing this for now. It is sounding like we might have 
direction for repurposing `__bf16` for `std::bfloat16_t` (and a future 
`_BFloat16` C type; with `__bf16` retained as an alternate spelling). If we go 
in that direction, then we would presumably want a change that goes in the 
opposite direction of this patch; a change that migrates "bf16" names towards 
"bfloat16". Let's focus on confirming that direction first. I'll mark this as 
requesting changes for now while we figure this out.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150291/new/

https://reviews.llvm.org/D150291

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150427: [AMDGPU] Non hostcall printf support for HIP

2023-05-12 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.def:274
 LANGOPT(OffloadingNewDriver, 1, 0, "use the new driver for generating 
offloading code.")
+ENUM_LANGOPT(AMDGPUPrintfKindVal, AMDGPUPrintfKind, 2, 
AMDGPUPrintfKind::Buffered, "printf lowering scheme to be used, hostcall or 
buffer based")
 

This should be a target option like https://reviews.llvm.org/D91546 instead of 
a language option since it is target specific.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4663-4664
+
+if (JA.isDeviceOffloading(Action::OFK_HIP) &&
+(types::isHIP(Input.getType()) || types::isLLVMIR(Input.getType( {
+  // Device side compilation printf

You can check whether target triple is amdgpu instead.



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:416
+
 Value *llvm::emitAMDGPUPrintfCall(IRBuilder<> &Builder,
+  ArrayRef Args, bool isBuffered) {

Please add some comments about the transformations done for buffered and 
non-buffered cases. Better provide a simple example.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150427/new/

https://reviews.llvm.org/D150427

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Mark de Wever via Phabricator via cfe-commits
Mordante accepted this revision.
Mordante added a comment.
This revision is now accepted and ready to land.

In D150450#4338065 , @erichkeane 
wrote:

> In D150450#4338034 , @Mordante 
> wrote:
>
>> In D150450#4337952 , @erichkeane 
>> wrote:
>>
>>> In D150450#4337858 , @cor3ntin 
>>> wrote:
>>>
 Similar PR here https://reviews.llvm.org/D149875
>>>
>>> Ah! I'd not noticed that one (or maybe someone mentioned it?).  If 
>>> @Mordante wants to take this over/change his to meet our RFC, I'm all for 
>>> it.
>>
>> I've mentioned it in 
>> https://discourse.llvm.org/t/rfc-lets-just-call-it-c-26-and-forget-about-the-c-2c-business-at-least-internally/70383/3
>>  to avoid duplicated effort.
>>
>> It seems, as expected. the patches have a large overlap, but you added a bit 
>> more of the status page and I updated the clang-cl driver.
>>
>> I just updated my patch before I saw this update in the mail.
>
> Woops, looks like that was long enough ago I completely forgot about it :)
>
> Completely up to you if you want to just steal my stuff and we can go with 
> your review, or you want to just help me fill in anything I missed here.

No problem. I think it's easier to land this patch instead of me stealing your 
work.
I mainly care that Clang get C++2c support so I can prepare libc++ for C++2c.

LGTM after `clang/test/Driver/cl-options.c` is fixed.




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6650
  // TODO add c++23 when MSVC supports it.
- .Case("c++latest", "-std=c++23")
+ .Case("c++latest", "-std=c++26")
  .Default("");

The CI will fail in the test clang/test/Driver/cl-options.c
see https://reviews.llvm.org/D149875#change-s8WC0AhDg4dT



Comment at: clang/test/Preprocessor/init.c:22
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix CXX2B %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix CXX2B %s
 //

I had noticed I missed this too, this landed earlier today D150063.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150427: [AMDGPU] Non hostcall printf support for HIP

2023-05-12 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1036
+  NormalizedValues<["Hostcall", "Buffered"]>,
+  MarshallingInfoEnum, "Hostcall">;
 def fgpu_default_stream_EQ : Joined<["-"], "fgpu-default-stream=">,

as a target option, usually it starts with `-m` and does not contain target 
name, e.g. `-mprintf=`.

Better describe allowed values and their effect from users point of view, e.g. 
hostcall outputs immediately during kernel execution but requires some hardware 
feature.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150427/new/

https://reviews.llvm.org/D150427

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names and introduce Bfloat16 arithmetic type.

2023-05-12 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs marked an inline comment as done.
codemzs added a comment.

In D149573#4337480 , @stuij wrote:

> I made a comment on the RFC 
> 
>  to understand if we really need/want a new bfloat16 type.

Thank you, @stuij, for your input. I will continue to follow the consensus on 
the RFC regarding the introduction of a new bfloat16 type. For context, my 
initial implementation transitioned the existing storage-only `__bf16` type 
into an arithmetic type. If the decision leans towards not introducing a new 
`bfloat16` type, I'm prepared to revert my changes to utilize the `__bf16` 
type. To ensure our collective efforts are effectively streamlined and avoid 
any potential duplication, I am committed to aligning my work with the 
community consensus and ongoing discussions.

@tahonermann, when you have a moment, your guidance would be greatly 
appreciated.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149573/new/

https://reviews.llvm.org/D149573

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 521688.
erichkeane added a comment.

Updated last few things @Mordante  mentioned, did a rebase.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

Files:
  clang/docs/CommandGuide/clang.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangStandard.h
  clang/include/clang/Basic/LangStandards.def
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Driver/cl-options.c
  clang/test/Driver/unknown-std.cpp
  clang/test/Preprocessor/init.c
  clang/www/OpenProjects.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -65,6 +65,11 @@
  -std=c++23
  Partial
 
+
+ C++2c
+ -std=c++2c
+ Partial
+
 
 
 The Clang community is continually striving to improve C++ standards
@@ -1560,6 +1565,25 @@
 
 
 
+C++2c implementation status
+
+
+Clang has support for some of the features of the C++ standard following
+C++23, informally referred to as C++26.
+
+You can use Clang in C++2c mode with the -std=c++2c option.
+
+
+List of features and minimum Clang version with support
+
+ 
+Language Feature
+C++26 Proposal
+Available in Clang?
+ 
+ 
+ 
+
 Defect reports
 
 Clang generally aims to implement resolutions to Defect Reports (bug fixes
Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -123,7 +123,7 @@
 
 
 
-Continue work on C++20, C++23, and C2x support:
+Continue work on C++20, C++23, C++2c, and C2x support:
   There are still several C++20 features to complete, and work has begun on
   supporting the latest language standards. Please see the
   C++ status report page to find out what is
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -8,6 +8,15 @@
 // BLOCKS:#define __BLOCKS__ 1
 // BLOCKS:#define __block __attribute__((__blocks__(byref)))
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+//
+// CXX26:#define __GNUG__ 4
+// CXX26:#define __GXX_EXPERIMENTAL_CXX0X__ 1
+// CXX26:#define __GXX_RTTI 1
+// CXX26:#define __GXX_WEAK__ 1
+// CXX26:#define __cplusplus 202102L
+// CXX26:#define __private_extern__ extern
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
@@ -134,6 +143,14 @@
 // RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+//
+// GXX26:#define __GNUG__ 4
+// GXX26:#define __GXX_WEAK__ 1
+// GXX26:#define __cplusplus 202102L
+// GXX26:#define __private_extern__ extern
+//
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
 //
Index: clang/test/Driver/unknown-std.cpp
===
--- clang/test/Driver/unknown-std.cpp
+++ clang/test/Driver/unknown-std.cpp
@@ -19,6 +19,8 @@
 // CHECK-NEXT: note: use 'gnu++20' for 'ISO C++ 2020 DIS with GNU extensions' standard
 // CHECK-NEXT: note: use 'c++23' for 'ISO C++ 2023 DIS' standard
 // CHECK-NEXT: note: use 'gnu++23' for 'ISO C++ 2023 DIS with GNU extensions' standard
+// CHECK-NEXT: note: use 'c++2c' or 'c++26' for 'Working draft for ISO C++ 2026 DIS' standard
+// CHECK-NEXT: note: use 'gnu++2c' or 'gnu++26' for 'Working draft for ISO C++ 2026 DIS with GNU extensions' standard
 // CUDA-NEXT: note: use 'cuda' for 'NVIDIA CUDA(tm)' standard
 
 // Make sure that no other output is present.
Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -604,7 +604,7 @@
 // STDCXX20: -std=c++20
 
 // RUN: %clang

[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.

LGTM. I'm looking forward to start implementing upcoming proposals


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-12 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D150226#4336755 , @rupprecht wrote:

> We're still using `-Wno-enum-constexpr-conversion`, although I'm not sure if 
> we need that or if we just forgot to remove it after doing some cleanup. I'm 
> trying it out now. (Sorry, I'm not sure we were aware that having a way to 
> turn this off was just temporary).

Please let me know how things look on your end.

> BTW, LLVM itself still uses this flag in openmp: 
> https://github.com/llvm/llvm-project/blob/c2ce2a509f74a85a3c0ef4b9d6d79fbacc7e8bdf/openmp/cmake/HandleOpenMPOptions.cmake#L34

Thank you for flagging that.

I followed up on the PR that put in this change to see if they can remediate 
this.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150226/new/

https://reviews.llvm.org/D150226

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150461: [OpenMP] Naturally align internal global variables in the OpenMPIRBuilder

2023-05-12 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, ABataev, JonChesterfield, 
tstellar, gchatelet.
Herald added subscribers: sunshaoce, guansong, hiraditya, yaxunl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1.
Herald added projects: clang, LLVM.

We use this helper to make several internal global variables during
codegen. currently we do not specify any alignment which allows the
alignment to be set incorrectly after some changes in how alignment was
handled. This patch explicitly aligns these variables to the natural
alignment as specified by the data layout

Fixes https://github.com/llvm/llvm-project/issues/62668


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150461

Files:
  clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/for_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_master_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_sections_reduction_task_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/sections_reduction_task_codegen.cpp
  clang/test/OpenMP/target_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/target_parallel_reduction_task_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/taskloop_reduction_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4225,10 +4225,12 @@
 // variable for possibly changing that to internal or private, or maybe
 // create different versions of the function for different OMP internal
 // variables.
-Elem.second = new GlobalVariable(
+auto *GV = new GlobalVariable(
 M, Ty, /*IsConstant=*/false, GlobalValue::CommonLinkage,
 Constant::getNullValue(Ty), Elem.first(),
 /*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
+GV->setAlignment(M.getDataLayout().getABITypeAlign(Ty));
+Elem.second = GV;
   }
 
   return cast(&*Elem.second);
Index: clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
===
--- clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
+++ clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
@@ -348,7 +348,7 @@
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
 // CHECK1-NEXT:[[TMP2:%.*]] = load ptr, ptr [[DOTADDR]], align 8
-// CHECK1-NEXT:[[TMP3:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP3:%.*]] = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP4:%.*]] = load i64, ptr [[TMP3]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP4]]
 // CHECK1-NEXT:[[OMP_ARRAYINIT_ISEMPTY:%.*]] = icmp eq ptr [[TMP2]], [[TMP5]]
@@ -370,7 +370,7 @@
 // CHECK1-NEXT:[[DOTADDR1:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
-// CHECK1-NEXT:[[TMP2:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP2:%.*]] = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP3:%.*]] = load i64, ptr [[TMP2]], align 8
 // CHECK1-NEXT:[[TMP4:%.*]] = load ptr, ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = load ptr, ptr [[DOTADDR1]], align 8
@@ -712,7 +712,7 @@
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
 // CHECK1-NEXT:[[TMP2:%.*]] = load ptr, ptr [[DOTADDR]], align 8
-// CHECK1-NEXT:[[TMP3:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP3:%.*]] = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP4:%.*]] = load i64, ptr [[TMP3]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP4]]
 // CHECK1-NEXT:[[OMP_ARRAYINIT_ISEMPTY:%.*]] = icmp eq ptr [[TMP2]], [[TMP5]]
@@ -734,7 +734,7 @@
 // CHECK1-NEXT:[[DOTADDR1:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTAD

[PATCH] D150461: [OpenMP] Naturally align internal global variables in the OpenMPIRBuilder

2023-05-12 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 accepted this revision.
tianshilei1992 added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150461/new/

https://reviews.llvm.org/D150461

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149997: [clang] [test] Narrow down MSVC specific behaviours from "any windows" to only MSVC/clang-cl

2023-05-12 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D149997#4337548 , @mstorsjo wrote:

> So, the reason why this failed, is that when invoked as `%clang_cc1` in a 
> MSVC/clang-cl style build, `_MSC_VER` isn't predefined, while `_WIN32` is. 
> When invoked via the Clang driver instead of directly going at `-cc1`, 
> `_MSC_VER` does get defined.
>
> @rnk @hans @thakis - who know the intricacies of the MSVC target - do you 
> happen to know why that is? How do I distinguish between MSVC-style behaviour 
> and other cases (in particular, mingw) in a `%clang_cc1` test? Currently it 
> uses `#idef _WIN32` but that's incorrect for mingw.

I think `_MSC_EXTENSIONS` will work, but it's kind of gross. `_MSC_VER` is 
controlled by `-fms-compatibility-verson=`, which I think is off by default or 
unset at the cc1 level:
https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/OSTargets.cpp#L206
`-fms-extensions` is on by default at cc1, I think.

This isn't great. It would be nice to have some kind of feature test mechanism 
for "which C++ ABI am I using, Itanium, one of the variants, or Microsoft".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149997/new/

https://reviews.llvm.org/D149997

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-12 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D150226#4336771 , @manojgupta 
wrote:

> We also use Wno-enum-constexpr-conversion in ChromeOS. There are many 
> packages that break with this warning. One of them is boost which is used in 
> many other packages.
>
> The errors in boost were:
>
>   ./boost/mpl/aux_/integral_wrapper.hpp:73:31: error: integer value -1 is 
> outside the valid range of values [0, 3] for this enumeration type 
> [-Wenum-constexpr-conversion]
>   ./boost/mpl/aux_/static_cast.hpp:24:47: note: expanded from macro 
> 'BOOST_MPL_AUX_STATIC_CAST'
>   #   define BOOST_MPL_AUX_STATIC_CAST(T, expr) static_cast(expr)
> ^
>
> I do not think boost upstream has updated these files, I see they were last 
> updated 3 years back.
> https://github.com/boostorg/mpl/blob/master/include/boost/mpl/aux_/static_cast.hpp
> and 
> https://github.com/boostorg/mpl/blob/master/include/boost/mpl/aux_/integral_wrapper.hpp

I was under the impression from https://github.com/boostorg/mpl/issues/69 that 
this was fixed but there are a number of issues off of the main one and maybe I 
am confused.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150226/new/

https://reviews.llvm.org/D150226

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150427: [AMDGPU] Non hostcall printf support for HIP

2023-05-12 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

Where does the runtime implementation of this live? I'm not very familiar with 
the HIP / hostcall ecosystem.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150427/new/

https://reviews.llvm.org/D150427

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145343: [AMDGPU] Emit predefined macro `__AMDGCN_CUMODE__`

2023-05-12 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 521714.
yaxunl marked an inline comment as done.
yaxunl added a comment.

revised by Matt's comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145343/new/

https://reviews.llvm.org/D145343

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/AMDGPU.h
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/Hexagon.h
  clang/test/CodeGenHIP/hip-cumode.hip
  clang/test/Driver/amdgpu-macros.cl
  clang/test/Driver/hip-macros.hip
  llvm/include/llvm/TargetParser/TargetParser.h
  llvm/lib/TargetParser/TargetParser.cpp

Index: llvm/lib/TargetParser/TargetParser.cpp
===
--- llvm/lib/TargetParser/TargetParser.cpp
+++ llvm/lib/TargetParser/TargetParser.cpp
@@ -107,21 +107,21 @@
   {{"gfx940"},{"gfx940"},  GK_GFX940,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
   {{"gfx941"},{"gfx941"},  GK_GFX941,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
   {{"gfx942"},{"gfx942"},  GK_GFX942,  FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_XNACK|FEATURE_SRAMECC},
-  {{"gfx1010"},   {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK},
-  {{"gfx1011"},   {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK},
-  {{"gfx1012"},   {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK},
-  {{"gfx1013"},   {"gfx1013"}, GK_GFX1013, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK},
-  {{"gfx1030"},   {"gfx1030"}, GK_GFX1030, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1031"},   {"gfx1031"}, GK_GFX1031, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1032"},   {"gfx1032"}, GK_GFX1032, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1033"},   {"gfx1033"}, GK_GFX1033, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1034"},   {"gfx1034"}, GK_GFX1034, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1035"},   {"gfx1035"}, GK_GFX1035, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1036"},   {"gfx1036"}, GK_GFX1036, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1100"},   {"gfx1100"}, GK_GFX1100, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1101"},   {"gfx1101"}, GK_GFX1101, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1102"},   {"gfx1102"}, GK_GFX1102, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
-  {{"gfx1103"},   {"gfx1103"}, GK_GFX1103, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32},
+  {{"gfx1010"},   {"gfx1010"}, GK_GFX1010, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
+  {{"gfx1011"},   {"gfx1011"}, GK_GFX1011, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
+  {{"gfx1012"},   {"gfx1012"}, GK_GFX1012, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
+  {{"gfx1013"},   {"gfx1013"}, GK_GFX1013, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_XNACK|FEATURE_WGP},
+  {{"gfx1030"},   {"gfx1030"}, GK_GFX1030, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1031"},   {"gfx1031"}, GK_GFX1031, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1032"},   {"gfx1032"}, GK_GFX1032, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1033"},   {"gfx1033"}, GK_GFX1033, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1034"},   {"gfx1034"}, GK_GFX1034, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1035"},   {"gfx1035"}, GK_GFX1035, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1036"},   {"gfx1036"}, GK_GFX1036, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1100"},   {"gfx1100"}, GK_GFX1100, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1101"},   {"gfx1101"}, GK_GFX1101, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1102"},   {"gfx1102"}, GK_GFX1102, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
+  {{"gfx1103"},   {"gfx1103"}, GK_GFX1103, FEATURE_FAST_FMA_F32|FEATURE_FAST_DENORMAL_F32|FEATURE_WAVE32|FEATURE_WGP},
 };

[PATCH] D150427: [AMDGPU] Non hostcall printf support for HIP

2023-05-12 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/include/clang/Basic/LangOptions.def:274
 LANGOPT(OffloadingNewDriver, 1, 0, "use the new driver for generating 
offloading code.")
+ENUM_LANGOPT(AMDGPUPrintfKindVal, AMDGPUPrintfKind, 2, 
AMDGPUPrintfKind::Buffered, "printf lowering scheme to be used, hostcall or 
buffer based")
 

yaxunl wrote:
> This should be a target option like https://reviews.llvm.org/D91546 instead 
> of a language option since it is target specific.
Should be -m option 



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4673
+ 
+  // unconditionally claim the pritnf option now to avoid unused diagnostic.
+  // TODO: OpenCL targets will should use this option to switch between

Capitalize, typo 'pritnf'



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:4674
+  // unconditionally claim the pritnf option now to avoid unused diagnostic.
+  // TODO: OpenCL targets will should use this option to switch between
+  // hostcall and buffered printf schemes.

Typo 'will should'

Don't really understand the TODO, this should trigger for OpenCL as it is



Comment at: clang/test/CodeGenHIP/printf_nonhostcall.cpp:5
+// RUN:   -o - %s | FileCheck --enable-var-scope %s
+
+#define __device__ __attribute__((device))

Do we need a test with -fno-builtin?



Comment at: clang/test/CodeGenHIP/printf_nonhostcall.cpp:69
+  const char *s = "hello world";
+  return printf("%.*f %*.*s %p\n", 8, 3.14159, 8, 4, s, s);
+}

Doesn't cover the full range of printable types. need some other non-string 
pointers and different address spaces, some FP promotions, 16 and 64 bit 
integers 



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:259-261
+  // This is a tradeoff. we might end up taking more compile
+  // time to calculate string contents if possible, but the generated
+  // code would be better runtime wise.

Don't understand the point of the comment, I would assume anything involving 
analysis of a constant string has ignorable compile time 



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:371-384
+Function *TheFn = Intrinsic::getDeclaration(
+Builder.GetInsertBlock()->getModule(), Intrinsic::memcpy, Tys);
+SmallVector BuffOffset;
+
+Value *FnArgs[] = {
+PtrToStore, Args[i], val,
+ConstantInt::get(Type::getInt1Ty(Builder.getContext()), false)};

Builder.CreateMemCpy



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:402
+  SmallVector BuffOffset;
+  uint offsetVal = toStore->getType()->getIntegerBitWidth() == 32 ? 4 : 8;
+  BuffOffset.push_back(ConstantInt::get(Builder.getInt32Ty(), offsetVal));

Just use the type store size



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:403
+  uint offsetVal = toStore->getType()->getIntegerBitWidth() == 32 ? 4 : 8;
+  BuffOffset.push_back(ConstantInt::get(Builder.getInt32Ty(), offsetVal));
+

You don't need a SmallVector to push back a single entry 



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:428
+SmallVector StringContents;
+llvm::Module *M = Builder.GetInsertBlock()->getModule();
+LLVMContext &Ctx = Builder.getContext();

Don't need llvm::



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:430
+LLVMContext &Ctx = Builder.getContext();
+auto Int1Ty = Builder.getInt1Ty();
+auto Int8Ty = Builder.getInt8Ty();

No auto 



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:458
+auto CreateControlDWord = M->getOrInsertFunction(
+StringRef("__ockl_create_control_dword"), Builder.getInt32Ty(),
+Builder.getInt32Ty(), Int1Ty, Int1Ty);

Do we really need another ockl control variable for this? Why isn't it a 
parameter? printf=stdout always 



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:473
+if (!FmtStr.empty()) {
+  llvm::MD5 Hasher;
+  llvm::MD5::MD5Result Hash;

Don't need llvm::



Comment at: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp:498
+  NamedMDNode *metaD = M->getOrInsertNamedMetadata("llvm.printf.fmts");
+  if(0 == metaD->getNumOperands()) {
+MDString *fmtStrArray = MDString::get(Ctx, "0:0:deadbeef,\"\"");

Backwards conditional 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150427/new/

https://reviews.llvm.org/D150427

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-12 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D150226#4336803 , @thesamesam 
wrote:

> Adding to the concerns raised above, I don't think we're there yet. See 
> https://bugs.gentoo.org/buglist.cgi?quicksearch=enum-constexpr-conversion&list_id=6843355
>  and keep in mind that a bunch of stuff isn't buildable with Clang 16 yet 
> anyway so I expect a bunch more to be broken on top of that.

Is there anything we can do to help move these along? We really want to fix 
this asap b/c we are not conforming at this point wrt constant expressions and 
this causes other undesirable issues w/ diagnostics and SFINAE that are easily 
fixable.

> Also, e.g. gdb isn't fixed in a release yet.

Can you give me a reference for the gdb issue?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150226/new/

https://reviews.llvm.org/D150226

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 49b87b0 - [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-12 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-05-12T10:46:06-07:00
New Revision: 49b87b05726b4395503230c3d400f93c626e6dce

URL: 
https://github.com/llvm/llvm-project/commit/49b87b05726b4395503230c3d400f93c626e6dce
DIFF: 
https://github.com/llvm/llvm-project/commit/49b87b05726b4395503230c3d400f93c626e6dce.diff

LOG: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

Inspired by D133662.
Close https://github.com/llvm/llvm-project/issues/57285

When -ftime-trace is specified and the driver performs both compilation and
linking phases, the trace files are currently placed in the temporary directory
(/tmp by default on *NIX). A more sensible behavior would be to derive the trace
file names from the -o option, similar to how GCC derives auxiliary and dump
file names. Use -dumpdir (D149193) to implement the -gsplit-dwarf like behavior.

The following script demonstrates the time trace filenames.

```
#!/bin/sh -e
PATH=/tmp/Rel/bin:$PATH# adapt according to your build directory
mkdir -p d e f
echo 'int main() {}' > d/a.c
echo > d/b.c

a() { rm $1 || exit 1; }

clang -ftime-trace d/a.c d/b.c # previously /tmp/[ab]-*.json
a a-a.json; a a-b.json
clang -ftime-trace d/a.c d/b.c -o e/x  # previously /tmp/[ab]-*.json
a e/x-a.json; a e/x-b.json
clang -ftime-trace d/a.c d/b.c -o e/x -dumpdir f/
a f/a.json; a f/b.json
clang -ftime-trace=f d/a.c d/b.c -o e/x
a f/a-*.json; a f/b-*.json

clang -c -ftime-trace d/a.c d/b.c
a a.json b.json
clang -c -ftime-trace=f d/a.c d/b.c
a f/a.json f/b.json

clang -c -ftime-trace d/a.c -o e/xa.o
a e/xa.json
clang -c -ftime-trace d/a.c -o e/xa.o -dumpdir f/g
a f/ga.json
```

The driver checks `-ftime-trace` and `-ftime-trace=`, infers the trace file
name, and passes `-ftime-trace=` to cc1. The `-ftime-trace` cc1 option is
removed.

With offloading, previously `-ftime-trace` is passed to all offloading
actions, causing the same trace file to be overwritten by host and
offloading actions. This patch doesn't attempt to support offloading (D133662),
but makes a sensible change (`OffloadingPrefix.empty()`) to ensure we don't
overwrite the trace file.

Minor behavior differences: the trace file is now a result file, which
will be removed upon an error. -ftime-trace-granularity=0, like
-ftime-trace, can now cause a -Wunused-command-line-argument warning.

Reviewed By: Maetveis

Differential Revision: https://reviews.llvm.org/D150282

Added: 


Modified: 
clang/include/clang/Driver/Compilation.h
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/FrontendOptions.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/ftime-trace.cpp
clang/tools/driver/cc1_main.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Compilation.h 
b/clang/include/clang/Driver/Compilation.h
index f58b5a8cc9fdb..36ae85c424514 100644
--- a/clang/include/clang/Driver/Compilation.h
+++ b/clang/include/clang/Driver/Compilation.h
@@ -112,6 +112,9 @@ class Compilation {
   /// only be removed if we crash.
   ArgStringMap FailureResultFiles;
 
+  /// -ftime-trace result files.
+  ArgStringMap TimeTraceFiles;
+
   /// Optional redirection for stdin, stdout, stderr.
   std::vector> Redirects;
 
@@ -269,6 +272,14 @@ class Compilation {
 return Name;
   }
 
+  const char *getTimeTraceFile(const JobAction *JA) const {
+return TimeTraceFiles.lookup(JA);
+  }
+  void addTimeTraceFile(const char *Name, const JobAction *JA) {
+assert(!TimeTraceFiles.contains(JA));
+TimeTraceFiles[JA] = Name;
+  }
+
   /// CleanupFile - Delete a given file.
   ///
   /// \param IssueErrors - Report failures as errors.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 670003a3da847..ac2c3c2fa718b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3004,8 +3004,7 @@ def ftime_trace : Flag<["-"], "ftime-trace">, 
Group,
 Turn on time profiler. Generates JSON file based on output filename. Results
 can be analyzed with chrome://tracing or `Speedscope App
 `_ for flamegraph visualization.}]>,
-  Flags<[CC1Option, CoreOption]>,
-  MarshallingInfoFlag>;
+  Flags<[CoreOption]>;
 def ftime_trace_granularity_EQ : Joined<["-"], "ftime-trace-granularity=">, 
Group,
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
   Flags<[CC1Option, CoreOption]>,

diff  --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 85183a3812b42..40aa144a0e369 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -283,9 +283,6 @@ class FrontendOptions {
   /// print the supported cpus for the current target
   unsigned PrintSupportedCPUs : 1;
 
-  /// Output time trace profile.
-  unsigned TimeTrace : 1;
-
   /

[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-12 Thread Fangrui Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG49b87b05726b: [Driver] -ftime-trace: derive trace file names 
from -o and -dumpdir (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150282/new/

https://reviews.llvm.org/D150282

Files:
  clang/include/clang/Driver/Compilation.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ftime-trace.cpp
  clang/tools/driver/cc1_main.cpp

Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -213,9 +213,7 @@
   bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
 Argv, Diags, Argv0);
 
-  if (Clang->getFrontendOpts().TimeTrace ||
-  !Clang->getFrontendOpts().TimeTracePath.empty()) {
-Clang->getFrontendOpts().TimeTrace = 1;
+  if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
 llvm::timeTraceProfilerInitialize(
 Clang->getFrontendOpts().TimeTraceGranularity, Argv0);
   }
@@ -257,16 +255,6 @@
   llvm::TimerGroup::clearAll();
 
   if (llvm::timeTraceProfilerEnabled()) {
-SmallString<128> Path(Clang->getFrontendOpts().OutputFile);
-llvm::sys::path::replace_extension(Path, "json");
-if (!Clang->getFrontendOpts().TimeTracePath.empty()) {
-  // replace the suffix to '.json' directly
-  SmallString<128> TracePath(Clang->getFrontendOpts().TimeTracePath);
-  if (llvm::sys::fs::is_directory(TracePath))
-llvm::sys::path::append(TracePath, llvm::sys::path::filename(Path));
-  Path.assign(TracePath);
-}
-
 // It is possible that the compiler instance doesn't own a file manager here
 // if we're compiling a module unit. Since the file manager are owned by AST
 // when we're compiling a module unit. So the file manager may be invalid
@@ -280,7 +268,8 @@
   Clang->getInvocation(), Clang->getDiagnostics()));
 
 if (auto profilerOutput = Clang->createOutputFile(
-Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false,
+Clang->getFrontendOpts().TimeTracePath, /*Binary=*/false,
+/*RemoveFileOnSignal=*/false,
 /*useTemporary=*/false)) {
   llvm::timeTraceProfilerWrite(*profilerOutput);
   profilerOutput.reset();
Index: clang/test/Driver/ftime-trace.cpp
===
--- clang/test/Driver/ftime-trace.cpp
+++ clang/test/Driver/ftime-trace.cpp
@@ -31,6 +31,35 @@
 // CHECK:  "name": "process_name"
 // CHECK:  "name": "thread_name"
 
+// RUN: mkdir d e f && cp %s d/a.cpp && touch d/b.c
+
+// RUN: %clang -### -c -ftime-trace -ftime-trace-granularity=0 d/a.cpp -o e/a.o 2>&1 | FileCheck %s --check-prefix=COMPILE1
+// COMPILE1: -cc1{{.*}} "-ftime-trace=e/a.json" "-ftime-trace-granularity=0"
+
+// RUN: %clang -### -c -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=COMPILE2
+// COMPILE2: -cc1{{.*}} "-ftime-trace=f/a.json" "-ftime-trace-granularity=0"
+// COMPILE2: -cc1{{.*}} "-ftime-trace=f/b.json" "-ftime-trace-granularity=0"
+
+/// -o specifies the link output. Create ${output}-${basename}.json.
+// RUN: %clang -### -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -o e/x 2>&1 | FileCheck %s --check-prefix=LINK1
+// LINK1: -cc1{{.*}} "-ftime-trace=e/x-a.json" "-ftime-trace-granularity=0"
+// LINK1: -cc1{{.*}} "-ftime-trace=e/x-b.json" "-ftime-trace-granularity=0"
+
+/// -dumpdir is f/g, not ending with a path separator. We create f/g${basename}.json.
+// RUN: %clang -### -ftime-trace -ftime-trace-granularity=0 d/a.cpp d/b.c -o e/x -dumpdir f/g 2>&1 | FileCheck %s --check-prefix=LINK2
+// LINK2: -cc1{{.*}} "-ftime-trace=f/ga.json" "-ftime-trace-granularity=0"
+// LINK2: -cc1{{.*}} "-ftime-trace=f/gb.json" "-ftime-trace-granularity=0"
+
+// RUN: %clang -### -ftime-trace=e -ftime-trace-granularity=0 d/a.cpp d/b.c -o f/x -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=LINK3
+// LINK3: -cc1{{.*}} "-ftime-trace=e/a-{{[^.]*}}.json" "-ftime-trace-granularity=0"
+// LINK3: -cc1{{.*}} "-ftime-trace=e/b-{{[^.]*}}.json" "-ftime-trace-granularity=0"
+
+// RUN: %clang -### -ftime-trace -ftime-trace=e -ftime-trace-granularity=1 -xassembler d/a.cpp 2>&1 | \
+// RUN:   FileCheck %s --check-prefix=UNUSED --implicit-check-not=warning:
+// UNUSED: warning: argument unused during compilation: '-ftime-trace'
+// UNUSED: warning: argument unused during compilation: '-ftime-trace=e'
+// UNUSED: warning: argument unused during compilation: '-ftime-trace-granularity=1'
+
 template 
 struct Struct {
   T Num;
Index: clang/lib/Driver/ToolChains/Clang.cpp
=

[PATCH] D150403: [clang-format] Adjust braced list detection (try 2)

2023-05-12 Thread Galen Elias via Phabricator via cfe-commits
galenelias added a subscriber: sstwcw.
galenelias added a comment.

Looks like @sstwcw also submitted a fix for the same issue, with a bit of a 
different approach: https://reviews.llvm.org/D150452


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150403/new/

https://reviews.llvm.org/D150403

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150452: [clang-format] Recognize nested blocks

2023-05-12 Thread Galen Elias via Phabricator via cfe-commits
galenelias added a comment.

Coincidentally I also sent out a review to fix this issue yesterday, but went 
with a different approach of trying to scope the ProbablyBracedList logic by 
just looking at the lbrace previous token.

https://reviews.llvm.org/D150403


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150452/new/

https://reviews.llvm.org/D150452

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150461: [OpenMP] Naturally align internal global variables in the OpenMPIRBuilder

2023-05-12 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet accepted this revision.
gchatelet added a comment.

You beat me to it :)
Thx for the fix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150461/new/

https://reviews.llvm.org/D150461

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150461: [OpenMP] Naturally align internal global variables in the OpenMPIRBuilder

2023-05-12 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added a comment.

quick question, did you try to build the openmp runtime as well to check if the 
tests still pass?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150461/new/

https://reviews.llvm.org/D150461

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150461: [OpenMP] Naturally align internal global variables in the OpenMPIRBuilder

2023-05-12 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D150461#4338498 , @gchatelet wrote:

> quick question, did you try to build the openmp runtime as well to check if 
> the tests still pass?

I'm an OpenMP developer so I always have it built : ). Yes they still pass.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150461/new/

https://reviews.llvm.org/D150461

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150221: Add option -fkeep-static-variables to emit all static variables

2023-05-12 Thread Zheng Qian via Phabricator via cfe-commits
qianzhen added a comment.

This is useful in keeping the static variables in a patchable function 
(https://clang.llvm.org/docs/AttributeReference.html#patchable-function-entry), 
so that they can be directly addressed by a hot patch when the optimization to 
merge them is enabled 
(https://llvm.org/docs/doxygen/GlobalMerge_8cpp_source.html).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150221/new/

https://reviews.llvm.org/D150221

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150461: [OpenMP] Naturally align internal global variables in the OpenMPIRBuilder

2023-05-12 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet added a comment.

In D150461#4338499 , @jhuber6 wrote:

> In D150461#4338498 , @gchatelet 
> wrote:
>
>> quick question, did you try to build the openmp runtime as well to check if 
>> the tests still pass?
>
> I'm an OpenMP developer so I always have it built : ). Yes they still pass.

👍


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150461/new/

https://reviews.llvm.org/D150461

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150461: [OpenMP] Naturally align internal global variables in the OpenMPIRBuilder

2023-05-12 Thread Joseph Huber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdd02984519ab: [OpenMP] Naturally align internal global 
variables in the OpenMPIRBuilder (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150461/new/

https://reviews.llvm.org/D150461

Files:
  clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/for_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_master_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_reduction_task_codegen.cpp
  clang/test/OpenMP/parallel_sections_reduction_task_codegen.cpp
  clang/test/OpenMP/reduction_implicit_map.cpp
  clang/test/OpenMP/sections_reduction_task_codegen.cpp
  clang/test/OpenMP/target_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/target_parallel_reduction_task_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/taskloop_reduction_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4225,10 +4225,12 @@
 // variable for possibly changing that to internal or private, or maybe
 // create different versions of the function for different OMP internal
 // variables.
-Elem.second = new GlobalVariable(
+auto *GV = new GlobalVariable(
 M, Ty, /*IsConstant=*/false, GlobalValue::CommonLinkage,
 Constant::getNullValue(Ty), Elem.first(),
 /*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
+GV->setAlignment(M.getDataLayout().getABITypeAlign(Ty));
+Elem.second = GV;
   }
 
   return cast(&*Elem.second);
Index: clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
===
--- clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
+++ clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
@@ -348,7 +348,7 @@
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
 // CHECK1-NEXT:[[TMP2:%.*]] = load ptr, ptr [[DOTADDR]], align 8
-// CHECK1-NEXT:[[TMP3:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP3:%.*]] = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP4:%.*]] = load i64, ptr [[TMP3]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP4]]
 // CHECK1-NEXT:[[OMP_ARRAYINIT_ISEMPTY:%.*]] = icmp eq ptr [[TMP2]], [[TMP5]]
@@ -370,7 +370,7 @@
 // CHECK1-NEXT:[[DOTADDR1:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
-// CHECK1-NEXT:[[TMP2:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP2:%.*]] = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP3:%.*]] = load i64, ptr [[TMP2]], align 8
 // CHECK1-NEXT:[[TMP4:%.*]] = load ptr, ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = load ptr, ptr [[DOTADDR1]], align 8
@@ -712,7 +712,7 @@
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
 // CHECK1-NEXT:[[TMP2:%.*]] = load ptr, ptr [[DOTADDR]], align 8
-// CHECK1-NEXT:[[TMP3:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP3:%.*]] = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP4:%.*]] = load i64, ptr [[TMP3]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP4]]
 // CHECK1-NEXT:[[OMP_ARRAYINIT_ISEMPTY:%.*]] = icmp eq ptr [[TMP2]], [[TMP5]]
@@ -734,7 +734,7 @@
 // CHECK1-NEXT:[[DOTADDR1:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
-// CHECK1-NEXT:[[TMP2:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP2:%.*]] = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP3:%.*]] = load i64, ptr [[TMP2]], align 8
 // CHECK1-NEXT:[[TMP4:%.*]] = load ptr, ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = load ptr, p

[clang] dd02984 - [OpenMP] Naturally align internal global variables in the OpenMPIRBuilder

2023-05-12 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-05-12T13:14:27-05:00
New Revision: dd02984519abafe7637cdafcf4ede8b303f385ab

URL: 
https://github.com/llvm/llvm-project/commit/dd02984519abafe7637cdafcf4ede8b303f385ab
DIFF: 
https://github.com/llvm/llvm-project/commit/dd02984519abafe7637cdafcf4ede8b303f385ab.diff

LOG: [OpenMP] Naturally align internal global variables in the OpenMPIRBuilder

We use this helper to make several internal global variables during
codegen. currently we do not specify any alignment which allows the
alignment to be set incorrectly after some changes in how alignment was
handled. This patch explicitly aligns these variables to the natural
alignment as specified by the data layout

Fixes https://github.com/llvm/llvm-project/issues/62668

Reviewed By: tianshilei1992, gchatelet

Differential Revision: https://reviews.llvm.org/D150461

Added: 


Modified: 
clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
clang/test/OpenMP/for_reduction_task_codegen.cpp
clang/test/OpenMP/parallel_for_reduction_task_codegen.cpp
clang/test/OpenMP/parallel_master_reduction_task_codegen.cpp
clang/test/OpenMP/parallel_reduction_task_codegen.cpp
clang/test/OpenMP/parallel_sections_reduction_task_codegen.cpp
clang/test/OpenMP/reduction_implicit_map.cpp
clang/test/OpenMP/sections_reduction_task_codegen.cpp
clang/test/OpenMP/target_parallel_for_reduction_task_codegen.cpp
clang/test/OpenMP/target_parallel_reduction_task_codegen.cpp

clang/test/OpenMP/target_teams_distribute_parallel_for_reduction_task_codegen.cpp
clang/test/OpenMP/taskloop_reduction_codegen.cpp
clang/test/OpenMP/teams_distribute_parallel_for_reduction_task_codegen.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Removed: 




diff  --git 
a/clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp 
b/clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
index de9b18bbb5fba..ce7171c35020e 100644
--- a/clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
+++ b/clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
@@ -448,7 +448,7 @@ int main(int argc, char **argv) {
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
 // CHECK1-NEXT:[[TMP2:%.*]] = load ptr, ptr [[DOTADDR]], align 8
-// CHECK1-NEXT:[[TMP3:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr 
@{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP3:%.*]] = call align 8 ptr 
@llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP4:%.*]] = load i64, ptr [[TMP3]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP4]]
 // CHECK1-NEXT:[[OMP_ARRAYINIT_ISEMPTY:%.*]] = icmp eq ptr [[TMP2]], 
[[TMP5]]
@@ -470,7 +470,7 @@ int main(int argc, char **argv) {
 // CHECK1-NEXT:[[DOTADDR1:%.*]] = alloca ptr, align 8
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
-// CHECK1-NEXT:[[TMP2:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr 
@{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP2:%.*]] = call align 8 ptr 
@llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP3:%.*]] = load i64, ptr [[TMP2]], align 8
 // CHECK1-NEXT:[[TMP4:%.*]] = load ptr, ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = load ptr, ptr [[DOTADDR1]], align 8

diff  --git a/clang/test/OpenMP/for_reduction_task_codegen.cpp 
b/clang/test/OpenMP/for_reduction_task_codegen.cpp
index 48587ce9a34b6..6a024fb7d3785 100644
--- a/clang/test/OpenMP/for_reduction_task_codegen.cpp
+++ b/clang/test/OpenMP/for_reduction_task_codegen.cpp
@@ -19,22 +19,6 @@ int main(int argc, char **argv) {
   }
 }
 
-
-
-// Init firstprivate copy of argc
-
-// Init firstprivate copy of argv[0:10][0:argc]
-
-// Register task reduction.
-
-
-
-
-
-
-
-
-
 #endif
 // CHECK1-LABEL: define {{[^@]+}}@main
 // CHECK1-SAME: (i32 noundef [[ARGC:%.*]], ptr noundef [[ARGV:%.*]]) 
#[[ATTR0:[0-9]+]] {
@@ -361,7 +345,7 @@ int main(int argc, char **argv) {
 // CHECK1-NEXT:store ptr [[TMP0]], ptr [[DOTADDR]], align 8
 // CHECK1-NEXT:store ptr [[TMP1]], ptr [[DOTADDR1]], align 8
 // CHECK1-NEXT:[[TMP2:%.*]] = load ptr, ptr [[DOTADDR]], align 8
-// CHECK1-NEXT:[[TMP3:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr 
@{{reduction_size[.].+[.]}})
+// CHECK1-NEXT:[[TMP3:%.*]] = call align 8 ptr 
@llvm.threadlocal.address.p0(ptr align 8 @{{reduction_size[.].+[.]}})
 // CHECK1-NEXT:[[TMP4:%.*]] = load i64, ptr [[TMP3]], align 8
 // CHECK1-NEXT:[[TMP5:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP4]]
 // CHECK1-NEXT:[[OMP_ARRAYINIT_ISEMPTY:%.*]] = icmp eq ptr [[TMP2]], 
[[TMP5]]
@@ -383,7 +367,7 @@ int main(int argc, char **argv) {
 // CHECK1-NE

[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:114
+^
+- Compiler flags -std=c++2c and -std=gnu++2c have been added for experimental 
C++26 implementation work.
+

cor3ntin wrote:
> This should be 2c
double backsticks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148654: Modify BoundsSan to improve debuggability

2023-05-12 Thread Oskar Wirga via Phabricator via cfe-commits
oskarwirga added a comment.

CC: @nlopes @chandlerc @jgalenson

I have y'all added here because of your past work on BoundsSan, if you know of 
anyone else who may be able to provide review please tag them!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148654/new/

https://reviews.llvm.org/D148654

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148094: [clang][CodeGen] Break up TargetInfo.cpp [8/8]

2023-05-12 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

ping :)
Any comments / questions / suggestions are welcome


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148094/new/

https://reviews.llvm.org/D148094

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146389: [clang-repl][CUDA] Initial interactive CUDA support for clang-repl

2023-05-12 Thread Anubhab Ghosh via Phabricator via cfe-commits
argentite updated this revision to Diff 521742.
argentite marked an inline comment as done.
argentite added a comment.

Add some CUDA basic functionality tests.
Disallow undo-ing of the initial PTU. This should fix the undo command test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146389/new/

https://reviews.llvm.org/D146389

Files:
  clang/include/clang/CodeGen/ModuleBuilder.h
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/DeviceOffload.cpp
  clang/lib/Interpreter/DeviceOffload.h
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/test/Interpreter/CUDA/device-function-template.cu
  clang/test/Interpreter/CUDA/device-function.cu
  clang/test/Interpreter/CUDA/host-and-device.cu
  clang/test/Interpreter/CUDA/lit.local.cfg
  clang/test/Interpreter/CUDA/memory.cu
  clang/test/Interpreter/CUDA/sanity.cu
  clang/test/lit.cfg.py
  clang/tools/clang-repl/ClangRepl.cpp
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
  clang/unittests/Interpreter/IncrementalProcessingTest.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -40,7 +40,9 @@
   DiagnosticConsumer *Client = nullptr) {
   Args ClangArgs = {"-Xclang", "-emit-llvm-only"};
   ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
-  auto CI = cantFail(clang::IncrementalCompilerBuilder::create(ClangArgs));
+  auto CB = clang::IncrementalCompilerBuilder();
+  CB.SetCompilerArgs(ClangArgs);
+  auto CI = cantFail(CB.CreateCpp());
   if (Client)
 CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
   return cantFail(clang::Interpreter::create(std::move(CI)));
Index: clang/unittests/Interpreter/IncrementalProcessingTest.cpp
===
--- clang/unittests/Interpreter/IncrementalProcessingTest.cpp
+++ clang/unittests/Interpreter/IncrementalProcessingTest.cpp
@@ -52,7 +52,9 @@
 
 TEST(IncrementalProcessing, EmitCXXGlobalInitFunc) {
   std::vector ClangArgv = {"-Xclang", "-emit-llvm-only"};
-  auto CI = llvm::cantFail(IncrementalCompilerBuilder::create(ClangArgv));
+  auto CB = clang::IncrementalCompilerBuilder();
+  CB.SetCompilerArgs(ClangArgv);
+  auto CI = cantFail(CB.CreateCpp());
   auto Interp = llvm::cantFail(Interpreter::create(std::move(CI)));
 
   std::array PTUs;
Index: clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
===
--- clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -38,7 +38,9 @@
   DiagnosticConsumer *Client = nullptr) {
   Args ClangArgs = {"-Xclang", "-emit-llvm-only"};
   ClangArgs.insert(ClangArgs.end(), ExtraArgs.begin(), ExtraArgs.end());
-  auto CI = cantFail(clang::IncrementalCompilerBuilder::create(ClangArgs));
+  auto CB = clang::IncrementalCompilerBuilder();
+  CB.SetCompilerArgs(ClangArgs);
+  auto CI = cantFail(CB.CreateCpp());
   if (Client)
 CI->getDiagnostics().setClient(Client, /*ShouldOwnClient=*/false);
   return cantFail(clang::Interpreter::create(std::move(CI)));
Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -23,6 +23,10 @@
 #include "llvm/Support/TargetSelect.h" // llvm::Initialize*
 #include 
 
+static llvm::cl::opt CudaEnabled("cuda", llvm::cl::Hidden);
+static llvm::cl::opt CudaPath("cuda-path", llvm::cl::Hidden);
+static llvm::cl::opt OffloadArch("offload-arch", llvm::cl::Hidden);
+
 static llvm::cl::list
 ClangArgs("Xcc",
   llvm::cl::desc("Argument to pass to the CompilerInvocation"),
@@ -90,9 +94,36 @@
 return 0;
   }
 
+  clang::IncrementalCompilerBuilder CB;
+  CB.SetCompilerArgs(ClangArgv);
+
+  std::unique_ptr DeviceCI;
+  if (CudaEnabled) {
+// initialize NVPTX backend
+LLVMInitializeNVPTXTargetInfo();
+LLVMInitializeNVPTXTarget();
+LLVMInitializeNVPTXTargetMC();
+LLVMInitializeNVPTXAsmPrinter();
+
+if (!CudaPath.empty())
+  CB.SetCudaSDK(CudaPath);
+
+if (OffloadArch.empty()) {
+  OffloadArch = "sm_35";
+}
+CB.SetOffloadArch(OffloadArch);
+
+DeviceCI = ExitOnErr(CB.CreateCudaDevice());
+  }
+
   // FIXME: Investigate if we could use runToolOnCodeWithArgs from tooling. It
   // can replace t

[PATCH] D150450: Add C++26 compile flags.

2023-05-12 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 521743.
erichkeane marked an inline comment as done.
erichkeane added a comment.

Added double-backticks, updated the tests for the new __cplusplus entries I 
changed during review.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150450/new/

https://reviews.llvm.org/D150450

Files:
  clang/docs/CommandGuide/clang.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangStandard.h
  clang/include/clang/Basic/LangStandards.def
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Driver/cl-options.c
  clang/test/Driver/unknown-std.cpp
  clang/test/Preprocessor/init.c
  clang/www/OpenProjects.html
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -65,6 +65,11 @@
  -std=c++23
  Partial
 
+
+ C++2c
+ -std=c++2c
+ Partial
+
 
 
 The Clang community is continually striving to improve C++ standards
@@ -1560,6 +1565,25 @@
 
 
 
+C++2c implementation status
+
+
+Clang has support for some of the features of the C++ standard following
+C++23, informally referred to as C++26.
+
+You can use Clang in C++2c mode with the -std=c++2c option.
+
+
+List of features and minimum Clang version with support
+
+ 
+Language Feature
+C++26 Proposal
+Available in Clang?
+ 
+ 
+ 
+
 Defect reports
 
 Clang generally aims to implement resolutions to Defect Reports (bug fixes
Index: clang/www/OpenProjects.html
===
--- clang/www/OpenProjects.html
+++ clang/www/OpenProjects.html
@@ -123,7 +123,7 @@
 
 
 
-Continue work on C++20, C++23, and C2x support:
+Continue work on C++20, C++23, C++2c, and C2x support:
   There are still several C++20 features to complete, and work has begun on
   supporting the latest language standards. Please see the
   C++ status report page to find out what is
Index: clang/test/Preprocessor/init.c
===
--- clang/test/Preprocessor/init.c
+++ clang/test/Preprocessor/init.c
@@ -8,6 +8,15 @@
 // BLOCKS:#define __BLOCKS__ 1
 // BLOCKS:#define __block __attribute__((__blocks__(byref)))
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX26 %s
+//
+// CXX26:#define __GNUG__ 4
+// CXX26:#define __GXX_EXPERIMENTAL_CXX0X__ 1
+// CXX26:#define __GXX_RTTI 1
+// CXX26:#define __GXX_WEAK__ 1
+// CXX26:#define __cplusplus 202402L
+// CXX26:#define __private_extern__ extern
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2B %s
@@ -16,7 +25,7 @@
 // CXX2B:#define __GXX_EXPERIMENTAL_CXX0X__ 1
 // CXX2B:#define __GXX_RTTI 1
 // CXX2B:#define __GXX_WEAK__ 1
-// CXX2B:#define __cplusplus 202101L
+// CXX2B:#define __cplusplus 202302L
 // CXX2B:#define __private_extern__ extern
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=c++20 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix CXX2A %s
@@ -134,12 +143,20 @@
 // RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++26 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+// RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2c -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX26 %s
+//
+// GXX26:#define __GNUG__ 4
+// GXX26:#define __GXX_WEAK__ 1
+// GXX26:#define __cplusplus 202402L
+// GXX26:#define __private_extern__ extern
+//
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++23 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++2b -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2B %s
 //
 // GXX2B:#define __GNUG__ 4
 // GXX2B:#define __GXX_WEAK__ 1
-// GXX2B:#define __cplusplus 202101L
+// GXX2B:#define __cplusplus 202302L
 // GXX2B:#define __private_extern__ extern
 //
 // RUN: %clang_cc1 -x c++ -fgnuc-version=4.2.1 -std=gnu++20 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix GXX2A %s
Index: clang/test/Driver/unknown-std.cpp
===
--- clang/test/Driver/unknown-std.cpp
+++ clang/test/Driver/unknown-std.cpp
@@ -19,6 +19,8 @@
 // CHECK-NEXT: n

[PATCH] D150291: [Clang] Rename internal type identifier(s) for __bf16 to BF16Ty

2023-05-12 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs added a comment.

In D150291#4338118 , @tahonermann 
wrote:

>> I do wonder if we need two bfloat implementations, but for that I'll leave a 
>> comment on D149573 .
>
> Given the discussions occurring in D149573 
> , let's hold off on landing this for now. 
> It is sounding like we might have direction for repurposing `__bf16` for 
> `std::bfloat16_t` (and a future `_BFloat16` C type; with `__bf16` retained as 
> an alternate spelling). If we go in that direction, then we would presumably 
> want a change that goes in the opposite direction of this patch; a change 
> that migrates "bf16" names towards "bfloat16". Let's focus on confirming that 
> direction first. I'll mark this as requesting changes for now while we figure 
> this out.

Thank you for your guidance, @tahonermann. I agree it's prudent to establish a 
confirmed direction for reusing `__bf16` to implement `std::bfloat16_t` as an 
arithmetic type before proceeding. If we decide to take this route, I 
understand that we'll be looking towards a change that aligns "bf16" names more 
closely with "bfloat16".

In the meantime, I will revert to my initial change in D149573 
 which repurposed `__bf16` type, and present 
it for further discussion. This, along with a summary of the RFC discussion, 
should help us reach a consensus. I welcome any further insights or 
considerations you might think pertinent to this process.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150291/new/

https://reviews.llvm.org/D150291

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146342: [-Wunsafe-buffer-usage] Move the whole analysis to the end of a translation unit

2023-05-12 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 marked an inline comment as done.
ziqingluo-90 added inline comments.



Comment at: clang/lib/Sema/AnalysisBasedWarnings.cpp:2364
+ Node->getBeginLoc())) {
+  UnsafeBufferUsageReporter R(S);
+  clang::checkUnsafeBufferUsage(Node, R, UnsafeBufferEmitFixits);

NoQ wrote:
> So WDYT about capturing the reporter from outside lambda instead?
The Reporter is stateless so we definitely can let analyses of functions share 
it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146342/new/

https://reviews.llvm.org/D146342

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150446: [analyzer] Check ArraySubscriptExprs in ArrayBoundCheckerV2

2023-05-12 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I still struggle to see the motivation.
Please consider adding a test demonstraing a case when the diagnostic is not 
relevant or easily misunderstood by the users. Alternatively, give an 
evaluation of this change so that I can see it myself. In the end it would 
still make sense to have something to talk about some specifi case(s).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150446/new/

https://reviews.llvm.org/D150446

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150282: [Driver] -ftime-trace: derive trace file names from -o and -dumpdir

2023-05-12 Thread Douglas Yung via Phabricator via cfe-commits
dyung added inline comments.



Comment at: clang/test/Driver/ftime-trace.cpp:54
+// RUN: %clang -### -ftime-trace=e -ftime-trace-granularity=0 d/a.cpp d/b.c -o 
f/x -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=LINK3
+// LINK3: -cc1{{.*}} "-ftime-trace=e/a-{{[^.]*}}.json" 
"-ftime-trace-granularity=0"
+// LINK3: -cc1{{.*}} "-ftime-trace=e/b-{{[^.]*}}.json" 
"-ftime-trace-granularity=0"

This seems to be failing on Windows due to path separator issues:
https://lab.llvm.org/buildbot/#/builders/216/builds/21115/steps/7/logs/FAIL__Clang__ftime-trace_cpp
```
... "-ftime-trace=e\\a-b9537d.json" ...
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150282/new/

https://reviews.llvm.org/D150282

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146342: [-Wunsafe-buffer-usage] Move the whole analysis to the end of a translation unit

2023-05-12 Thread Ziqing Luo via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
ziqingluo-90 marked an inline comment as done.
Closed by commit rG6d861d498de1: [-Wunsafe-buffer-usage] Move the whole 
analysis to the end of a translation unit (authored by ziqingluo-90).

Changed prior to commit:
  https://reviews.llvm.org/D146342?vs=521409&id=521747#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146342/new/

https://reviews.llvm.org/D146342

Files:
  clang/include/clang/Sema/AnalysisBasedWarnings.h
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/lib/Sema/Sema.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
===
--- clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
@@ -220,11 +220,11 @@
 void testTemplate(int * p) {
   int *a[10];
   foo(f(p, &p, a, a)[1]); // expected-warning{{unsafe buffer access}}
-  // expected-note@-1{{in instantiation of function template specialization 'f' requested here}}
+  // FIXME: expected note@-1{{in instantiation of function template specialization 'f' requested here}}
 
   const int **q = const_cast(&p);
 
-  testPointerArithmetic(p, q, p); //expected-note{{in instantiation of}}
+  testPointerArithmetic(p, q, p); //FIXME: expected note{{in instantiation of}}
 }
 
 void testPointerToMember() {
@@ -315,7 +315,7 @@
   foo(ar[5]);   // expected-note{{used in buffer access here}}
 }
 
-template void fArr(int t[]); // expected-note {{in instantiation of}}
+template void fArr(int t[]); // FIXME: expected note {{in instantiation of}}
 
 int testReturn(int t[]) {
   // expected-warning@-1{{'t' is an unsafe pointer used for buffer access}}
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1426,6 +1426,8 @@
 }
   }
 
+  AnalysisWarnings.IssueWarnings(Context.getTranslationUnitDecl());
+
   // Check we've noticed that we're no longer parsing the initializer for every
   // variable. If we miss cases, then at best we have a performance issue and
   // at worst a rejects-valid bug.
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "clang/Sema/AnalysisBasedWarnings.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/EvaluatedExprVisitor.h"
@@ -25,6 +26,8 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
 #include "clang/Analysis/Analyses/CalledOnceCheck.h"
 #include "clang/Analysis/Analyses/Consumed.h"
@@ -35,6 +38,7 @@
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CFGStmtMap.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Preprocessor.h"
@@ -43,6 +47,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -2290,6 +2295,87 @@
 S.Diag(D.Loc, D.PD);
 }
 
+// An AST Visitor that calls a callback function on each callable DEFINITION
+// that is NOT in a dependent context:
+class CallableVisitor : public RecursiveASTVisitor {
+private:
+  llvm::function_ref Callback;
+
+public:
+  CallableVisitor(llvm::function_ref Callback)
+  : Callback(Callback) {}
+
+  bool VisitFunctionDecl(FunctionDecl *Node) {
+if (cast(Node)->isDependentContext())
+  return true; // Not to analyze dependent decl
+// `FunctionDecl->hasBody()` returns true if the function has a body
+// somewhere defined.  But we want to know if this `Node` has a body
+// child.  So we use `doesThisDeclarationHaveABody`:
+if (Node->doesThisDeclarationHaveABody())
+  Callback(Node);
+return true;
+  }
+
+  bool VisitBlockDecl(BlockDecl *Node) {
+if (cast(Node)->isDependentContext())
+  return true; // Not to analyze dependent decl
+Callback(Node);
+return true;
+  }
+
+  bool VisitObjCMethodDecl(ObjCMethodDecl *Node) {
+if (cast(Node)->isDependentContext())
+  return true; // Not to analyze dependent decl
+if (Node->hasBody())
+  Callback(Node);
+return true;
+  }
+
+  bool Vis

[clang] 6d861d4 - [-Wunsafe-buffer-usage] Move the whole analysis to the end of a translation unit

2023-05-12 Thread via cfe-commits

Author: ziqingluo-90
Date: 2023-05-12T11:50:51-07:00
New Revision: 6d861d498de1320d22771c329ec69f9419ef06b7

URL: 
https://github.com/llvm/llvm-project/commit/6d861d498de1320d22771c329ec69f9419ef06b7
DIFF: 
https://github.com/llvm/llvm-project/commit/6d861d498de1320d22771c329ec69f9419ef06b7.diff

LOG: [-Wunsafe-buffer-usage] Move the whole analysis to the end of a 
translation unit

The unsafe-buffer analysis requires a complete view of the translation
unit (TU) to be conservative. So the analysis is moved to the end of a
TU.

A summary of changes made: add a new `IssueWarnings` function in
`AnalysisBasedWarnings.cpp` for TU-based analyses. So far
[-Wunsafe-buffer-usage] is the only analysis using it but there could
be more.  `Sema` will call the new `IssueWarnings` function at the end
of parsing a TU.

Reviewed by: NoQ (Artem Dergachev)

Differential revision: https://reviews.llvm.org/D146342

Added: 


Modified: 
clang/include/clang/Sema/AnalysisBasedWarnings.h
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/lib/Sema/Sema.cpp
clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/AnalysisBasedWarnings.h 
b/clang/include/clang/Sema/AnalysisBasedWarnings.h
index 13a88bb9f8968..c73506894db9d 100644
--- a/clang/include/clang/Sema/AnalysisBasedWarnings.h
+++ b/clang/include/clang/Sema/AnalysisBasedWarnings.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_SEMA_ANALYSISBASEDWARNINGS_H
 #define LLVM_CLANG_SEMA_ANALYSISBASEDWARNINGS_H
 
+#include "clang/AST/Decl.h"
 #include "llvm/ADT/DenseMap.h"
 #include 
 
@@ -95,6 +96,9 @@ class AnalysisBasedWarnings {
   void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
  const Decl *D, QualType BlockType);
 
+  // Issue warnings that require whole-translation-unit analysis.
+  void IssueWarnings(const TranslationUnitDecl *D);
+
   Policy getDefaultPolicy() { return DefaultPolicy; }
 
   void PrintStats() const;

diff  --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index f5c48ed89e93d..4d96f3b9ab32b 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -13,6 +13,7 @@
 
//===--===//
 
 #include "clang/Sema/AnalysisBasedWarnings.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/EvaluatedExprVisitor.h"
@@ -25,6 +26,8 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
 #include "clang/Analysis/Analyses/CalledOnceCheck.h"
 #include "clang/Analysis/Analyses/Consumed.h"
@@ -35,6 +38,7 @@
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CFGStmtMap.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Preprocessor.h"
@@ -43,6 +47,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -2290,6 +2295,87 @@ static void flushDiagnostics(Sema &S, const 
sema::FunctionScopeInfo *fscope) {
 S.Diag(D.Loc, D.PD);
 }
 
+// An AST Visitor that calls a callback function on each callable DEFINITION
+// that is NOT in a dependent context:
+class CallableVisitor : public RecursiveASTVisitor {
+private:
+  llvm::function_ref Callback;
+
+public:
+  CallableVisitor(llvm::function_ref Callback)
+  : Callback(Callback) {}
+
+  bool VisitFunctionDecl(FunctionDecl *Node) {
+if (cast(Node)->isDependentContext())
+  return true; // Not to analyze dependent decl
+// `FunctionDecl->hasBody()` returns true if the function has a body
+// somewhere defined.  But we want to know if this `Node` has a body
+// child.  So we use `doesThisDeclarationHaveABody`:
+if (Node->doesThisDeclarationHaveABody())
+  Callback(Node);
+return true;
+  }
+
+  bool VisitBlockDecl(BlockDecl *Node) {
+if (cast(Node)->isDependentContext())
+  return true; // Not to analyze dependent decl
+Callback(Node);
+return true;
+  }
+
+  bool VisitObjCMethodDecl(ObjCMethodDecl *Node) {
+if (cast(Node)->isDependentContext())
+  return true; // Not to analyze dependent decl
+if (Node->hasBody())
+  Callback(Node);
+return true;
+  }
+
+  bool VisitLambdaExpr(LambdaExpr *Node) {
+return VisitFunctionDecl(Node->getCallOperator());
+  }
+
+  bool shouldVisitTemplateInstantiations() const { return true; }
+  bool shouldVisitImplicitCode() const { return fals

[PATCH] D150226: [Clang] Remove ability to downgrade warning on the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values

2023-05-12 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

> I was under the impression from https://github.com/boostorg/mpl/issues/69 
> that this was fixed but there are a number of issues off of the main one and 
> maybe I am confused.

Seems like boost 1.81 has the mentioned fix. I can try it and see if the 
warning still fires.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150226/new/

https://reviews.llvm.org/D150226

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d66417f - [test] Fix ftime-trace.cpp on Windows

2023-05-12 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-05-12T12:23:30-07:00
New Revision: d66417f0ae9d6b5e1be9b80c0c3630601169818d

URL: 
https://github.com/llvm/llvm-project/commit/d66417f0ae9d6b5e1be9b80c0c3630601169818d
DIFF: 
https://github.com/llvm/llvm-project/commit/d66417f0ae9d6b5e1be9b80c0c3630601169818d.diff

LOG: [test] Fix ftime-trace.cpp on Windows

Added: 


Modified: 
clang/test/Driver/ftime-trace.cpp

Removed: 




diff  --git a/clang/test/Driver/ftime-trace.cpp 
b/clang/test/Driver/ftime-trace.cpp
index 24848d9fa1ed..fc7f5d680575 100644
--- a/clang/test/Driver/ftime-trace.cpp
+++ b/clang/test/Driver/ftime-trace.cpp
@@ -51,8 +51,8 @@
 // LINK2: -cc1{{.*}} "-ftime-trace=f/gb.json" "-ftime-trace-granularity=0"
 
 // RUN: %clang -### -ftime-trace=e -ftime-trace-granularity=0 d/a.cpp d/b.c -o 
f/x -dumpdir f/ 2>&1 | FileCheck %s --check-prefix=LINK3
-// LINK3: -cc1{{.*}} "-ftime-trace=e/a-{{[^.]*}}.json" 
"-ftime-trace-granularity=0"
-// LINK3: -cc1{{.*}} "-ftime-trace=e/b-{{[^.]*}}.json" 
"-ftime-trace-granularity=0"
+// LINK3: -cc1{{.*}} "-ftime-trace=e{{/|}}a-{{[^.]*}}.json" 
"-ftime-trace-granularity=0"
+// LINK3: -cc1{{.*}} "-ftime-trace=e{{/|}}b-{{[^.]*}}.json" 
"-ftime-trace-granularity=0"
 
 // RUN: %clang -### -ftime-trace -ftime-trace=e -ftime-trace-granularity=1 
-xassembler d/a.cpp 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=UNUSED --implicit-check-not=warning:



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150473: [clang/Driver] Also consider `gnu++` standard when checking for modules support

2023-05-12 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150473

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.cpp


Index: clang/test/Driver/modules.cpp
===
--- clang/test/Driver/modules.cpp
+++ clang/test/Driver/modules.cpp
@@ -4,6 +4,7 @@
 // Check compiling a module interface to a .pcm file.
 //
 // RUN: %clang -std=c++2a -x c++-module --precompile %s -o %t/module.pcm -v 
2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
+// RUN: %clang -std=gnu++2a -x c++-module --precompile %s -o %t/module-gnu.pcm 
-v 2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
 //
 // CHECK-PRECOMPILE: -cc1 {{.*}} -emit-module-interface
 // CHECK-PRECOMPILE-SAME: -o {{.*}}.pcm
@@ -23,6 +24,7 @@
 //
 // RUN: %clang -std=c++2a -fmodule-file=%t/module.pcm -Dexport= %s -S -o 
%t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 // RUN: %clang -std=c++20 -fmodule-file=%t/module.pcm -Dexport= %s -S -o 
%t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
+// RUN: %clang -std=gnu++20 -fmodule-file=%t/module-gnu.pcm -Dexport= %s -S -o 
%t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 //
 // CHECK-USE: -cc1 {{.*}} {{-emit-obj|-S}}
 // CHECK-USE-SAME: -fmodule-file={{.*}}.pcm
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3672,9 +3672,11 @@
   // modules support by default.
   bool HaveStdCXXModules =
   IsCXX && Std &&
-  (Std->containsValue("c++2a") || Std->containsValue("c++20") ||
-   Std->containsValue("c++2b") || Std->containsValue("c++23") ||
-   Std->containsValue("c++latest"));
+  (Std->containsValue("c++2a") || Std->containsValue("gnu++2a") ||
+   Std->containsValue("c++20") || Std->containsValue("gnu++20") ||
+   Std->containsValue("c++2b") || Std->containsValue("gnu++2b") ||
+   Std->containsValue("c++23") || Std->containsValue("gnu++23") ||
+   Std->containsValue("c++latest") || Std->containsValue("gnu++latest"));
   bool HaveModules = HaveStdCXXModules;
 
   // -fmodules enables the use of precompiled modules (off by default).


Index: clang/test/Driver/modules.cpp
===
--- clang/test/Driver/modules.cpp
+++ clang/test/Driver/modules.cpp
@@ -4,6 +4,7 @@
 // Check compiling a module interface to a .pcm file.
 //
 // RUN: %clang -std=c++2a -x c++-module --precompile %s -o %t/module.pcm -v 2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
+// RUN: %clang -std=gnu++2a -x c++-module --precompile %s -o %t/module-gnu.pcm -v 2>&1 | FileCheck %s --check-prefix=CHECK-PRECOMPILE
 //
 // CHECK-PRECOMPILE: -cc1 {{.*}} -emit-module-interface
 // CHECK-PRECOMPILE-SAME: -o {{.*}}.pcm
@@ -23,6 +24,7 @@
 //
 // RUN: %clang -std=c++2a -fmodule-file=%t/module.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 // RUN: %clang -std=c++20 -fmodule-file=%t/module.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
+// RUN: %clang -std=gnu++20 -fmodule-file=%t/module-gnu.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
 //
 // CHECK-USE: -cc1 {{.*}} {{-emit-obj|-S}}
 // CHECK-USE-SAME: -fmodule-file={{.*}}.pcm
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3672,9 +3672,11 @@
   // modules support by default.
   bool HaveStdCXXModules =
   IsCXX && Std &&
-  (Std->containsValue("c++2a") || Std->containsValue("c++20") ||
-   Std->containsValue("c++2b") || Std->containsValue("c++23") ||
-   Std->containsValue("c++latest"));
+  (Std->containsValue("c++2a") || Std->containsValue("gnu++2a") ||
+   Std->containsValue("c++20") || Std->containsValue("gnu++20") ||
+   Std->containsValue("c++2b") || Std->containsValue("gnu++2b") ||
+   Std->containsValue("c++23") || Std->containsValue("gnu++23") ||
+   Std->containsValue("c++latest") || Std->containsValue("gnu++latest"));
   bool HaveModules = HaveStdCXXModules;
 
   // -fmodules enables the use of precompiled modules (off by default).
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148654: Modify BoundsSan to improve debuggability

2023-05-12 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a reviewer: melver.
smeenai added a comment.

The patch should be uploaded with full context to make review easier.

Adding another potential reviewer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148654/new/

https://reviews.llvm.org/D148654

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148654: Modify BoundsSan to improve debuggability

2023-05-12 Thread Oskar Wirga via Phabricator via cfe-commits
oskarwirga updated this revision to Diff 521767.
oskarwirga added a comment.

Add full context


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148654/new/

https://reviews.llvm.org/D148654

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGen/bounds-checking.c
  llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp

Index: llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
===
--- llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
+++ llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp
@@ -39,6 +39,10 @@
 static cl::opt SingleTrapBB("bounds-checking-single-trap",
   cl::desc("Use one trap block per function"));
 
+static cl::opt
+DebugTrapBB("bounds-checking-debug-trap",
+cl::desc("Use one trap block per check despite optimizations"));
+
 STATISTIC(ChecksAdded, "Bounds checks added");
 STATISTIC(ChecksSkipped, "Bounds checks skipped");
 STATISTIC(ChecksUnable, "Bounds checks unable to add");
@@ -182,24 +186,39 @@
   // will create a fresh block every time it is called.
   BasicBlock *TrapBB = nullptr;
   auto GetTrapBB = [&TrapBB](BuilderTy &IRB) {
-if (TrapBB && SingleTrapBB)
-  return TrapBB;
-
-Function *Fn = IRB.GetInsertBlock()->getParent();
-// FIXME: This debug location doesn't make a lot of sense in the
-// `SingleTrapBB` case.
-auto DebugLoc = IRB.getCurrentDebugLocation();
-IRBuilder<>::InsertPointGuard Guard(IRB);
-TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
-IRB.SetInsertPoint(TrapBB);
-
-auto *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
-CallInst *TrapCall = IRB.CreateCall(F, {});
-TrapCall->setDoesNotReturn();
-TrapCall->setDoesNotThrow();
-TrapCall->setDebugLoc(DebugLoc);
-IRB.CreateUnreachable();
-
+if (DebugTrapBB) {
+  Function *Fn = IRB.GetInsertBlock()->getParent();
+  auto DebugLoc = IRB.getCurrentDebugLocation();
+  IRBuilder<>::InsertPointGuard Guard(IRB);
+  TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
+  IRB.SetInsertPoint(TrapBB);
+  auto *F =
+  Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::ubsantrap);
+  CallInst *TrapCall =
+  IRB.CreateCall(F, ConstantInt::get(IRB.getInt8Ty(), Fn->size()));
+  TrapCall->setDoesNotReturn();
+  TrapCall->setDoesNotThrow();
+  TrapCall->setDebugLoc(DebugLoc);
+  IRB.CreateUnreachable();
+} else {
+  if (TrapBB && SingleTrapBB)
+return TrapBB;
+
+  Function *Fn = IRB.GetInsertBlock()->getParent();
+  // FIXME: This debug location doesn't make a lot of sense in the
+  // `SingleTrapBB` case.
+  auto DebugLoc = IRB.getCurrentDebugLocation();
+  IRBuilder<>::InsertPointGuard Guard(IRB);
+  TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
+  IRB.SetInsertPoint(TrapBB);
+
+  auto *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
+  CallInst *TrapCall = IRB.CreateCall(F, {});
+  TrapCall->setDoesNotReturn();
+  TrapCall->setDoesNotThrow();
+  TrapCall->setDebugLoc(DebugLoc);
+  IRB.CreateUnreachable();
+}
 return TrapBB;
   };
 
Index: clang/test/CodeGen/bounds-checking.c
===
--- clang/test/CodeGen/bounds-checking.c
+++ clang/test/CodeGen/bounds-checking.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -fsanitize=local-bounds -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
 // RUN: %clang_cc1 -fsanitize=array-bounds -O -fsanitize-trap=array-bounds -emit-llvm -triple x86_64-apple-darwin10 -DNO_DYNAMIC %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fsanitize=local-bounds -fsanitize-trap=local-bounds -O3 -mllvm -bounds-checking-debug-trap -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s --check-prefixes=NOOPTLOCAL
+// RUN: %clang_cc1 -fsanitize=array-bounds -fsanitize-trap=array-bounds -O3 -mllvm -sanitizer-de-opt-traps -emit-llvm -triple x86_64-apple-darwin10 %s -o - | FileCheck %s --check-prefixes=NOOPTARRAY
 //
 // REQUIRES: x86-registered-target
 
@@ -66,3 +68,16 @@
   // CHECK-NOT: @llvm.ubsantrap
   return u->c[i];
 }
+
+char B[10];
+char B2[10];
+// CHECK-LABEL: @f8
+void f8(int i, int k) {
+  // NOOPTLOCAL: call void @llvm.ubsantrap(i8 3)
+  // NOOPTARRAY: call void @llvm.ubsantrap(i8 2)
+  B[i] = '\0';
+
+  // NOOPTLOCAL: call void @llvm.ubsantrap(i8 5)
+  // NOOPTARRAY: call void @llvm.ubsantrap(i8 4)
+  B2[k] = '\0';
+}
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -48,6 +48,11 @@
 using namespace clang;
 using namespace CodeGen;
 
+// Experiment to make sanitizers easier to debug
+static llvm::cl::opt ClSanitizeDebugDeoptimization(
+"sanitizer-de-opt-traps", llvm::cl::Optional,
+ 

[PATCH] D146054: [RISCV] Add --print-supported-extensions and -march=help support

2023-05-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D146054#4337866 , @kito-cheng 
wrote:

> GCC ins't implement yet, but planed, so add it later I think?
>
> @4vtomat already drop -march=help, @MaskRay did you mind take a look again?

Done. But this update still doesn't look quite polished. If `-march=help` is 
dropped, at the very least the subject needs to updated.




Comment at: clang/tools/driver/cc1_main.cpp:187
+/// Print supported extensions of the given target.
+static int PrintSupportedExtensions(std::string TargetStr) {
+  llvm::riscvMarchHelp();

Use camelCase for new function names. `StringRef TargetStr`?



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:26
 
+void riscvMarchHelp();
+

This naming does not match the `--print-supported-extensions` option name.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:143
+void llvm::riscvMarchHelp() {
+  errs() << "All available -march extensions for RISC-V\n\n";
+  errs() << '\t' << left_justify("Name", 20) << "Version\n";

For most `--print-*` options, the output goes to stdout instead of stderr.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146054/new/

https://reviews.llvm.org/D146054

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >