[PATCH] D130831: [CodeGen] Track DeferredDecls that have been emitted

2022-08-27 Thread Jun Zhang 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 rGa4f84f1b2e92: [CodeGen] Track DeferredDecls that have been 
emitted (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130831

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/lambda.cpp


Index: clang/test/Interpreter/lambda.cpp
===
--- /dev/null
+++ clang/test/Interpreter/lambda.cpp
@@ -0,0 +1,21 @@
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+extern "C" int printf(const char *, ...);
+
+auto l1 = []() { printf("ONE\n"); return 42; };
+auto l2 = []() { printf("TWO\n"); return 17; };
+
+auto r1 = l1();
+// CHECK: ONE
+auto r2 = l2();
+// CHECK: TWO
+auto r3 = l2();
+// CHECK: TWO
+
+%quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3356,6 +3356,7 @@
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
+EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -4073,6 +4074,7 @@
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
+  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4354,6 +4356,7 @@
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
+EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 


Index: clang/test/Interpreter/lambda.cpp
===
--- /dev/null
+++ clang/test/Interpreter/lambda.cpp
@@ -0,0 +1,21 @@
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+extern "C" int printf(const char *, ...);
+
+auto l1 = []() { printf("ONE\n"); return 42; };
+auto l2 = []() { printf("TWO\n"); return 17; };
+
+auto r1 = l1();
+// CHECK: ONE
+auto r2 = l2();
+// CHECK: TWO
+auto r3 = l2();
+// CHECK: TWO
+
+%quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3356,6 +3356,7 @@
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
+EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -4073,6 +4074,7 @@
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
+  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4354,6 +4356,7 @@
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
+EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-08-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: aaron.ballman.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If the declaration of an identifier has block scope, and the identifier has
external or internal linkage, the declaration shall have no initializer for
the identifier.

Clang now gives a correct diagnostic for this case.
Fixes https://github.com/llvm/llvm-project/issues/57478

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133088

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/error-decl-block-internal-linkage-no-init.c


Index: clang/test/Sema/error-decl-block-internal-linkage-no-init.c
===
--- /dev/null
+++ clang/test/Sema/error-decl-block-internal-linkage-no-init.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+static int x;
+
+void f(void)
+{
+extern int x = 1; // expected-error {{declaration of block scope 
identifier with internal linkage shall have no initializer}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12771,9 +12771,17 @@
 return;
   }
 
+  // C99 6.7.8p5. C++ has no such restriction, but that is a defect.
   if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) {
-// C99 6.7.8p5. C++ has no such restriction, but that is a defect.
-Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
+
+// C2x 6.7.10p6.
+unsigned DiagKind = diag::err_block_extern_cant_init;
+bool IsInBlock =
+getCurScope()->getFlags() & (Scope::FnScope | Scope::BlockScope);
+if (IsInBlock && VDecl->getFormalLinkage() == InternalLinkage)
+  DiagKind = diag::err_block_internal_linkage_no_init;
+
+Diag(VDecl->getLocation(), DiagKind);
 VDecl->setInvalidDecl();
 return;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5896,6 +5896,9 @@
 "'loader_uninitialized' attribute">;
 def err_block_extern_cant_init : Error<
   "'extern' variable cannot have an initializer">;
+def err_block_internal_linkage_no_init : Error<
+  "declaration of block scope identifier with internal linkage shall "
+  "have no initializer">;
 def warn_extern_init : Warning<"'extern' variable has an initializer">,
   InGroup>;
 def err_variable_object_no_init : Error<
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -116,6 +116,9 @@
 - Correctly diagnose a future keyword if it exist as a keyword in the higher
   language version and specifies in which version it will be a keyword. This
   supports both c and c++ language.
+- Clang will now give a new more accurate diagnostic for declaration of block
+  scope identifiers that have internal linkage that has an initializer.
+  Fixes `Issue 57478: `_.
 
 Non-comprehensive list of changes in this release
 -


Index: clang/test/Sema/error-decl-block-internal-linkage-no-init.c
===
--- /dev/null
+++ clang/test/Sema/error-decl-block-internal-linkage-no-init.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+static int x;
+
+void f(void)
+{
+extern int x = 1; // expected-error {{declaration of block scope identifier with internal linkage shall have no initializer}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12771,9 +12771,17 @@
 return;
   }
 
+  // C99 6.7.8p5. C++ has no such restriction, but that is a defect.
   if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) {
-// C99 6.7.8p5. C++ has no such restriction, but that is a defect.
-Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
+
+// C2x 6.7.10p6.
+unsigned DiagKind = diag::err_block_extern_cant_init;
+bool IsInBlock =
+getCurScope()->getFlags() & (Scope::FnScope | Scope::BlockScope);
+if (IsInBlock && VDecl->getFormalLinkage() == InternalLinkage)
+  DiagKind = diag::err_block_internal_linkage_no_init;
+
+Diag(VDecl->getLocation(), DiagKind);
 VDecl->setInvalidDecl();
 return;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
==

[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-08-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 457171.
junaire added a comment.

Simpify code a little bit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133088

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/error-decl-block-internal-linkage-no-init.c


Index: clang/test/Sema/error-decl-block-internal-linkage-no-init.c
===
--- /dev/null
+++ clang/test/Sema/error-decl-block-internal-linkage-no-init.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+static int x;
+
+void f(void)
+{
+extern int x = 1; // expected-error {{declaration of block scope 
identifier with internal linkage shall have no initializer}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12771,9 +12771,14 @@
 return;
   }
 
+  // C99 6.7.8p5. C++ has no such restriction, but that is a defect.
   if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) {
-// C99 6.7.8p5. C++ has no such restriction, but that is a defect.
-Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
+unsigned DiagKind = diag::err_block_extern_cant_init;
+// C2x 6.7.10p6.
+if (VDecl->getFormalLinkage() == InternalLinkage)
+  DiagKind = diag::err_block_internal_linkage_no_init;
+
+Diag(VDecl->getLocation(), DiagKind);
 VDecl->setInvalidDecl();
 return;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5896,6 +5896,9 @@
 "'loader_uninitialized' attribute">;
 def err_block_extern_cant_init : Error<
   "'extern' variable cannot have an initializer">;
+def err_block_internal_linkage_no_init : Error<
+  "declaration of block scope identifier with internal linkage shall "
+  "have no initializer">;
 def warn_extern_init : Warning<"'extern' variable has an initializer">,
   InGroup>;
 def err_variable_object_no_init : Error<
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -116,6 +116,9 @@
 - Correctly diagnose a future keyword if it exist as a keyword in the higher
   language version and specifies in which version it will be a keyword. This
   supports both c and c++ language.
+- Clang will now give a new more accurate diagnostic for declaration of block
+  scope identifiers that have internal linkage that has an initializer.
+  Fixes `Issue 57478: `_.
 
 Non-comprehensive list of changes in this release
 -


Index: clang/test/Sema/error-decl-block-internal-linkage-no-init.c
===
--- /dev/null
+++ clang/test/Sema/error-decl-block-internal-linkage-no-init.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+static int x;
+
+void f(void)
+{
+extern int x = 1; // expected-error {{declaration of block scope identifier with internal linkage shall have no initializer}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12771,9 +12771,14 @@
 return;
   }
 
+  // C99 6.7.8p5. C++ has no such restriction, but that is a defect.
   if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) {
-// C99 6.7.8p5. C++ has no such restriction, but that is a defect.
-Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
+unsigned DiagKind = diag::err_block_extern_cant_init;
+// C2x 6.7.10p6.
+if (VDecl->getFormalLinkage() == InternalLinkage)
+  DiagKind = diag::err_block_internal_linkage_no_init;
+
+Diag(VDecl->getLocation(), DiagKind);
 VDecl->setInvalidDecl();
 return;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5896,6 +5896,9 @@
 "'loader_uninitialized' attribute">;
 def err_block_extern_cant_init : Error<
   "'extern' variable cannot have an initializer">;
+def err_block_internal_linkage_no_init : Error<
+  "declaration of block scope identifier with internal linkage shall "
+  "have no initializer">;
 def warn_extern_init : Warning<"'extern' variable has an initializer">,
   InGroup>;
 def err_variable_object_no_init : Error<
Index: clang/docs/Rel

[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-09-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 457485.
junaire added a comment.

Update the existing diagnostic and its tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133088

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Sema/array-init.c
  clang/test/Sema/err-decl-block-extern-no-init.c
  clang/test/Sema/private-extern.c

Index: clang/test/Sema/private-extern.c
===
--- clang/test/Sema/private-extern.c
+++ clang/test/Sema/private-extern.c
@@ -69,9 +69,9 @@
 struct s0 { int x; };
 
 void f9(void) {
-  extern int g15 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int g15 = 0; // expected-error{{declaration of block scope identifier with external linkage shall have no initializer}}
   // FIXME: linkage specifier in warning.
-  __private_extern__ int g16 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  __private_extern__ int g16 = 0; // expected-error{{declaration of block scope identifier with external linkage shall have no initializer}}
 }
 
 extern int g17;
Index: clang/test/Sema/err-decl-block-extern-no-init.c
===
--- /dev/null
+++ clang/test/Sema/err-decl-block-extern-no-init.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+static int x;
+
+void foo(void)
+{
+extern int x = 1; // expected-error {{declaration of block scope identifier with internal linkage shall have no initializer}}
+}
+
+int y;
+
+void bar(void)
+{
+extern int y = 1; // expected-error {{declaration of block scope identifier with external linkage shall have no initializer}}
+
+}
Index: clang/test/Sema/array-init.c
===
--- clang/test/Sema/array-init.c
+++ clang/test/Sema/array-init.c
@@ -48,7 +48,7 @@
 
   struct threeElements *p = 7; // expected-error{{incompatible integer to pointer conversion initializing 'struct threeElements *' with an expression of type 'int'}}
 
-  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{declaration of block scope identifier with external linkage shall have no initializer}}
 
   static long x2[3] = { 1.0,
 "abc", // expected-error{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char[4]'}}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -69,7 +69,7 @@
 // storage-class-specifiers
 static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
 thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
-extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{cannot have an initializer}}
+extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with external linkage shall have no initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12771,9 +12771,14 @@
 return;
   }
 
+  // C99 6.7.8p5. C++ has no such restriction, but that is a defect.
   if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) {
-// C99 6.7.8p5. C++ has no such restriction, but that is a defect.
-Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
+unsigned LinkageKind = /*external*/ 0;
+// C2x 6.7.10p6.
+if (VDecl->getFormalLinkage() == InternalLinkage)
+  LinkageKind = /*internal*/ 1;
+
+Diag(VDecl->getLocation(), diag::err_block_extern_cant_init) << LinkageKind;
 VDecl->setInvalidDecl();
 return;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5895,7 +5895,8 @@
 : Error<"variable %0 cannot be declared both 'extern' and with the "
 "'loader_uninitialized' attribute">;
 def err_block_extern_cant_init : Error<
-  "'extern' variable cannot have an initializer">;
+  "declaration of block scope identifier with %select{external|internal}0 "
+  "linkage shall have no initializer">;
 def warn_extern_init : Warning<"'ext

[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-09-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 457855.
junaire added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133088

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Sema/array-init.c
  clang/test/Sema/err-decl-block-extern-no-init.c
  clang/test/Sema/private-extern.c

Index: clang/test/Sema/private-extern.c
===
--- clang/test/Sema/private-extern.c
+++ clang/test/Sema/private-extern.c
@@ -69,9 +69,9 @@
 struct s0 { int x; };
 
 void f9(void) {
-  extern int g15 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int g15 = 0; // expected-error{{declaration of block scope identifier with external linkage shall have no initializer}}
   // FIXME: linkage specifier in warning.
-  __private_extern__ int g16 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  __private_extern__ int g16 = 0; // expected-error{{declaration of block scope identifier with external linkage shall have no initializer}}
 }
 
 extern int g17;
Index: clang/test/Sema/err-decl-block-extern-no-init.c
===
--- /dev/null
+++ clang/test/Sema/err-decl-block-extern-no-init.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+static int x;
+
+void foo(void)
+{
+extern int x = 1; // expected-error {{declaration of block scope identifier with internal linkage shall have no initializer}}
+}
+
+int y;
+
+void bar(void)
+{
+extern int y = 1; // expected-error {{declaration of block scope identifier with external linkage shall have no initializer}}
+
+}
Index: clang/test/Sema/array-init.c
===
--- clang/test/Sema/array-init.c
+++ clang/test/Sema/array-init.c
@@ -48,7 +48,7 @@
 
   struct threeElements *p = 7; // expected-error{{incompatible integer to pointer conversion initializing 'struct threeElements *' with an expression of type 'int'}}
 
-  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{declaration of block scope identifier with external linkage shall have no initializer}}
 
   static long x2[3] = { 1.0,
 "abc", // expected-error{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char[4]'}}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -69,7 +69,7 @@
 // storage-class-specifiers
 static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
 thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
-extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{cannot have an initializer}}
+extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with external linkage shall have no initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12771,9 +12771,14 @@
 return;
   }
 
+  // C99 6.7.8p5. C++ has no such restriction, but that is a defect.
   if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) {
-// C99 6.7.8p5. C++ has no such restriction, but that is a defect.
-Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
+unsigned LinkageKind = /*external*/ 0;
+// C2x 6.7.10p6.
+if (VDecl->getFormalLinkage() == InternalLinkage)
+  LinkageKind = /*internal*/ 1;
+
+Diag(VDecl->getLocation(), diag::err_block_extern_cant_init) << LinkageKind;
 VDecl->setInvalidDecl();
 return;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5901,7 +5901,8 @@
 : Error<"variable %0 cannot be declared both 'extern' and with the "
 "'loader_uninitialized' attribute">;
 def err_block_extern_cant_init : Error<
-  "'extern' variable cannot have an initializer">;
+  "declaration of block scope identifier with %select{external|internal}0 "
+  "linkage shall have no initializer">;
 def warn_extern_init : Warning<"'extern' variable has an initializer">,
   

[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-09-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

gentle ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133088

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


[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-09-10 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 459287.
junaire added a comment.

Try to address Aaron's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133088

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Sema/array-init.c
  clang/test/Sema/err-decl-block-extern-no-init.c
  clang/test/Sema/private-extern.c

Index: clang/test/Sema/private-extern.c
===
--- clang/test/Sema/private-extern.c
+++ clang/test/Sema/private-extern.c
@@ -69,9 +69,9 @@
 struct s0 { int x; };
 
 void f9(void) {
-  extern int g15 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int g15 = 0; // expected-error{{declaration of block scope identifier with linkage cannot have an initializer}}
   // FIXME: linkage specifier in warning.
-  __private_extern__ int g16 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  __private_extern__ int g16 = 0; // expected-error{{declaration of block scope identifier with linkage cannot have an initializer}}
 }
 
 extern int g17;
Index: clang/test/Sema/err-decl-block-extern-no-init.c
===
--- /dev/null
+++ clang/test/Sema/err-decl-block-extern-no-init.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+static int x;
+
+void foo(void)
+{
+extern int x = 1; // expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
+}
+
+int y;
+
+void bar(void)
+{
+extern int y = 1; // expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
+
+}
Index: clang/test/Sema/array-init.c
===
--- clang/test/Sema/array-init.c
+++ clang/test/Sema/array-init.c
@@ -48,7 +48,7 @@
 
   struct threeElements *p = 7; // expected-error{{incompatible integer to pointer conversion initializing 'struct threeElements *' with an expression of type 'int'}}
 
-  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{declaration of block scope identifier with linkage cannot have an initializer}}
 
   static long x2[3] = { 1.0,
 "abc", // expected-error{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char[4]'}}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -69,7 +69,7 @@
 // storage-class-specifiers
 static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
 thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
-extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{cannot have an initializer}}
+extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12773,8 +12773,11 @@
 return;
   }
 
+  // C99 6.7.8p5. If the declaration of an identifier has block scope, and
+  // the identifier has external or internal linkage, the declaration shall
+  // have no initializer for the identifier.
+  // C++14 [dcl.init]p5 is the same restriction for C++.
   if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) {
-// C99 6.7.8p5. C++ has no such restriction, but that is a defect.
 Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
 VDecl->setInvalidDecl();
 return;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5901,7 +5901,7 @@
 : Error<"variable %0 cannot be declared both 'extern' and with the "
 "'loader_uninitialized' attribute">;
 def err_block_extern_cant_init : Error<
-  "'extern' variable cannot have an initializer">;
+  "declaration of block scope identifier with linkage cannot have an initializer">;
 def warn_extern_init : Warning<"'extern' variable has an initializer">,
   InGroup>;
 def err_variable_object_no_init : Error<
Index: clang/docs/ReleaseNotes.rst

[PATCH] D133088: [Clang] Fix wrong diagnostic for scope identifier with internal linkage

2022-09-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 459394.
junaire added a comment.

Rebase, adjust commit message and release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133088

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Parser/cxx1z-decomposition.cpp
  clang/test/Sema/array-init.c
  clang/test/Sema/err-decl-block-extern-no-init.c
  clang/test/Sema/private-extern.c

Index: clang/test/Sema/private-extern.c
===
--- clang/test/Sema/private-extern.c
+++ clang/test/Sema/private-extern.c
@@ -69,9 +69,9 @@
 struct s0 { int x; };
 
 void f9(void) {
-  extern int g15 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int g15 = 0; // expected-error{{declaration of block scope identifier with linkage cannot have an initializer}}
   // FIXME: linkage specifier in warning.
-  __private_extern__ int g16 = 0; // expected-error{{'extern' variable cannot have an initializer}}
+  __private_extern__ int g16 = 0; // expected-error{{declaration of block scope identifier with linkage cannot have an initializer}}
 }
 
 extern int g17;
Index: clang/test/Sema/err-decl-block-extern-no-init.c
===
--- /dev/null
+++ clang/test/Sema/err-decl-block-extern-no-init.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify %s
+static int x;
+
+void foo(void)
+{
+extern int x = 1; // expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
+}
+
+int y;
+
+void bar(void)
+{
+extern int y = 1; // expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
+
+}
Index: clang/test/Sema/array-init.c
===
--- clang/test/Sema/array-init.c
+++ clang/test/Sema/array-init.c
@@ -48,7 +48,7 @@
 
   struct threeElements *p = 7; // expected-error{{incompatible integer to pointer conversion initializing 'struct threeElements *' with an expression of type 'int'}}
 
-  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}}
+  extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{declaration of block scope identifier with linkage cannot have an initializer}}
 
   static long x2[3] = { 1.0,
 "abc", // expected-error{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char[4]'}}
Index: clang/test/Parser/cxx1z-decomposition.cpp
===
--- clang/test/Parser/cxx1z-decomposition.cpp
+++ clang/test/Parser/cxx1z-decomposition.cpp
@@ -69,7 +69,7 @@
 // storage-class-specifiers
 static auto &[a] = n; // expected-warning {{declared 'static' is a C++20 extension}}
 thread_local auto &[b] = n; // expected-warning {{declared 'thread_local' is a C++20 extension}}
-extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{cannot have an initializer}}
+extern auto &[c] = n; // expected-error {{cannot be declared 'extern'}} expected-error {{declaration of block scope identifier with linkage cannot have an initializer}}
 struct S {
   mutable auto &[d] = n; // expected-error {{not permitted in this context}}
 
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -12773,8 +12773,11 @@
 return;
   }
 
+  // C99 6.7.8p5. If the declaration of an identifier has block scope, and
+  // the identifier has external or internal linkage, the declaration shall
+  // have no initializer for the identifier.
+  // C++14 [dcl.init]p5 is the same restriction for C++.
   if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) {
-// C99 6.7.8p5. C++ has no such restriction, but that is a defect.
 Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
 VDecl->setInvalidDecl();
 return;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5901,7 +5901,7 @@
 : Error<"variable %0 cannot be declared both 'extern' and with the "
 "'loader_uninitialized' attribute">;
 def err_block_extern_cant_init : Error<
-  "'extern' variable cannot have an initializer">;
+  "declaration of block scope identifier with linkage cannot have an initializer">;
 def warn_extern_init : Warning<"'extern' variable has an initializer">,
   InGroup>;
 def err_variable_object_no_init : Error<
Index: clang/docs/ReleaseNotes.rst
=

[PATCH] D128782: [CodeGen] Keep track of decls that were deferred and have been emitted.

2022-06-28 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: v.g.vassilev.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds a new field called EmittedDeferredDecls in CodeGenModule
that keeps track of decls that were deferred and have been emitted.

The intention of this patch is to solve issues in the incremental c++,
we'll lose info of decls that are lazily emitted when we undo their
usage.

See example below:

clang-repl> inline int foo() { return 42;}
clang-repl> int bar = foo();
clang-repl> %undo
clang-repl> int baz = foo();
JIT session error: Symbols not found: [ _Z3foov ]
error: Failed to materialize symbols: { (main, { baz, $.incr_module_2.__inits.0,
__orc_init_func.incr_module_2 }) }

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128782

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/Interpreter/code-undo.cpp


Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -20,4 +20,11 @@
 auto r3 = printf("foo() = %d\n", foo());
 // CHECK-NEXT: foo() = 2
 
+inline int bar() { return 42;}
+auto r4 = printf("r4 = %d\n", bar());
+// CHECK-NEXT: r4 = 42
+%undo
+auto r5 = printf("r5 = %d\n", bar());
+// CHECK-NEXT: r5 = 42
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -344,6 +344,20 @@
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
+  }
+
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+if (!llvm::isa(GD.getDecl()))
+  return;
+llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1516,6 +1530,10 @@
 NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
 NewBuilder->TBAA = std::move(TBAA);
+assert(NewBuilder->EmittedDeferredDecls.empty() &&
+   "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
+NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
   }
 
 private:
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -445,6 +445,7 @@
 
 void CodeGenModule::clear() {
   DeferredDeclsToEmit.clear();
+  EmittedDeferredDecls.clear();
   if (OpenMPRuntime)
 OpenMPRuntime->clear();
 }
@@ -510,6 +511,9 @@
 
 void CodeGenModule::Release() {
   EmitDeferred();
+  DeferredDecls.insert(EmittedDeferredDecls.begin(),
+   EmittedDeferredDecls.end());
+  EmittedDeferredDecls.clear();
   EmitVTablesOpportunistically();
   applyGlobalValReplacements();
   applyReplacements();


Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -20,4 +20,11 @@
 auto r3 = printf("foo() = %d\n", foo());
 // CHECK-NEXT: foo() = 2
 
+inline int bar() { return 42;}
+auto r4 = printf("r4 = %d\n", bar());
+// CHECK-NEXT: r4 = 42
+%undo
+auto r5 = printf("r5 = %d\n", bar());
+// CHECK-NEXT: r5 = 42
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -344,6 +344,20 @@
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
+  }
+
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+if (!llvm::isa(GD.getDecl()))
+  return;
+llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1516,6 +1530,10 @@
 NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
 NewBuilder->TBAA = std::move(TBAA);
+assert(NewBuilder->EmittedDeferredDecls.empty() &&
+   "Still have (unmerged) EmittedDeferredDec

[PATCH] D128782: [CodeGen] Keep track of decls that were deferred and have been emitted.

2022-07-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 441667.
junaire added a comment.

- Rebase
- turn clang-format off in tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128782

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/Interpreter/code-undo.cpp


Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -1,3 +1,4 @@
+// clang-format off
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
@@ -20,4 +21,9 @@
 auto r3 = printf("foo() = %d\n", foo());
 // CHECK-NEXT: foo() = 2
 
+inline int bar() { return 42;}
+auto r4 = bar();
+%undo
+auto r5 = bar();
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -344,6 +344,20 @@
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
+  }
+
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+if (!llvm::isa(GD.getDecl()))
+  return;
+llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1516,6 +1530,10 @@
 NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
 NewBuilder->TBAA = std::move(TBAA);
+assert(NewBuilder->EmittedDeferredDecls.empty() &&
+   "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
+NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
   }
 
 private:
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -445,6 +445,7 @@
 
 void CodeGenModule::clear() {
   DeferredDeclsToEmit.clear();
+  EmittedDeferredDecls.clear();
   if (OpenMPRuntime)
 OpenMPRuntime->clear();
 }
@@ -510,6 +511,9 @@
 
 void CodeGenModule::Release() {
   EmitDeferred();
+  DeferredDecls.insert(EmittedDeferredDecls.begin(),
+   EmittedDeferredDecls.end());
+  EmittedDeferredDecls.clear();
   EmitVTablesOpportunistically();
   applyGlobalValReplacements();
   applyReplacements();


Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -1,3 +1,4 @@
+// clang-format off
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
@@ -20,4 +21,9 @@
 auto r3 = printf("foo() = %d\n", foo());
 // CHECK-NEXT: foo() = 2
 
+inline int bar() { return 42;}
+auto r4 = bar();
+%undo
+auto r5 = bar();
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -344,6 +344,20 @@
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
+  }
+
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+if (!llvm::isa(GD.getDecl()))
+  return;
+llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1516,6 +1530,10 @@
 NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
 NewBuilder->TBAA = std::move(TBAA);
+assert(NewBuilder->EmittedDeferredDecls.empty() &&
+   "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
+NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
   }
 
 private:
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -445,6 +445,7 @@
 
 void CodeGenModule:

[PATCH] D128991: [NFC] Add a missing test for for clang-repl

2022-07-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: v.g.vassilev.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This adds a missing test for 0ecbedc0986bd4b7b90a60a5f31d32337160d4c4 

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128991

Files:
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,8 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+int __attribute__((weak)) bar() { return 1; }
+auto r4 = printf("bar() = %d\n", bar());
+// CHECK-NEXT: bar() = 1
+
 %quit


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,8 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+int __attribute__((weak)) bar() { return 1; }
+auto r4 = printf("bar() = %d\n", bar());
+// CHECK-NEXT: bar() = 1
+
 %quit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128991: [NFC] Add a missing test for for clang-repl

2022-07-01 Thread Jun Zhang 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 rG2750985a5ccb: [NFC] Add a missing test for for clang-repl 
(authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128991

Files:
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,8 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+int __attribute__((weak)) bar() { return 1; }
+auto r4 = printf("bar() = %d\n", bar());
+// CHECK-NEXT: bar() = 1
+
 %quit


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -18,4 +18,8 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+int __attribute__((weak)) bar() { return 1; }
+auto r4 = printf("bar() = %d\n", bar());
+// CHECK-NEXT: bar() = 1
+
 %quit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128991: [NFC] Add a missing test for for clang-repl

2022-07-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D128991#3625194 , @thakis wrote:

> Looks like this breaks tests on Windows: 
> http://45.33.8.238/win/61429/step_7.txt
>
> Please take a look and revert for now if it takes a while to fix.

Thanks for the heads up, I'll revert it for now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128991

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


[PATCH] D129042: Reland "[NFC] Add a missing test for for clang-repl"

2022-07-03 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: v.g.vassilev.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reverts 3668d1264e2d246f7e222338b8a5cab18ce1bdab 

As far as we know, `__attribute__((weak))` support has been really bad
in runtimeldyld, so we just disable it in Windows at this moment. This
should fix the angry Windows buildbot.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129042

Files:
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,6 +3,7 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
+// XFAIL: windows-msvc
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -18,4 +19,8 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+int __attribute__((weak)) bar() { return 1; }
+auto r4 = printf("bar() = %d\n", bar());
+// CHECK-NEXT: bar() = 1
+
 %quit


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,6 +3,7 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
+// XFAIL: windows-msvc
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -18,4 +19,8 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+int __attribute__((weak)) bar() { return 1; }
+auto r4 = printf("bar() = %d\n", bar());
+// CHECK-NEXT: bar() = 1
+
 %quit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129042: Reland "[NFC] Add a missing test for for clang-repl"

2022-07-03 Thread Jun Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8679cbc29fb7: Reland "[NFC] Add a missing test for for 
clang-repl" (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129042

Files:
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,6 +3,7 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
+// XFAIL: windows-msvc
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -18,4 +19,8 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+int __attribute__((weak)) bar() { return 1; }
+auto r4 = printf("bar() = %d\n", bar());
+// CHECK-NEXT: bar() = 1
+
 %quit


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,6 +3,7 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
+// XFAIL: windows-msvc
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -18,4 +19,8 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
+int __attribute__((weak)) bar() { return 1; }
+auto r4 = printf("bar() = %d\n", bar());
+// CHECK-NEXT: bar() = 1
+
 %quit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129250: [clang-repl][NFC] Split weak symbol test to a new test

2022-07-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: v.g.vassilev.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Windows has some issues when we try to use `__attribute__((weak))` in
JIT, so we disabled that. But it's not worth to disable the whole test
just for this single feature. This patch split that part from the
original test so we can keep testing stuff that normally working in
Windows.

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129250

Files:
  clang/test/Interpreter/execute-weak.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -6,18 +6,6 @@
 // XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
-extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
 
 int __attribute__((weak)) bar() { return 1; }
 auto r4 = printf("bar() = %d\n", bar());


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -6,18 +6,6 @@
 // XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
-extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
 
 int __attribute__((weak)) bar() { return 1; }
 auto r4 = printf("bar() = %d\n", bar());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129250: [clang-repl][NFC] Split weak symbol test to a new test

2022-07-07 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 442879.
junaire added a comment.

Correct copy paster error


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129250

Files:
  clang/test/Interpreter/execute-weak.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -6,21 +6,9 @@
 // XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
-extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
 
 int __attribute__((weak)) bar() { return 1; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 1
 
 %quit


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -6,21 +6,9 @@
 // XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
-extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
 
 int __attribute__((weak)) bar() { return 1; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 1
 
 %quit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129250: [clang-repl][NFC] Split weak symbol test to a new test

2022-07-07 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 442902.
junaire added a comment.

extern printf so we can use, another copy paster mistake...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129250

Files:
  clang/test/Interpreter/execute-weak.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -7,20 +7,8 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
-
-int __attribute__((weak)) bar() { return 1; }
+int __attribute__((weak)) bar() { return 42; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 42
 
 %quit


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -7,20 +7,8 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
-
-int __attribute__((weak)) bar() { return 1; }
+int __attribute__((weak)) bar() { return 42; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 42
 
 %quit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129250: [clang-repl][NFC] Split weak symbol test to a new test

2022-07-07 Thread Jun Zhang 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 rGeee6a12227a6: [clang-repl][NFC] Split weak symbol test to a 
new test (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129250

Files:
  clang/test/Interpreter/execute-weak.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -7,20 +7,8 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
-
-int __attribute__((weak)) bar() { return 1; }
+int __attribute__((weak)) bar() { return 42; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 42
 
 %quit


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -3,7 +3,6 @@
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
@@ -19,8 +18,4 @@
 inline int foo() { return 42; }
 int r3 = foo();
 
-int __attribute__((weak)) bar() { return 1; }
-auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
-
 %quit
Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -7,20 +7,8 @@
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
-int i = 42;
-auto r1 = printf("i = %d\n", i);
-// CHECK: i = 42
-
-struct S { float f = 1.0; S *m = nullptr;} s;
-
-auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
-// CHECK-NEXT: S[f=1.00, m=0x0]
-
-inline int foo() { return 42; }
-int r3 = foo();
-
-int __attribute__((weak)) bar() { return 1; }
+int __attribute__((weak)) bar() { return 42; }
 auto r4 = printf("bar() = %d\n", bar());
-// CHECK-NEXT: bar() = 1
+// CHECK: bar() = 42
 
 %quit
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128782: [CodeGen] Keep track of decls that were deferred and have been emitted.

2022-07-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

gentle ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128782

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


[PATCH] D122657: [NFC] Use range based loop.

2022-03-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: v.g.vassilev, rsmith.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122657

Files:
  clang/lib/AST/ASTDiagnostic.cpp


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -270,9 +270,9 @@
   std::string S = Ty.getAsString(Context.getPrintingPolicy());
   std::string CanS = CanTy.getAsString(Context.getPrintingPolicy());
 
-  for (unsigned I = 0, E = QualTypeVals.size(); I != E; ++I) {
+  for (const intptr_t &QualTypeVal : QualTypeVals) {
 QualType CompareTy =
-QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVals[I]));
+QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVal));
 if (CompareTy.isNull())
   continue;
 if (CompareTy == Ty)
@@ -302,10 +302,10 @@
   // Check to see if we already desugared this type in this
   // diagnostic.  If so, don't do it again.
   bool Repeated = false;
-  for (unsigned i = 0, e = PrevArgs.size(); i != e; ++i) {
+  for (auto &PrevArg : PrevArgs) {
 // TODO: Handle ak_declcontext case.
-if (PrevArgs[i].first == DiagnosticsEngine::ak_qualtype) {
-  void *Ptr = (void*)PrevArgs[i].second;
+if (PrevArg.first == DiagnosticsEngine::ak_qualtype) {
+  void *Ptr = (void *)PrevArg.second;
   QualType PrevTy(QualType::getFromOpaquePtr(Ptr));
   if (PrevTy == Ty) {
 Repeated = true;


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -270,9 +270,9 @@
   std::string S = Ty.getAsString(Context.getPrintingPolicy());
   std::string CanS = CanTy.getAsString(Context.getPrintingPolicy());
 
-  for (unsigned I = 0, E = QualTypeVals.size(); I != E; ++I) {
+  for (const intptr_t &QualTypeVal : QualTypeVals) {
 QualType CompareTy =
-QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVals[I]));
+QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVal));
 if (CompareTy.isNull())
   continue;
 if (CompareTy == Ty)
@@ -302,10 +302,10 @@
   // Check to see if we already desugared this type in this
   // diagnostic.  If so, don't do it again.
   bool Repeated = false;
-  for (unsigned i = 0, e = PrevArgs.size(); i != e; ++i) {
+  for (auto &PrevArg : PrevArgs) {
 // TODO: Handle ak_declcontext case.
-if (PrevArgs[i].first == DiagnosticsEngine::ak_qualtype) {
-  void *Ptr = (void*)PrevArgs[i].second;
+if (PrevArg.first == DiagnosticsEngine::ak_qualtype) {
+  void *Ptr = (void *)PrevArg.second;
   QualType PrevTy(QualType::getFromOpaquePtr(Ptr));
   if (PrevTy == Ty) {
 Repeated = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122657: [NFC] Use range based loop.

2022-03-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 418877.
junaire added a comment.

use const when possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122657

Files:
  clang/lib/AST/ASTDiagnostic.cpp


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -270,9 +270,9 @@
   std::string S = Ty.getAsString(Context.getPrintingPolicy());
   std::string CanS = CanTy.getAsString(Context.getPrintingPolicy());
 
-  for (unsigned I = 0, E = QualTypeVals.size(); I != E; ++I) {
+  for (const intptr_t &QualTypeVal : QualTypeVals) {
 QualType CompareTy =
-QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVals[I]));
+QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVal));
 if (CompareTy.isNull())
   continue;
 if (CompareTy == Ty)
@@ -302,10 +302,10 @@
   // Check to see if we already desugared this type in this
   // diagnostic.  If so, don't do it again.
   bool Repeated = false;
-  for (unsigned i = 0, e = PrevArgs.size(); i != e; ++i) {
+  for (const auto &PrevArg : PrevArgs) {
 // TODO: Handle ak_declcontext case.
-if (PrevArgs[i].first == DiagnosticsEngine::ak_qualtype) {
-  void *Ptr = (void*)PrevArgs[i].second;
+if (PrevArg.first == DiagnosticsEngine::ak_qualtype) {
+  void *Ptr = (void *)PrevArg.second;
   QualType PrevTy(QualType::getFromOpaquePtr(Ptr));
   if (PrevTy == Ty) {
 Repeated = true;


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -270,9 +270,9 @@
   std::string S = Ty.getAsString(Context.getPrintingPolicy());
   std::string CanS = CanTy.getAsString(Context.getPrintingPolicy());
 
-  for (unsigned I = 0, E = QualTypeVals.size(); I != E; ++I) {
+  for (const intptr_t &QualTypeVal : QualTypeVals) {
 QualType CompareTy =
-QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVals[I]));
+QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVal));
 if (CompareTy.isNull())
   continue;
 if (CompareTy == Ty)
@@ -302,10 +302,10 @@
   // Check to see if we already desugared this type in this
   // diagnostic.  If so, don't do it again.
   bool Repeated = false;
-  for (unsigned i = 0, e = PrevArgs.size(); i != e; ++i) {
+  for (const auto &PrevArg : PrevArgs) {
 // TODO: Handle ak_declcontext case.
-if (PrevArgs[i].first == DiagnosticsEngine::ak_qualtype) {
-  void *Ptr = (void*)PrevArgs[i].second;
+if (PrevArg.first == DiagnosticsEngine::ak_qualtype) {
+  void *Ptr = (void *)PrevArg.second;
   QualType PrevTy(QualType::getFromOpaquePtr(Ptr));
   if (PrevTy == Ty) {
 Repeated = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122657: [NFC] Use range based loop.

2022-03-29 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 418882.
junaire added a comment.

Simplify code a little bit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122657

Files:
  clang/lib/AST/ASTDiagnostic.cpp


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -270,9 +270,9 @@
   std::string S = Ty.getAsString(Context.getPrintingPolicy());
   std::string CanS = CanTy.getAsString(Context.getPrintingPolicy());
 
-  for (unsigned I = 0, E = QualTypeVals.size(); I != E; ++I) {
+  for (const intptr_t &QualTypeVal : QualTypeVals) {
 QualType CompareTy =
-QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVals[I]));
+QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVal));
 if (CompareTy.isNull())
   continue;
 if (CompareTy == Ty)
@@ -302,11 +302,11 @@
   // Check to see if we already desugared this type in this
   // diagnostic.  If so, don't do it again.
   bool Repeated = false;
-  for (unsigned i = 0, e = PrevArgs.size(); i != e; ++i) {
+  for (const auto &PrevArg : PrevArgs) {
 // TODO: Handle ak_declcontext case.
-if (PrevArgs[i].first == DiagnosticsEngine::ak_qualtype) {
-  void *Ptr = (void*)PrevArgs[i].second;
-  QualType PrevTy(QualType::getFromOpaquePtr(Ptr));
+if (PrevArg.first == DiagnosticsEngine::ak_qualtype) {
+  QualType PrevTy(
+  QualType::getFromOpaquePtr(reinterpret_cast(PrevArg.second)));
   if (PrevTy == Ty) {
 Repeated = true;
 break;


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -270,9 +270,9 @@
   std::string S = Ty.getAsString(Context.getPrintingPolicy());
   std::string CanS = CanTy.getAsString(Context.getPrintingPolicy());
 
-  for (unsigned I = 0, E = QualTypeVals.size(); I != E; ++I) {
+  for (const intptr_t &QualTypeVal : QualTypeVals) {
 QualType CompareTy =
-QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVals[I]));
+QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVal));
 if (CompareTy.isNull())
   continue;
 if (CompareTy == Ty)
@@ -302,11 +302,11 @@
   // Check to see if we already desugared this type in this
   // diagnostic.  If so, don't do it again.
   bool Repeated = false;
-  for (unsigned i = 0, e = PrevArgs.size(); i != e; ++i) {
+  for (const auto &PrevArg : PrevArgs) {
 // TODO: Handle ak_declcontext case.
-if (PrevArgs[i].first == DiagnosticsEngine::ak_qualtype) {
-  void *Ptr = (void*)PrevArgs[i].second;
-  QualType PrevTy(QualType::getFromOpaquePtr(Ptr));
+if (PrevArg.first == DiagnosticsEngine::ak_qualtype) {
+  QualType PrevTy(
+  QualType::getFromOpaquePtr(reinterpret_cast(PrevArg.second)));
   if (PrevTy == Ty) {
 Repeated = true;
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122657: [NFC] Use range based loop.

2022-03-30 Thread Jun Zhang via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b38292d5d77: [NFC] Use range based loop. (authored by 
junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122657

Files:
  clang/lib/AST/ASTDiagnostic.cpp


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -270,9 +270,9 @@
   std::string S = Ty.getAsString(Context.getPrintingPolicy());
   std::string CanS = CanTy.getAsString(Context.getPrintingPolicy());
 
-  for (unsigned I = 0, E = QualTypeVals.size(); I != E; ++I) {
+  for (const intptr_t &QualTypeVal : QualTypeVals) {
 QualType CompareTy =
-QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVals[I]));
+QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVal));
 if (CompareTy.isNull())
   continue;
 if (CompareTy == Ty)
@@ -302,11 +302,11 @@
   // Check to see if we already desugared this type in this
   // diagnostic.  If so, don't do it again.
   bool Repeated = false;
-  for (unsigned i = 0, e = PrevArgs.size(); i != e; ++i) {
+  for (const auto &PrevArg : PrevArgs) {
 // TODO: Handle ak_declcontext case.
-if (PrevArgs[i].first == DiagnosticsEngine::ak_qualtype) {
-  void *Ptr = (void*)PrevArgs[i].second;
-  QualType PrevTy(QualType::getFromOpaquePtr(Ptr));
+if (PrevArg.first == DiagnosticsEngine::ak_qualtype) {
+  QualType PrevTy(
+  QualType::getFromOpaquePtr(reinterpret_cast(PrevArg.second)));
   if (PrevTy == Ty) {
 Repeated = true;
 break;


Index: clang/lib/AST/ASTDiagnostic.cpp
===
--- clang/lib/AST/ASTDiagnostic.cpp
+++ clang/lib/AST/ASTDiagnostic.cpp
@@ -270,9 +270,9 @@
   std::string S = Ty.getAsString(Context.getPrintingPolicy());
   std::string CanS = CanTy.getAsString(Context.getPrintingPolicy());
 
-  for (unsigned I = 0, E = QualTypeVals.size(); I != E; ++I) {
+  for (const intptr_t &QualTypeVal : QualTypeVals) {
 QualType CompareTy =
-QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVals[I]));
+QualType::getFromOpaquePtr(reinterpret_cast(QualTypeVal));
 if (CompareTy.isNull())
   continue;
 if (CompareTy == Ty)
@@ -302,11 +302,11 @@
   // Check to see if we already desugared this type in this
   // diagnostic.  If so, don't do it again.
   bool Repeated = false;
-  for (unsigned i = 0, e = PrevArgs.size(); i != e; ++i) {
+  for (const auto &PrevArg : PrevArgs) {
 // TODO: Handle ak_declcontext case.
-if (PrevArgs[i].first == DiagnosticsEngine::ak_qualtype) {
-  void *Ptr = (void*)PrevArgs[i].second;
-  QualType PrevTy(QualType::getFromOpaquePtr(Ptr));
+if (PrevArg.first == DiagnosticsEngine::ak_qualtype) {
+  QualType PrevTy(
+  QualType::getFromOpaquePtr(reinterpret_cast(PrevArg.second)));
   if (PrevTy == Ty) {
 Repeated = true;
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122871: Clang-Formatting

2022-04-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

You are not supposed to format the test, because the comment is actually 
something we called regression tests. If you reformat it (put it in the wrong 
place), the test will fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122871

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


[PATCH] D119609: [Clang][Sema] Prohibit expression statement in lambda default argument

2022-04-02 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 419965.
junaire added a comment.

- Rebase.
- Update commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Sema/err-expr-stmt-in-default-arg.cpp
  clang/test/SemaTemplate/dependent-expr.cpp

Index: clang/test/SemaTemplate/dependent-expr.cpp
===
--- clang/test/SemaTemplate/dependent-expr.cpp
+++ clang/test/SemaTemplate/dependent-expr.cpp
@@ -141,15 +141,7 @@
   using U = float; // expected-error {{different types ('float' vs 'decltype(g())' (aka 'void'))}}
 
   void h(auto a, decltype(g())*) {} // expected-note {{previous}}
-  void h(auto a, void*) {} // expected-error {{redefinition}}
-
-  void i(auto a) {
-[](auto a, int = ({decltype(a) i; i * 2;})){}(a); // expected-error {{invalid operands to binary expression ('decltype(a)' (aka 'void *') and 'int')}} expected-note {{in instantiation of}}
-  }
-  void use_i() {
-i(0);
-i((void*)0); // expected-note {{instantiation of}}
-  }
+  void h(auto a, void *) {} // expected-error {{redefinition}}
 }
 
 namespace BindingInStmtExpr {
Index: clang/test/Sema/err-expr-stmt-in-default-arg.cpp
===
--- /dev/null
+++ clang/test/Sema/err-expr-stmt-in-default-arg.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20
+
+void foo() {
+  void fn(int i, int = ({ 1; })); // expected-error {{expression statement not permitted in default argument}}
+
+  auto a = [](int = ({ 1; })) {}; // expected-error {{expression statement not permitted in default argument}}
+
+  auto b = [](){}; // expected-error {{expression statement not permitted in default argument}}
+
+  void fn(int i, int j = ({{}, {}, {,}}), int k = ""); // expected-error {{expression statement not permitted in default argument}} expected-error {{cannot initialize a parameter of type 'int' with an lvalue of type 'const char[1]'}} expected-note {{passing argument to parameter 'k' here}}
+}
+
+template 
+int bar(Callable &&Call) {
+  return Call();
+}
+
+int baz() {
+  auto l = [](int a = ({ int x = 12; x; })) { // expected-error {{expression statement not permitted in default argument}}
+return 1;
+  };
+  return bar(l);
+}
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -19,6 +19,7 @@
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
+#include "clang/Sema/SemaDiagnostic.h"
 #include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 
@@ -1007,18 +1008,23 @@
   SourceLocation EqualLoc;
   ExprResult DefaultArg;
   if (TryConsumeToken(tok::equal, EqualLoc)) {
-// C++ [temp.param]p15:
-//   When parsing a default template-argument for a non-type
-//   template-parameter, the first non-nested > is taken as the
-//   end of the template-parameter-list rather than a greater-than
-//   operator.
-GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
-EnterExpressionEvaluationContext ConstantEvaluated(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-
-DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
-if (DefaultArg.isInvalid())
+if (Tok.is(tok::l_paren) && NextToken().is(tok::l_brace)) {
+  Diag(Tok.getLocation(), diag::err_expr_statement_in_default_arg);
   SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+} else {
+  // C++ [temp.param]p15:
+  //   When parsing a default template-argument for a non-type
+  //   template-parameter, the first non-nested > is taken as the
+  //   end of the template-parameter-list rather than a greater-than
+  //   operator.
+  GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
+  EnterExpressionEvaluationContext ConstantEvaluated(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+  DefaultArg =
+  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  if (DefaultArg.isInvalid())
+SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+}
   }
 
   // Create the parameter.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -7066,8 +7066,16 @@
   if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
 DefArgResult = ParseBraceInitializer();
-  } else
+  } else {
+if (Tok.is

[PATCH] D119609: [Clang][Sema] Prohibit expr statement in the default argument

2022-04-02 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

Hi @aaron.ballman, do you think it's time to consider reviewing this?

I don't why there's no response or progress in GCC, but I think I can submit a 
patch for them if they think this issue is low prior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

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


[PATCH] D119609: [Clang][Sema] Prohibit expr statement in the default argument

2022-04-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/test/Sema/err-expr-stmt-in-default-arg.cpp:10
+
+  void fn(int i, int j = ({{}, {}, {,}}), int k = ""); // expected-error 
{{expression statement not permitted in default argument}} expected-error 
{{cannot initialize a parameter of type 'int' with an lvalue of type 'const 
char[1]'}} expected-note {{passing argument to parameter 'k' here}}
+}

@erichkeane Do you mean this one? Or I get you wrong?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

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


[PATCH] D119609: [Clang][Sema] Prohibit expr statement in the default argument

2022-04-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 420178.
junaire retitled this revision from " [Clang][Sema] Prohibit expr statement in 
the default argument" to "[Clang][Sema] Prohibit expr statement in the default 
argument".
junaire edited the summary of this revision.
junaire added a comment.

Add tests for template arguments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Sema/err-expr-stmt-in-default-arg.cpp
  clang/test/SemaTemplate/dependent-expr.cpp

Index: clang/test/SemaTemplate/dependent-expr.cpp
===
--- clang/test/SemaTemplate/dependent-expr.cpp
+++ clang/test/SemaTemplate/dependent-expr.cpp
@@ -141,15 +141,7 @@
   using U = float; // expected-error {{different types ('float' vs 'decltype(g())' (aka 'void'))}}
 
   void h(auto a, decltype(g())*) {} // expected-note {{previous}}
-  void h(auto a, void*) {} // expected-error {{redefinition}}
-
-  void i(auto a) {
-[](auto a, int = ({decltype(a) i; i * 2;})){}(a); // expected-error {{invalid operands to binary expression ('decltype(a)' (aka 'void *') and 'int')}} expected-note {{in instantiation of}}
-  }
-  void use_i() {
-i(0);
-i((void*)0); // expected-note {{instantiation of}}
-  }
+  void h(auto a, void *) {} // expected-error {{redefinition}}
 }
 
 namespace BindingInStmtExpr {
Index: clang/test/Sema/err-expr-stmt-in-default-arg.cpp
===
--- /dev/null
+++ clang/test/Sema/err-expr-stmt-in-default-arg.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20
+
+void foo() {
+  void fn(int i, int = ({ 1; })); // expected-error {{expression statement not permitted in default argument}}
+
+  auto a = [](int = ({ 1; })) {}; // expected-error {{expression statement not permitted in default argument}}
+
+  auto b = [](){}; // expected-error {{expression statement not permitted in default argument}}
+
+  void fn(int i, int j = ({{}, {}, {,}}), int k = ""); // expected-error {{expression statement not permitted in default argument}} expected-error {{cannot initialize a parameter of type 'int' with an lvalue of type 'const char[1]'}} expected-note {{passing argument to parameter 'k' here}}
+}
+
+template // expected-error {{expression statement not permitted in default argument}}
+void f() {}
+
+template // expected-error {{expression statement not permitted in default argument}}
+class S{};
+
+template 
+int bar(Callable &&Call) {
+  return Call();
+}
+
+int baz() {
+  auto l = [](int a = ({ int x = 12; x; })) { // expected-error {{expression statement not permitted in default argument}}
+return 1;
+  };
+  return bar(l);
+}
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -19,6 +19,7 @@
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
+#include "clang/Sema/SemaDiagnostic.h"
 #include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 
@@ -1007,18 +1008,23 @@
   SourceLocation EqualLoc;
   ExprResult DefaultArg;
   if (TryConsumeToken(tok::equal, EqualLoc)) {
-// C++ [temp.param]p15:
-//   When parsing a default template-argument for a non-type
-//   template-parameter, the first non-nested > is taken as the
-//   end of the template-parameter-list rather than a greater-than
-//   operator.
-GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
-EnterExpressionEvaluationContext ConstantEvaluated(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-
-DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
-if (DefaultArg.isInvalid())
+if (Tok.is(tok::l_paren) && NextToken().is(tok::l_brace)) {
+  Diag(Tok.getLocation(), diag::err_expr_statement_in_default_arg);
   SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+} else {
+  // C++ [temp.param]p15:
+  //   When parsing a default template-argument for a non-type
+  //   template-parameter, the first non-nested > is taken as the
+  //   end of the template-parameter-list rather than a greater-than
+  //   operator.
+  GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
+  EnterExpressionEvaluationContext ConstantEvaluated(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+  DefaultArg =
+  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  if (DefaultArg.isInvalid())
+SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+}
   }
 
   // Create the parameter.
Index: clang/lib/Parse/ParseDecl.cpp
==

[PATCH] D119609: [Clang][Sema] Prohibit expr statement in the default argument

2022-04-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 420384.
junaire added a comment.

Wording issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Sema/stmt-expr-in-default-arg.cpp
  clang/test/SemaTemplate/dependent-expr.cpp

Index: clang/test/SemaTemplate/dependent-expr.cpp
===
--- clang/test/SemaTemplate/dependent-expr.cpp
+++ clang/test/SemaTemplate/dependent-expr.cpp
@@ -141,15 +141,7 @@
   using U = float; // expected-error {{different types ('float' vs 'decltype(g())' (aka 'void'))}}
 
   void h(auto a, decltype(g())*) {} // expected-note {{previous}}
-  void h(auto a, void*) {} // expected-error {{redefinition}}
-
-  void i(auto a) {
-[](auto a, int = ({decltype(a) i; i * 2;})){}(a); // expected-error {{invalid operands to binary expression ('decltype(a)' (aka 'void *') and 'int')}} expected-note {{in instantiation of}}
-  }
-  void use_i() {
-i(0);
-i((void*)0); // expected-note {{instantiation of}}
-  }
+  void h(auto a, void *) {} // expected-error {{redefinition}}
 }
 
 namespace BindingInStmtExpr {
Index: clang/test/Sema/stmt-expr-in-default-arg.cpp
===
--- /dev/null
+++ clang/test/Sema/stmt-expr-in-default-arg.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20
+
+void foo() {
+  void fn(int i, int = ({ 1; })); // expected-error {{default argument may not use a GNU statement expression}}
+
+  auto a = [](int = ({ 1; })) {}; // expected-error {{default argument may not use a GNU statement expression}}
+
+  auto b = [](){}; // expected-error {{default non-type template argument may not use a GNU statement expression}}
+
+  void fn(int i, int j = ({{}, {}, {,}}), int k = ""); // expected-error {{default argument may not use a GNU statement expression}} expected-error {{cannot initialize a parameter of type 'int' with an lvalue of type 'const char[1]'}} expected-note {{passing argument to parameter 'k' here}}
+}
+
+template // expected-error {{default non-type template argument may not use a GNU statement expression}}
+void f() {}
+
+template // expected-error {{default non-type template argument may not use a GNU statement expression}}
+class S{};
+
+template 
+int bar(Callable &&Call) {
+  return Call();
+}
+
+int baz() {
+  auto l = [](int a = ({ int x = 12; x; })) { // expected-error {{default argument may not use a GNU statement expression}}
+return 1;
+  };
+  return bar(l);
+}
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -19,6 +19,7 @@
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
+#include "clang/Sema/SemaDiagnostic.h"
 #include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 
@@ -1007,18 +1008,23 @@
   SourceLocation EqualLoc;
   ExprResult DefaultArg;
   if (TryConsumeToken(tok::equal, EqualLoc)) {
-// C++ [temp.param]p15:
-//   When parsing a default template-argument for a non-type
-//   template-parameter, the first non-nested > is taken as the
-//   end of the template-parameter-list rather than a greater-than
-//   operator.
-GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
-EnterExpressionEvaluationContext ConstantEvaluated(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-
-DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
-if (DefaultArg.isInvalid())
+if (Tok.is(tok::l_paren) && NextToken().is(tok::l_brace)) {
+  Diag(Tok.getLocation(), diag::err_stmt_expr_in_default_arg) << 1;
   SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+} else {
+  // C++ [temp.param]p15:
+  //   When parsing a default template-argument for a non-type
+  //   template-parameter, the first non-nested > is taken as the
+  //   end of the template-parameter-list rather than a greater-than
+  //   operator.
+  GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
+  EnterExpressionEvaluationContext ConstantEvaluated(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+  DefaultArg =
+  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  if (DefaultArg.isInvalid())
+SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+}
   }
 
   // Create the parameter.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -7066,8 +7066,16 @@
   if (getLangOpts()

[PATCH] D119609: [Clang][Sema] Prohibit statement expression in the default argument

2022-04-05 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 420664.
junaire edited the summary of this revision.
junaire added a comment.

- Add release note.
- re-wrap line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Sema/stmt-expr-in-default-arg.cpp
  clang/test/SemaTemplate/dependent-expr.cpp

Index: clang/test/SemaTemplate/dependent-expr.cpp
===
--- clang/test/SemaTemplate/dependent-expr.cpp
+++ clang/test/SemaTemplate/dependent-expr.cpp
@@ -141,15 +141,7 @@
   using U = float; // expected-error {{different types ('float' vs 'decltype(g())' (aka 'void'))}}
 
   void h(auto a, decltype(g())*) {} // expected-note {{previous}}
-  void h(auto a, void*) {} // expected-error {{redefinition}}
-
-  void i(auto a) {
-[](auto a, int = ({decltype(a) i; i * 2;})){}(a); // expected-error {{invalid operands to binary expression ('decltype(a)' (aka 'void *') and 'int')}} expected-note {{in instantiation of}}
-  }
-  void use_i() {
-i(0);
-i((void*)0); // expected-note {{instantiation of}}
-  }
+  void h(auto a, void *) {}   // expected-error {{redefinition}}
 }
 
 namespace BindingInStmtExpr {
Index: clang/test/Sema/stmt-expr-in-default-arg.cpp
===
--- /dev/null
+++ clang/test/Sema/stmt-expr-in-default-arg.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20
+
+void foo() {
+  void fn(int i, int = ({ 1; })); // expected-error {{default argument may not use a GNU statement expression}}
+
+  auto a = [](int = ({ 1; })) {}; // expected-error {{default argument may not use a GNU statement expression}}
+
+  auto b = [](){}; // expected-error {{default non-type template argument may not use a GNU statement expression}}
+
+  void fn(int i, int j = ({{}, {}, {,}}), int k = ""); // expected-error {{default argument may not use a GNU statement expression}} expected-error {{cannot initialize a parameter of type 'int' with an lvalue of type 'const char[1]'}} expected-note {{passing argument to parameter 'k' here}}
+}
+
+template  // expected-error {{default non-type template argument may not use a GNU statement expression}}
+void f() {}
+
+template  // expected-error {{default non-type template argument may not use a GNU statement expression}}
+class S {};
+
+template 
+int bar(Callable &&Call) {
+  return Call();
+}
+
+int baz() {
+  auto l = [](int a = ({ int x = 12; x; })) { // expected-error {{default argument may not use a GNU statement expression}}
+return 1;
+  };
+  return bar(l);
+}
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -19,6 +19,7 @@
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
+#include "clang/Sema/SemaDiagnostic.h"
 #include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 
@@ -1007,18 +1008,23 @@
   SourceLocation EqualLoc;
   ExprResult DefaultArg;
   if (TryConsumeToken(tok::equal, EqualLoc)) {
-// C++ [temp.param]p15:
-//   When parsing a default template-argument for a non-type
-//   template-parameter, the first non-nested > is taken as the
-//   end of the template-parameter-list rather than a greater-than
-//   operator.
-GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
-EnterExpressionEvaluationContext ConstantEvaluated(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-
-DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
-if (DefaultArg.isInvalid())
+if (Tok.is(tok::l_paren) && NextToken().is(tok::l_brace)) {
+  Diag(Tok.getLocation(), diag::err_stmt_expr_in_default_arg) << 1;
   SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+} else {
+  // C++ [temp.param]p15:
+  //   When parsing a default template-argument for a non-type
+  //   template-parameter, the first non-nested > is taken as the
+  //   end of the template-parameter-list rather than a greater-than
+  //   operator.
+  GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
+  EnterExpressionEvaluationContext ConstantEvaluated(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+  DefaultArg =
+  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  if (DefaultArg.isInvalid())
+SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+}
   }
 
   // Create the parameter.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- cla

[PATCH] D119609: [Clang][Sema] Prohibit statement expression in the default argument

2022-04-05 Thread Jun Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8a4d388c7fa4: [Clang][Sema] Prohibit statement expression in 
the default argument (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Sema/stmt-expr-in-default-arg.cpp
  clang/test/SemaTemplate/dependent-expr.cpp

Index: clang/test/SemaTemplate/dependent-expr.cpp
===
--- clang/test/SemaTemplate/dependent-expr.cpp
+++ clang/test/SemaTemplate/dependent-expr.cpp
@@ -141,15 +141,7 @@
   using U = float; // expected-error {{different types ('float' vs 'decltype(g())' (aka 'void'))}}
 
   void h(auto a, decltype(g())*) {} // expected-note {{previous}}
-  void h(auto a, void*) {} // expected-error {{redefinition}}
-
-  void i(auto a) {
-[](auto a, int = ({decltype(a) i; i * 2;})){}(a); // expected-error {{invalid operands to binary expression ('decltype(a)' (aka 'void *') and 'int')}} expected-note {{in instantiation of}}
-  }
-  void use_i() {
-i(0);
-i((void*)0); // expected-note {{instantiation of}}
-  }
+  void h(auto a, void *) {}   // expected-error {{redefinition}}
 }
 
 namespace BindingInStmtExpr {
Index: clang/test/Sema/stmt-expr-in-default-arg.cpp
===
--- /dev/null
+++ clang/test/Sema/stmt-expr-in-default-arg.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20
+
+void foo() {
+  void fn(int i, int = ({ 1; })); // expected-error {{default argument may not use a GNU statement expression}}
+
+  auto a = [](int = ({ 1; })) {}; // expected-error {{default argument may not use a GNU statement expression}}
+
+  auto b = [](){}; // expected-error {{default non-type template argument may not use a GNU statement expression}}
+
+  void fn(int i, int j = ({{}, {}, {,}}), int k = ""); // expected-error {{default argument may not use a GNU statement expression}} expected-error {{cannot initialize a parameter of type 'int' with an lvalue of type 'const char[1]'}} expected-note {{passing argument to parameter 'k' here}}
+}
+
+template  // expected-error {{default non-type template argument may not use a GNU statement expression}}
+void f() {}
+
+template  // expected-error {{default non-type template argument may not use a GNU statement expression}}
+class S {};
+
+template 
+int bar(Callable &&Call) {
+  return Call();
+}
+
+int baz() {
+  auto l = [](int a = ({ int x = 12; x; })) { // expected-error {{default argument may not use a GNU statement expression}}
+return 1;
+  };
+  return bar(l);
+}
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -19,6 +19,7 @@
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
+#include "clang/Sema/SemaDiagnostic.h"
 #include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 
@@ -1007,18 +1008,23 @@
   SourceLocation EqualLoc;
   ExprResult DefaultArg;
   if (TryConsumeToken(tok::equal, EqualLoc)) {
-// C++ [temp.param]p15:
-//   When parsing a default template-argument for a non-type
-//   template-parameter, the first non-nested > is taken as the
-//   end of the template-parameter-list rather than a greater-than
-//   operator.
-GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
-EnterExpressionEvaluationContext ConstantEvaluated(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-
-DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
-if (DefaultArg.isInvalid())
+if (Tok.is(tok::l_paren) && NextToken().is(tok::l_brace)) {
+  Diag(Tok.getLocation(), diag::err_stmt_expr_in_default_arg) << 1;
   SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+} else {
+  // C++ [temp.param]p15:
+  //   When parsing a default template-argument for a non-type
+  //   template-parameter, the first non-nested > is taken as the
+  //   end of the template-parameter-list rather than a greater-than
+  //   operator.
+  GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
+  EnterExpressionEvaluationContext ConstantEvaluated(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+  DefaultArg =
+  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  if (DefaultArg.isInvalid())
+SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+}
   }
 
   // Create the parameter.
Index: clang/lib/Parse/ParseDecl.cpp
==

[PATCH] D130831: [CodeGen] Track DeferredDecls that have been emitted

2022-07-30 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: v.g.vassilev.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If we run into a first usage or definition of a mangled name, and
there's a DeferredDecl that associated with it, we should remember it we
need to emit it later on.

Without this patch, clang-repl hits a JIT symbol not found error:
clang-repl> extern "C" int printf(const char *, ...);
clang-repl> auto l1 = []() { printf("ONE\n"); return 42; };
clang-repl> auto l2 = []() { printf("TWO\n"); return 17; };
clang-repl> auto r1 = l1();
ONE
clang-repl> auto r2 = l2();
TWO
clang-repl> auto r3 = l2();
JIT session error: Symbols not found: [ l2 ]
error: Failed to materialize symbols: { (main,
{ r3, __orc_init_func.incr_module_5, $.incr_module_5.__inits.0 }) }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130831

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/lambda.cpp


Index: clang/test/Interpreter/lambda.cpp
===
--- /dev/null
+++ clang/test/Interpreter/lambda.cpp
@@ -0,0 +1,21 @@
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+extern "C" int printf(const char *, ...);
+
+auto l1 = []() { printf("ONE\n"); return 42; };
+auto l2 = []() { printf("TWO\n"); return 17; };
+
+auto r1 = l1();
+// CHECK: ONE
+auto r2 = l2();
+// CHECK: TWO
+auto r3 = l2();
+// CHECK: TWO
+
+%quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3271,6 +3271,7 @@
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
+EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -3988,6 +3989,7 @@
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
+  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4269,6 +4271,7 @@
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
+EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 


Index: clang/test/Interpreter/lambda.cpp
===
--- /dev/null
+++ clang/test/Interpreter/lambda.cpp
@@ -0,0 +1,21 @@
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+extern "C" int printf(const char *, ...);
+
+auto l1 = []() { printf("ONE\n"); return 42; };
+auto l2 = []() { printf("TWO\n"); return 17; };
+
+auto r1 = l1();
+// CHECK: ONE
+auto r2 = l2();
+// CHECK: TWO
+auto r3 = l2();
+// CHECK: TWO
+
+%quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3271,6 +3271,7 @@
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
+EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -3988,6 +3989,7 @@
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
+  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4269,6 +4271,7 @@
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don

[PATCH] D130827: [clang] Fixed a number of typos

2022-07-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

Hi, I think the main issue is that your patch contains another patch 
unintentionally, please fix that :)




Comment at: clang/CMakeLists.txt:513
-endif()
-
 option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)

Why delete these lines?



Comment at: clang/include/clang/Basic/JsonSupport.h:109
+ std::end(ForbiddenChars),
+ Char) != std::end(ForbiddenChars);
   });

This is not a typo, right? And I think using `llvm::is_contained` is more 
impressive?



Comment at: clang/include/clang/Sema/Sema.h:4022
+  ExprResult &SrcExpr, bool DoFunctionPointerConversion = false,
+  bool Complain = false, SourceRange OpRangeForComplaining = SourceRange(),
+  QualType DestTypeForComplaining = QualType(),

Normally we don't clang-format legacy code like this, as it's bad for git 
blame. 



Comment at: clang/lib/Format/Format.cpp:1724
+Style->QualifierOrder.end(), "type");
+  if (type == Style->QualifierOrder.end())
 return ParseError::MissingQualifierType;

ditto



Comment at: clang/lib/Headers/opencl-c.h:17856
+intel_sub_group_avc_sic_payload_t __ovld intel_sub_group_avc_sic_configure_ipe(
+uchar luma_intra_partition_mask, uchar intra_neighbour_availability,
 uchar left_edge_luma_pixels, uchar upper_left_corner_luma_pixel,

Not sure if we want to format this...



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:1880
+  if (I->getOwnKind() != K && I->args_end() !=
+  std::find(I->args_begin(), I->args_end(), Idx)) {
 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) << AL << 
I;

ditto



Comment at: clang/test/CMakeLists.txt:154
-endif()
-
 # Copy gen_ast_dump_json_test.py to the clang build dir. This allows invoking

Why drop this? I thought it was intentional?



Comment at: clang/test/Interpreter/code-undo.cpp:3
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix

why add this in a typo-fix patch?



Comment at: clang/test/Interpreter/execute-weak.cpp:4
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
 // CHECK-DRIVER: i = 10

why add this in a typo-fix patch?



Comment at: clang/test/Interpreter/execute.cpp:5
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix

why add this in a typo-fix patch?



Comment at: clang/test/Interpreter/global-dtor-win.cpp:1
+// clang-format off
+// FIXME: Merge into global-dtor.cpp when exception support arrives on 
windows-msvc

Is this in main?



Comment at: clang/tools/CMakeLists.txt:17
 add_clang_subdirectory(clang-scan-deps)
-if(HAVE_CLANG_REPL_SUPPORT)
-  add_clang_subdirectory(clang-repl)

Why drop this?



Comment at: clang/tools/clang-repl/ClangRepl.cpp:31
   llvm::cl::Hidden);
+static llvm::cl::opt OptHostSupportsException("host-supports-exception",
+llvm::cl::Hidden);

I think this patch contains another patch...



Comment at: clang/tools/clang-repl/ClangRepl.cpp:70
 
+// Check if the host environment supports c++ exception handling
+// by querying the existence of symbol __cxa_throw.

I think this patch contains another patch...



Comment at: clang/tools/clang-repl/ClangRepl.cpp:130
 
+  if (OptHostSupportsException) {
+if (checkExceptionSupport())

I think this patch contains another patch...



Comment at: clang/unittests/CMakeLists.txt:38
 add_subdirectory(CodeGen)
-if(HAVE_CLANG_REPL_SUPPORT)
-  add_subdirectory(Interpreter)

Why drop this?



Comment at: 
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp:116
 
+  // Check if platform does not support exceptions.
+  {

I think this patch contains another patch...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130827

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


[PATCH] D130422: [clang-repl] Fix incorrect return code

2022-07-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D130422#3689392 , @v.g.vassilev 
wrote:

> Thanks for working on this. This is one of the problems where is hard to find 
> the right behavior. For example, if a repl running in interactive issues an 
> error and then successfully recovers what's the right process return code 
> success or a failure? If we decide it is a success then if we ran in 
> non-interactive mode eg `clang-repl "err"` then the exit code should be a 
> failure.
>
> Either way, this patch improves our current state in which we cannot detect 
> failing tests in `-verify` mode. Let's accept it.

Maybe add a FIXME in the tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130422

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


[PATCH] D130422: [clang-repl] Fix incorrect return code

2022-07-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 448844.
junaire added a comment.

Rebase and add a FIXME


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130422

Files:
  clang/test/Interpreter/fail.cpp
  clang/tools/clang-repl/ClangRepl.cpp


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -107,6 +107,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -114,13 +116,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp->Undo()) {
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+  HasError = true;
+}
 continue;
   }
 
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+HasError = true;
+  }
 }
   }
 
@@ -129,5 +135,7 @@
   // later errors use the default handling behavior instead.
   llvm::remove_fatal_error_handler();
 
-  return checkDiagErrors(Interp->getCompilerInstance());
+  llvm::llvm_shutdown();
+
+  return checkDiagErrors(Interp->getCompilerInstance(), HasError);
 }
Index: clang/test/Interpreter/fail.cpp
===
--- /dev/null
+++ clang/test/Interpreter/fail.cpp
@@ -0,0 +1,17 @@
+// FIXME: There're some inconsistence between interactive and non-interactive
+// mode. For exmaple when clang-repl runs in the interactive mode, issues an
+// error and then successfully recovers, if we decide it's a success then for
+// the non-interactive mode the exit code should be a failure.
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | not clang-repl | FileCheck %s
+BOOM!
+extern "C" int printf(const char *, ...);
+int i = 42;
+auto r1 = printf("i = %d\n", i);
+// CHECK: i = 42
+%quit


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -107,6 +107,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -114,13 +116,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp->Undo()) {
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+  HasError = true;
+}
 continue;
   }
 
-  if (auto Err = Interp->

[PATCH] D130422: [clang-repl] Fix incorrect return code

2022-07-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 448846.
junaire added a comment.

Fix some typos


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130422

Files:
  clang/test/Interpreter/fail.cpp
  clang/tools/clang-repl/ClangRepl.cpp


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -107,6 +107,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -114,13 +116,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp->Undo()) {
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+  HasError = true;
+}
 continue;
   }
 
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+HasError = true;
+  }
 }
   }
 
@@ -129,5 +135,7 @@
   // later errors use the default handling behavior instead.
   llvm::remove_fatal_error_handler();
 
-  return checkDiagErrors(Interp->getCompilerInstance());
+  llvm::llvm_shutdown();
+
+  return checkDiagErrors(Interp->getCompilerInstance(), HasError);
 }
Index: clang/test/Interpreter/fail.cpp
===
--- /dev/null
+++ clang/test/Interpreter/fail.cpp
@@ -0,0 +1,17 @@
+// FIXME: There're some inconsistencies between interactive and non-interactive
+// modes. For example, when clang-repl runs in the interactive mode, issues an
+// error, and then successfully recovers if we decide it's a success then for
+// the non-interactive mode the exit code should be a failure.
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | not clang-repl | FileCheck %s
+BOOM!
+extern "C" int printf(const char *, ...);
+int i = 42;
+auto r1 = printf("i = %d\n", i);
+// CHECK: i = 42
+%quit


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -107,6 +107,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -114,13 +116,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp->Undo()) {
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+  HasError = true;
+}
 continue;
   }
 
-  if (auto Err = Interp->Pars

[PATCH] D130422: [clang-repl] Fix incorrect return code

2022-07-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

@v.g.vassilev if you can take another look at the wording of the FIXME, and 
make sure you're happy about it, that will be awesome.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130422

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


[PATCH] D130422: [clang-repl] Fix incorrect return code

2022-07-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/tools/clang-repl/ClangRepl.cpp:138
 
-  return checkDiagErrors(Interp->getCompilerInstance());
+  llvm::llvm_shutdown();
+

v.g.vassilev wrote:
> This seems not needed. We have already `llvm::llvm_shutdown_obj Y;`
> This seems not needed. We have already `llvm::llvm_shutdown_obj Y;`

Oh good catch, I think I messed it in the rebase :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130422

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


[PATCH] D130827: [clang] Fixed a number of typos

2022-07-31 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:4022
+  ExprResult &SrcExpr, bool DoFunctionPointerConversion = false,
+  bool Complain = false, SourceRange OpRangeForComplaining = SourceRange(),
+  QualType DestTypeForComplaining = QualType(),

GabrielRavier wrote:
> junaire wrote:
> > Normally we don't clang-format legacy code like this, as it's bad for git 
> > blame. 
> I've undone the clang-formatting on this
Oh, I'm sorry about it I think I missed something here. So basically if you 
touched the code then format it is a good choice. I thought there was nothing 
changed here but only formatting, that's something we usually want to avoid. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130827

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


[PATCH] D130422: [clang-repl] Fix incorrect return code

2022-07-31 Thread Jun Zhang 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 rG9caee577ef0f: [clang-repl] Fix incorrect return code 
(authored by junaire).

Changed prior to commit:
  https://reviews.llvm.org/D130422?vs=448846&id=448853#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130422

Files:
  clang/test/Interpreter/fail.cpp
  clang/tools/clang-repl/ClangRepl.cpp


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -107,6 +107,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -114,13 +116,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp->Undo()) {
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+  HasError = true;
+}
 continue;
   }
 
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+HasError = true;
+  }
 }
   }
 
@@ -129,5 +135,5 @@
   // later errors use the default handling behavior instead.
   llvm::remove_fatal_error_handler();
 
-  return checkDiagErrors(Interp->getCompilerInstance());
+  return checkDiagErrors(Interp->getCompilerInstance(), HasError);
 }
Index: clang/test/Interpreter/fail.cpp
===
--- /dev/null
+++ clang/test/Interpreter/fail.cpp
@@ -0,0 +1,17 @@
+// FIXME: There're some inconsistencies between interactive and non-interactive
+// modes. For example, when clang-repl runs in the interactive mode, issues an
+// error, and then successfully recovers if we decide it's a success then for
+// the non-interactive mode the exit code should be a failure.
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | not clang-repl | FileCheck %s
+BOOM!
+extern "C" int printf(const char *, ...);
+int i = 42;
+auto r1 = printf("i = %d\n", i);
+// CHECK: i = 42
+%quit


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -107,6 +107,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -114,13 +116,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp-

[PATCH] D131241: [Clang][Lex] Extend HeaderSearch::LookupFile to control OpenFile behavior.

2022-08-04 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In the downstream projects (ROOT and Cling), we want to do header files
lookups but no `OpenFile` behavior as we only need to register the file
name.

This patch extends the original API call by adding some optional flags
so we can continue use it in the previous way with no breakage.
Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131241

Files:
  clang/include/clang/Lex/DirectoryLookup.h
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/PPDirectives.cpp

Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -949,7 +949,7 @@
 ConstSearchDirIterator *CurDirArg, SmallVectorImpl *SearchPath,
 SmallVectorImpl *RelativePath,
 ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped,
-bool *IsFrameworkFound, bool SkipCache) {
+bool *IsFrameworkFound, bool SkipCache, bool OpenFile, bool CacheFailures) {
   ConstSearchDirIterator CurDirLocal = nullptr;
   ConstSearchDirIterator &CurDir = CurDirArg ? *CurDirArg : CurDirLocal;
 
@@ -1028,7 +1028,7 @@
   Optional FE = HeaderInfo.LookupFile(
   Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath,
   RelativePath, RequestingModule, SuggestedModule, IsMapped,
-  IsFrameworkFound, SkipCache, BuildSystemModule);
+  IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures);
   if (FE) {
 if (SuggestedModule && !LangOpts.AsmPreprocessor)
   HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -398,10 +398,11 @@
 Optional HeaderSearch::getFileAndSuggestModule(
 StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir,
 bool IsSystemHeaderDir, Module *RequestingModule,
-ModuleMap::KnownHeader *SuggestedModule) {
+ModuleMap::KnownHeader *SuggestedModule, bool OpenFile /*=true*/,
+bool CacheFailures /*=true*/) {
   // If we have a module map that might map this header, load it and
   // check whether we'll have a suggestion for a module.
-  auto File = getFileMgr().getFileRef(FileName, /*OpenFile=*/true);
+  auto File = getFileMgr().getFileRef(FileName, OpenFile, CacheFailures);
   if (!File) {
 // For rare, surprising errors (e.g. "out of file handles"), diag the EC
 // message.
@@ -431,7 +432,8 @@
 SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath,
 Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
 bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound,
-bool &IsInHeaderMap, SmallVectorImpl &MappedName) const {
+bool &IsInHeaderMap, SmallVectorImpl &MappedName,
+bool OpenFile) const {
   InUserSpecifiedSystemFramework = false;
   IsInHeaderMap = false;
   MappedName.clear();
@@ -451,9 +453,9 @@
   RelativePath->append(Filename.begin(), Filename.end());
 }
 
-return HS.getFileAndSuggestModule(TmpDir, IncludeLoc, getDir(),
-  isSystemHeaderDirectory(),
-  RequestingModule, SuggestedModule);
+return HS.getFileAndSuggestModule(
+TmpDir, IncludeLoc, getDir(), isSystemHeaderDirectory(),
+RequestingModule, SuggestedModule, OpenFile);
   }
 
   if (isFramework())
@@ -491,7 +493,7 @@
 Dest = HM->lookupFilename(Filename, Path);
   }
 
-  if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest)) {
+  if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest, OpenFile)) {
 FixupSearchPath();
 return *Res;
   }
@@ -840,7 +842,7 @@
 SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath,
 Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
 bool *IsMapped, bool *IsFrameworkFound, bool SkipCache,
-bool BuildSystemModule) {
+bool BuildSystemModule, bool OpenFile, bool CacheFailures) {
   ConstSearchDirIterator CurDirLocal = nullptr;
   ConstSearchDirIterator &CurDir = CurDirArg ? *CurDirArg : CurDirLocal;
 
@@ -869,8 +871,9 @@
 }
 // Otherwise, just return the file.
 return getFileAndSuggestModule(Filename, IncludeLoc, nullptr,
-   /*IsSystemHeaderDir*/false,
-   RequestingModule, SuggestedModule);
+   /*IsSystemHeaderDir*/ false,
+   RequestingModule, SuggestedModule, OpenFile,
+   CacheFailures);
   }
 
   // This is the header that MSVC's header search would have found.
@@ -1010,7 +1013,7 @@
 Option

[PATCH] D131241: [Clang][Lex] Extend HeaderSearch::LookupFile to control OpenFile behavior.

2022-08-05 Thread Jun Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG786b503f66b1: [Clang][Lex] Extend HeaderSearch::LookupFile 
to control OpenFile behavior. (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131241

Files:
  clang/include/clang/Lex/DirectoryLookup.h
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/PPDirectives.cpp

Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -949,7 +949,7 @@
 ConstSearchDirIterator *CurDirArg, SmallVectorImpl *SearchPath,
 SmallVectorImpl *RelativePath,
 ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped,
-bool *IsFrameworkFound, bool SkipCache) {
+bool *IsFrameworkFound, bool SkipCache, bool OpenFile, bool CacheFailures) {
   ConstSearchDirIterator CurDirLocal = nullptr;
   ConstSearchDirIterator &CurDir = CurDirArg ? *CurDirArg : CurDirLocal;
 
@@ -1028,7 +1028,7 @@
   Optional FE = HeaderInfo.LookupFile(
   Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath,
   RelativePath, RequestingModule, SuggestedModule, IsMapped,
-  IsFrameworkFound, SkipCache, BuildSystemModule);
+  IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures);
   if (FE) {
 if (SuggestedModule && !LangOpts.AsmPreprocessor)
   HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -398,10 +398,11 @@
 Optional HeaderSearch::getFileAndSuggestModule(
 StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir,
 bool IsSystemHeaderDir, Module *RequestingModule,
-ModuleMap::KnownHeader *SuggestedModule) {
+ModuleMap::KnownHeader *SuggestedModule, bool OpenFile /*=true*/,
+bool CacheFailures /*=true*/) {
   // If we have a module map that might map this header, load it and
   // check whether we'll have a suggestion for a module.
-  auto File = getFileMgr().getFileRef(FileName, /*OpenFile=*/true);
+  auto File = getFileMgr().getFileRef(FileName, OpenFile, CacheFailures);
   if (!File) {
 // For rare, surprising errors (e.g. "out of file handles"), diag the EC
 // message.
@@ -431,7 +432,8 @@
 SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath,
 Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
 bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound,
-bool &IsInHeaderMap, SmallVectorImpl &MappedName) const {
+bool &IsInHeaderMap, SmallVectorImpl &MappedName,
+bool OpenFile) const {
   InUserSpecifiedSystemFramework = false;
   IsInHeaderMap = false;
   MappedName.clear();
@@ -451,9 +453,9 @@
   RelativePath->append(Filename.begin(), Filename.end());
 }
 
-return HS.getFileAndSuggestModule(TmpDir, IncludeLoc, getDir(),
-  isSystemHeaderDirectory(),
-  RequestingModule, SuggestedModule);
+return HS.getFileAndSuggestModule(
+TmpDir, IncludeLoc, getDir(), isSystemHeaderDirectory(),
+RequestingModule, SuggestedModule, OpenFile);
   }
 
   if (isFramework())
@@ -491,7 +493,7 @@
 Dest = HM->lookupFilename(Filename, Path);
   }
 
-  if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest)) {
+  if (auto Res = HS.getFileMgr().getOptionalFileRef(Dest, OpenFile)) {
 FixupSearchPath();
 return *Res;
   }
@@ -840,7 +842,7 @@
 SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath,
 Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
 bool *IsMapped, bool *IsFrameworkFound, bool SkipCache,
-bool BuildSystemModule) {
+bool BuildSystemModule, bool OpenFile, bool CacheFailures) {
   ConstSearchDirIterator CurDirLocal = nullptr;
   ConstSearchDirIterator &CurDir = CurDirArg ? *CurDirArg : CurDirLocal;
 
@@ -869,8 +871,9 @@
 }
 // Otherwise, just return the file.
 return getFileAndSuggestModule(Filename, IncludeLoc, nullptr,
-   /*IsSystemHeaderDir*/false,
-   RequestingModule, SuggestedModule);
+   /*IsSystemHeaderDir*/ false,
+   RequestingModule, SuggestedModule, OpenFile,
+   CacheFailures);
   }
 
   // This is the header that MSVC's header search would have found.
@@ -1010,7 +1013,7 @@
 Optional File = It->LookupFile(
 Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule,
 SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir,
-IsInHeaderMap, Ma

[PATCH] D131464: [test] Make tests pass regardless of gnu++14/gnu++17 default

2022-08-08 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

I wonder what's the difference between this patch and 
https://reviews.llvm.org/D124434 ? Also add some reviewers that get involved in 
the previous discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131464

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


[PATCH] D131464: [test] Make tests pass regardless of gnu++14/gnu++17 default

2022-08-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/test/AST/ast-dump-openmp-begin-declare-variant_11.c:2
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify=c_mode   
-ast-dump %s   | FileCheck %s --check-prefix=C
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify=cxx_mode 
-ast-dump %s -x c++| FileCheck %s --check-prefix=CXX
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify=cxx_mode 
-ast-dump %s -x c++ -std=c++14 | FileCheck %s --check-prefix=CXX
 

aaron.ballman wrote:
> MaskRay wrote:
> > aaron.ballman wrote:
> > > I'm not really keen on this sort of change because it loses test coverage 
> > > for other language standard versions. We usually try to write our tests 
> > > to be standard version agnostic and only specify a specific language mode 
> > > only when absolutely necessary, which doesn't seem to be the case for a 
> > > lot of the tests in this patch (like this one).
> > I think we can identify such issues (tests which want to test the latest 
> > mature standard) and fix them post-transition. This way the transition 
> > patch feels more isolated and can more easily be reverted.
> > 
> > Not sure whether @junaire wants to work on this...
> > I think we can identify such issues (tests which want to test the latest 
> > mature standard) and fix them post-transition. This way the transition 
> > patch feels more isolated and can more easily be reverted.
> 
> That feels backwards to me, but maybe I'm misunderstanding. If there are 
> tests that are specifically testing C++14 behavior (that did not carry 
> forward into C++17 or later) but don't have a language standard specified on 
> the RUN line, I think we should fix those *before* transitioning the default 
> language standard version because those are NFC fixes that improve the test 
> clarity even if we never make the transition. The transition patch should 
> remain isolated and easily revertible with that approach, but there's less 
> risk that nobody goes back and fixes the tests post-transition.
> Not sure whether @junaire wants to work on this...
I don't think I have enough knowledge and experience to do this work, So I 
would like to abandon my previous patch to hope you can pick it up!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131464

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


[PATCH] D119609: [Clang][Sema] Prohibit expression statement in lambda default argument

2022-03-08 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 413997.
junaire added a comment.

- Make sure Parser can diagnostic remaining error after the expr statement.
- Prohibit expression statement in template argument
- Add more tests
- Better diagnostic message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Sema/err-expr-stmt-in-default-arg.cpp
  clang/test/SemaTemplate/dependent-expr.cpp

Index: clang/test/SemaTemplate/dependent-expr.cpp
===
--- clang/test/SemaTemplate/dependent-expr.cpp
+++ clang/test/SemaTemplate/dependent-expr.cpp
@@ -141,15 +141,7 @@
   using U = float; // expected-error {{different types ('float' vs 'decltype(g())' (aka 'void'))}}
 
   void h(auto a, decltype(g())*) {} // expected-note {{previous}}
-  void h(auto a, void*) {} // expected-error {{redefinition}}
-
-  void i(auto a) {
-[](auto a, int = ({decltype(a) i; i * 2;})){}(a); // expected-error {{invalid operands to binary expression ('decltype(a)' (aka 'void *') and 'int')}} expected-note {{in instantiation of}}
-  }
-  void use_i() {
-i(0);
-i((void*)0); // expected-note {{instantiation of}}
-  }
+  void h(auto a, void *) {} // expected-error {{redefinition}}
 }
 
 namespace BindingInStmtExpr {
Index: clang/test/Sema/err-expr-stmt-in-default-arg.cpp
===
--- /dev/null
+++ clang/test/Sema/err-expr-stmt-in-default-arg.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++20
+
+void foo() {
+  void fn(int i, int = ({ 1; })); // expected-error {{expression statement not permitted in default argument}}
+
+  auto a = [](int = ({ 1; })) {}; // expected-error {{expression statement not permitted in default argument}}
+
+  auto b = [](){}; // expected-error {{expression statement not permitted in default argument}}
+
+  void fn(int i, int j = ({{}, {}, {,}}), int k = ""); // expected-error {{expression statement not permitted in default argument}} expected-error {{cannot initialize a parameter of type 'int' with an lvalue of type 'const char[1]'}} expected-note {{passing argument to parameter 'k' here}}
+}
+
+template 
+int bar(Callable &&Call) {
+  return Call();
+}
+
+int baz() {
+  auto l = [](int a = ({ int x = 12; x; })) { // expected-error {{expression statement not permitted in default argument}}
+return 1;
+  };
+  return bar(l);
+}
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -19,6 +19,7 @@
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
+#include "clang/Sema/SemaDiagnostic.h"
 #include "llvm/Support/TimeProfiler.h"
 using namespace clang;
 
@@ -1007,18 +1008,23 @@
   SourceLocation EqualLoc;
   ExprResult DefaultArg;
   if (TryConsumeToken(tok::equal, EqualLoc)) {
-// C++ [temp.param]p15:
-//   When parsing a default template-argument for a non-type
-//   template-parameter, the first non-nested > is taken as the
-//   end of the template-parameter-list rather than a greater-than
-//   operator.
-GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
-EnterExpressionEvaluationContext ConstantEvaluated(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
-
-DefaultArg = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
-if (DefaultArg.isInvalid())
+if (Tok.is(tok::l_paren) && NextToken().is(tok::l_brace)) {
+  Diag(Tok.getLocation(), diag::err_expr_statement_in_default_arg);
   SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+} else {
+  // C++ [temp.param]p15:
+  //   When parsing a default template-argument for a non-type
+  //   template-parameter, the first non-nested > is taken as the
+  //   end of the template-parameter-list rather than a greater-than
+  //   operator.
+  GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
+  EnterExpressionEvaluationContext ConstantEvaluated(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated);
+  DefaultArg =
+  Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
+  if (DefaultArg.isInvalid())
+SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
+}
   }
 
   // Create the parameter.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -7085,8 +7085,16 @@
   if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
 Diag(Tok, diag::warn_cxx98_compat_general

[PATCH] D119609: [Clang][Sema] Prohibit expression statement in lambda default argument

2022-03-08 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

I just realized that something is not very clear here. Should we prohibit 
expression statements in all default arguments or just in lambda and templates? 
I wonder how gcc folks think about it as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

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


[PATCH] D119609: [Clang][Sema] Prohibit expression statement in lambda default argument

2022-03-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119609#3369816 , @erichkeane 
wrote:

> The commit message isn't quite accurate, we're prohibiting it in ALL default 
> arguments.

Yeah, I just realize this issue after changing the message.

>>> I just realized that something is not very clear here. Should we prohibit 
>>> expression statements in all default arguments or just in lambda and 
>>> templates? I wonder how gcc folks think about it as well.
>
> The latest patch was to prohibit it ONLY in the lambda default parameters, 
> but I though the discussion on the GCC bug had the patch author show 
> preference for all cases.  Can you please ping the thread to see what they 
> plan to do so we can align?

OK, done. let's wait the feedback before we continue the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

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


[PATCH] D119609: [Clang][Sema] Prohibit expression statement in lambda default argument

2022-03-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

Hi @aaron.ballman @erichkeane, I have already left a comment in GCC's Bugzilla, 
but unfortunately there's been no response for almost a week. I'm even not sure 
there's really a bug fix for GCC or not. Can you guys decide how to deal with 
this issue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

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


[PATCH] D119609: [Clang][Sema] Prohibit expression statement in lambda default argument

2022-03-16 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119609#3385671 , @aaron.ballman 
wrote:

> In D119609#3384568 , @junaire wrote:
>
>> Hi @aaron.ballman @erichkeane, I have already left a comment in GCC's 
>> Bugzilla, but unfortunately there's been no response for almost a week. I'm 
>> even not sure there's really a bug fix for GCC or not. Can you guys decide 
>> how to deal with this issue?
>
> Because statement expressions are a GCC extension that Clang tries to 
> emulate, I'd feel most comfortable moving after the GCC devs make their 
> decision. FWIW, the way I read that patch is there is some support for 
> disabling in all default parameters for consistency reasons, and I could get 
> behind that assuming it doesn't break significant code. I would recommend 
> preparing your patch as if the GCC folks agree to disallow statement 
> expressions as a default parameter in general, we can review that, and if GCC 
> devs still haven't made a decision in a few weeks, I think we can land it. If 
> GCC eventually decides to retain the feature for functions but not lambdas, 
> we can re-evaluate whether we want to relax the restriction to match or not.

Thanks for your comment, I would wait a few weeks to see what we can do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

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


[PATCH] D123436: [Clang] Pass llvm::BitstreamCursor by reference. NFC

2022-04-08 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: aaron.ballman, RKSimon, dblaikie.
Herald added a subscriber: arphaman.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

BitstreamCursors are heavy-weight objects that should not be passed by value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123436

Files:
  clang/include/clang/Serialization/GlobalModuleIndex.h
  clang/lib/Serialization/GlobalModuleIndex.cpp


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -127,7 +127,7 @@
 
 GlobalModuleIndex::GlobalModuleIndex(
 std::unique_ptr IndexBuffer,
-llvm::BitstreamCursor Cursor)
+llvm::BitstreamCursor &Cursor)
 : Buffer(std::move(IndexBuffer)), IdentifierIndex(), 
NumIdentifierLookups(),
   NumIdentifierLookupHits() {
   auto Fail = [&](llvm::Error &&Err) {
Index: clang/include/clang/Serialization/GlobalModuleIndex.h
===
--- clang/include/clang/Serialization/GlobalModuleIndex.h
+++ clang/include/clang/Serialization/GlobalModuleIndex.h
@@ -113,7 +113,7 @@
 
   /// Internal constructor. Use \c readIndex() to read an index.
   explicit GlobalModuleIndex(std::unique_ptr Buffer,
- llvm::BitstreamCursor Cursor);
+ llvm::BitstreamCursor &Cursor);
 
   GlobalModuleIndex(const GlobalModuleIndex &) = delete;
   GlobalModuleIndex &operator=(const GlobalModuleIndex &) = delete;


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -127,7 +127,7 @@
 
 GlobalModuleIndex::GlobalModuleIndex(
 std::unique_ptr IndexBuffer,
-llvm::BitstreamCursor Cursor)
+llvm::BitstreamCursor &Cursor)
 : Buffer(std::move(IndexBuffer)), IdentifierIndex(), NumIdentifierLookups(),
   NumIdentifierLookupHits() {
   auto Fail = [&](llvm::Error &&Err) {
Index: clang/include/clang/Serialization/GlobalModuleIndex.h
===
--- clang/include/clang/Serialization/GlobalModuleIndex.h
+++ clang/include/clang/Serialization/GlobalModuleIndex.h
@@ -113,7 +113,7 @@
 
   /// Internal constructor. Use \c readIndex() to read an index.
   explicit GlobalModuleIndex(std::unique_ptr Buffer,
- llvm::BitstreamCursor Cursor);
+ llvm::BitstreamCursor &Cursor);
 
   GlobalModuleIndex(const GlobalModuleIndex &) = delete;
   GlobalModuleIndex &operator=(const GlobalModuleIndex &) = delete;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-08 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: aaron.ballman, rsmith, erichkeane.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Don't warn on unknown type attributes in Parser::ProhibitCXX11Attributes
for most cases, but left the diagnostic to the later checks.
module declaration and module import declaration are special cases.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123447

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp


Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttr=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2444,7 +2446,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttr=*/true);
 
   if (PP.hadModuleLoaderFatalFailure()) {
 // With a fatal failure in the module loader, we abort parsing.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1658,7 +1658,8 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
- bool DiagnoseEmptyAttrs) {
+ bool DiagnoseEmptyAttrs,
+ bool WarnOnUnknownAttr) {
 
   if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
 // An attribute list has been parsed, but it was empty.
@@ -1685,10 +1686,11 @@
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
-if (AL.getKind() == ParsedAttr::UnknownAttribute)
-  Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
-  << AL << AL.getRange();
-else {
+if (AL.getKind() == ParsedAttr::UnknownAttribute) {
+  if (WarnOnUnknownAttr)
+Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+<< AL << AL.getRange();
+} else {
   Diag(AL.getLoc(), DiagID) << AL;
   AL.setInvalid();
 }
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2633,8 +2633,12 @@
   // Forbid C++11 and C2x attributes that appear on certain syntactic locations
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
+  // For the most cases we don't want to warn on unknown attributes, but left
+  // them to later diagnoses. However, for a few cases like module declarations
+  // and module import declarations, we should do it.
   void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
-   bool DiagnoseEmptyAttrs = false);
+   bool DiagnoseEmptyAttrs = false,
+   bool WarnOnUnknownAttr = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.


Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttr=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2444,7 +2446,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+   

[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-08 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 421695.
junaire added a comment.

Add a missing test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123447

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/SemaCXX/warn-once-on-unknown-attr.cpp


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void func() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' 
ignored}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttr=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2444,7 +2446,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttr=*/true);
 
   if (PP.hadModuleLoaderFatalFailure()) {
 // With a fatal failure in the module loader, we abort parsing.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1658,7 +1658,8 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
- bool DiagnoseEmptyAttrs) {
+ bool DiagnoseEmptyAttrs,
+ bool WarnOnUnknownAttr) {
 
   if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
 // An attribute list has been parsed, but it was empty.
@@ -1685,10 +1686,11 @@
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
-if (AL.getKind() == ParsedAttr::UnknownAttribute)
-  Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
-  << AL << AL.getRange();
-else {
+if (AL.getKind() == ParsedAttr::UnknownAttribute) {
+  if (WarnOnUnknownAttr)
+Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+<< AL << AL.getRange();
+} else {
   Diag(AL.getLoc(), DiagID) << AL;
   AL.setInvalid();
 }
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2633,8 +2633,12 @@
   // Forbid C++11 and C2x attributes that appear on certain syntactic locations
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
+  // For the most cases we don't want to warn on unknown attributes, but left
+  // them to later diagnoses. However, for a few cases like module declarations
+  // and module import declarations, we should do it.
   void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
-   bool DiagnoseEmptyAttrs = false);
+   bool DiagnoseEmptyAttrs = false,
+   bool WarnOnUnknownAttr = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void func() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11A

[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 421696.
junaire added a comment.

Update the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123447

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/SemaCXX/warn-once-on-unknown-attr.cpp


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' 
ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttr=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2444,7 +2446,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttr=*/true);
 
   if (PP.hadModuleLoaderFatalFailure()) {
 // With a fatal failure in the module loader, we abort parsing.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1658,7 +1658,8 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
- bool DiagnoseEmptyAttrs) {
+ bool DiagnoseEmptyAttrs,
+ bool WarnOnUnknownAttr) {
 
   if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
 // An attribute list has been parsed, but it was empty.
@@ -1685,10 +1686,11 @@
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
-if (AL.getKind() == ParsedAttr::UnknownAttribute)
-  Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
-  << AL << AL.getRange();
-else {
+if (AL.getKind() == ParsedAttr::UnknownAttribute) {
+  if (WarnOnUnknownAttr)
+Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+<< AL << AL.getRange();
+} else {
   Diag(AL.getLoc(), DiagID) << AL;
   AL.setInvalid();
 }
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2633,8 +2633,12 @@
   // Forbid C++11 and C2x attributes that appear on certain syntactic locations
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
+  // For the most cases we don't want to warn on unknown attributes, but left
+  // them to later diagnoses. However, for a few cases like module declarations
+  // and module import declarations, we should do it.
   void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
-   bool DiagnoseEmptyAttrs = false);
+   bool DiagnoseEmptyAttrs = false,
+   bool WarnOnUnknownAttr = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser

[PATCH] D123436: [Clang] Pass llvm::BitstreamCursor by reference. NFC

2022-04-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: clang/lib/Serialization/GlobalModuleIndex.cpp:130
 std::unique_ptr IndexBuffer,
-llvm::BitstreamCursor Cursor)
+llvm::BitstreamCursor &Cursor)
 : Buffer(std::move(IndexBuffer)), IdentifierIndex(), 
NumIdentifierLookups(),

RKSimon wrote:
> You're not passing this as a const, so the calling function's Cursor will be 
> updated - this doesn't sound generally safe to me - what about a move?
> You're not passing this as a const, so the calling function's Cursor will be 
> updated - this doesn't sound generally safe to me - what about a move?

IIUC, `GlobalModuleIndex::GlobalModuleIndex` is a private function that has 
only been called by `GlobalModuleIndex::readIndex`, and the `Cursor` object has 
only one consumer (`GlobalModuleIndex::readIndex`), so I guess there should not 
be any unsafe concern.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

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


[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 421719.
junaire added a comment.

Rename an argument for consistency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123447

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/SemaCXX/warn-once-on-unknown-attr.cpp


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' 
ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2444,7 +2446,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   if (PP.hadModuleLoaderFatalFailure()) {
 // With a fatal failure in the module loader, we abort parsing.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1658,7 +1658,8 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
- bool DiagnoseEmptyAttrs) {
+ bool DiagnoseEmptyAttrs,
+ bool WarnOnUnknownAttrs) {
 
   if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
 // An attribute list has been parsed, but it was empty.
@@ -1685,10 +1686,11 @@
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
-if (AL.getKind() == ParsedAttr::UnknownAttribute)
-  Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
-  << AL << AL.getRange();
-else {
+if (AL.getKind() == ParsedAttr::UnknownAttribute) {
+  if (WarnOnUnknownAttrs)
+Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+<< AL << AL.getRange();
+} else {
   Diag(AL.getLoc(), DiagID) << AL;
   AL.setInvalid();
 }
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2633,8 +2633,12 @@
   // Forbid C++11 and C2x attributes that appear on certain syntactic locations
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
+  // For the most cases we don't want to warn on unknown attributes, but left
+  // them to later diagnoses. However, for a few cases like module declarations
+  // and module import declarations, we should do it.
   void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
-   bool DiagnoseEmptyAttrs = false);
+   bool DiagnoseEmptyAttrs = false,
+   bool WarnOnUnknownAttrs = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index

[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 422094.
junaire added a comment.

Run test in C2x mode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123447

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/SemaCXX/warn-once-on-unknown-attr.cpp


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -x c %s
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' 
ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2444,7 +2446,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   if (PP.hadModuleLoaderFatalFailure()) {
 // With a fatal failure in the module loader, we abort parsing.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1658,7 +1658,8 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
- bool DiagnoseEmptyAttrs) {
+ bool DiagnoseEmptyAttrs,
+ bool WarnOnUnknownAttrs) {
 
   if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
 // An attribute list has been parsed, but it was empty.
@@ -1685,10 +1686,11 @@
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
-if (AL.getKind() == ParsedAttr::UnknownAttribute)
-  Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
-  << AL << AL.getRange();
-else {
+if (AL.getKind() == ParsedAttr::UnknownAttribute) {
+  if (WarnOnUnknownAttrs)
+Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+<< AL << AL.getRange();
+} else {
   Diag(AL.getLoc(), DiagID) << AL;
   AL.setInvalid();
 }
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2633,8 +2633,12 @@
   // Forbid C++11 and C2x attributes that appear on certain syntactic locations
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
+  // For the most cases we don't want to warn on unknown attributes, but left
+  // them to later diagnoses. However, for a few cases like module declarations
+  // and module import declarations, we should do it.
   void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
-   bool DiagnoseEmptyAttrs = false);
+   bool DiagnoseEmptyAttrs = false,
+   bool WarnOnUnknownAttrs = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.


Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -x c %s
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribu

[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 422096.
junaire added a comment.

Add release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123447

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/SemaCXX/warn-once-on-unknown-attr.cpp

Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -x c %s
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' ignored}}
+}
+
+
+void bar() {
+  [[attr]]; // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2377,7 +2377,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2444,7 +2446,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   if (PP.hadModuleLoaderFatalFailure()) {
 // With a fatal failure in the module loader, we abort parsing.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1658,7 +1658,8 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
- bool DiagnoseEmptyAttrs) {
+ bool DiagnoseEmptyAttrs,
+ bool WarnOnUnknownAttrs) {
 
   if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
 // An attribute list has been parsed, but it was empty.
@@ -1685,10 +1686,11 @@
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
-if (AL.getKind() == ParsedAttr::UnknownAttribute)
-  Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
-  << AL << AL.getRange();
-else {
+if (AL.getKind() == ParsedAttr::UnknownAttribute) {
+  if (WarnOnUnknownAttrs)
+Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+<< AL << AL.getRange();
+} else {
   Diag(AL.getLoc(), DiagID) << AL;
   AL.setInvalid();
 }
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2633,8 +2633,12 @@
   // Forbid C++11 and C2x attributes that appear on certain syntactic locations
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
+  // For the most cases we don't want to warn on unknown attributes, but left
+  // them to later diagnoses. However, for a few cases like module declarations
+  // and module import declarations, we should do it.
   void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
-   bool DiagnoseEmptyAttrs = false);
+   bool DiagnoseEmptyAttrs = false,
+   bool WarnOnUnknownAttrs = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -113,6 +113,8 @@
   This fixes Issue `Issue 54462 `_.
 - Statement expressions are now disabled in default arguments in general.
   This fixes Issue `Issue 53488 `_.
+- Unknown attributes with [[]] spelling now will only be warned once.
+  This fixes Issue `Issue 54817 

[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D123447#3442780 , @aaron.ballman 
wrote:

> Thank you for the fix! Can you add a release note for it as well?
>
> LGTM aside from a minor nit with some comment wording and a testing 
> suggestion.

Hey Aaron, thanks for your review :) I'm not an expert in C or C++, so I'd 
appreciate it if you can provide better wording.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123447

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


[PATCH] D123447: [Clang] Fix unknown type attributes diagnosed twice with [[]] spelling

2022-04-12 Thread Jun Zhang 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 rGf9c2f821d71b: [Clang] Fix unknown type attributes diagnosed 
twice with [[]] spelling (authored by junaire).

Changed prior to commit:
  https://reviews.llvm.org/D123447?vs=422096&id=422205#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123447

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/SemaCXX/warn-once-on-unknown-attr.cpp

Index: clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-once-on-unknown-attr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x -x c %s
+void foo() {
+  int [[attr]] i; // expected-warning {{unknown attribute 'attr' ignored}}
+  (void)sizeof(int [[attr]]); // expected-warning {{unknown attribute 'attr' ignored}}
+}
+
+void bar() {
+  [[attr]];   // expected-warning {{unknown attribute 'attr' ignored}}
+  [[attr]] int i; // expected-warning {{unknown attribute 'attr' ignored}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2386,7 +2386,9 @@
   // We don't support any module attributes yet; just parse them and diagnose.
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_module_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   ExpectAndConsumeSemi(diag::err_module_expected_semi);
 
@@ -2453,7 +2455,9 @@
   ParsedAttributes Attrs(AttrFactory);
   MaybeParseCXX11Attributes(Attrs);
   // We don't support any module import attributes yet.
-  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr);
+  ProhibitCXX11Attributes(Attrs, diag::err_attribute_not_import_attr,
+  /*DiagnoseEmptyAttrs=*/false,
+  /*WarnOnUnknownAttrs=*/true);
 
   if (PP.hadModuleLoaderFatalFailure()) {
 // With a fatal failure in the module loader, we abort parsing.
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -1658,7 +1658,8 @@
 }
 
 void Parser::ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
- bool DiagnoseEmptyAttrs) {
+ bool DiagnoseEmptyAttrs,
+ bool WarnOnUnknownAttrs) {
 
   if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
 // An attribute list has been parsed, but it was empty.
@@ -1685,10 +1686,11 @@
   for (const ParsedAttr &AL : Attrs) {
 if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
   continue;
-if (AL.getKind() == ParsedAttr::UnknownAttribute)
-  Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
-  << AL << AL.getRange();
-else {
+if (AL.getKind() == ParsedAttr::UnknownAttribute) {
+  if (WarnOnUnknownAttrs)
+Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
+<< AL << AL.getRange();
+} else {
   Diag(AL.getLoc(), DiagID) << AL;
   AL.setInvalid();
 }
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2633,8 +2633,12 @@
   // Forbid C++11 and C2x attributes that appear on certain syntactic locations
   // which standard permits but we don't supported yet, for example, attributes
   // appertain to decl specifiers.
+  // For the most cases we don't want to warn on unknown type attributes, but
+  // left them to later diagnoses. However, for a few cases like module
+  // declarations and module import declarations, we should do it.
   void ProhibitCXX11Attributes(ParsedAttributes &Attrs, unsigned DiagID,
-   bool DiagnoseEmptyAttrs = false);
+   bool DiagnoseEmptyAttrs = false,
+   bool WarnOnUnknownAttrs = false);
 
   /// Skip C++11 and C2x attributes and return the end location of the
   /// last one.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -117,6 +117,8 @@
   `C++20 [dcl.fct.def.general]p2 

[PATCH] D123840: [Clang][Sema] Fix invalid redefinition error in if/switch/for statement

2022-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: aaron.ballman, rsmith, erichkeane, dblaikie, rjmccall.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Because lambda will create its own scope, so we shouldn't consider variables
defined with the same name as redefinition error, if the new one is in a
lambda.

After this patch, clang is supposed to accept code below:

void foo() {

  for (int x = [] { int x = 0; return x; }(); ;) ;

}

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123840

Files:
  clang/lib/Sema/IdentifierResolver.cpp
  clang/test/SemaCXX/cxx1z-init-statement.cpp


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123840: [Clang][Sema] Fix invalid redefinition error in if/switch/for statement

2022-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

Hi @erichkeane , thanks for accepting this! But do you think we need to add a 
release note about it? (I'm a totally beginner so sometimes I'm confused about 
when we should do it.)  Also, Do you have any concerns about the wording? In 
fact, I am pretty embarrassed by the current wording in my commit message...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123840

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


[PATCH] D123840: [Clang][Sema] Fix invalid redefinition error in if/switch/for statement

2022-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 423079.
junaire added a comment.

Add a release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123840

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/IdentifierResolver.cpp
  clang/test/SemaCXX/cxx1z-init-statement.cpp


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,9 @@
   This fixes Issue `Issue 52802 
`_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed 
twice.
   This fixes Issue `Issue 54817 
`_.
+- No longer produce a wrong redefinition error if variables are defined in 
if/for/switch init statements
+  and lambda.
+  This fixes `Issue 54913 
`_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,9 @@
   This fixes Issue `Issue 52802 `_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed twice.
   This fixes Issue `Issue 54817 `_.
+- No longer produce a wrong redefinition error if variables are defined in if/for/switch init statements
+  and lambda.
+  This fixes `Issue 54913 `_.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123840: [Clang][Sema] Fix invalid redefinition error in if/switch/for statement

2022-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D123840#3453903 , @erichkeane 
wrote:

> Ah, right, we SHOULD have a release note, please add one and I'll help review 
> the wording.  Commit message is fine for a commit message, particularly with 
> a good release note.

Thanks! I have updated it :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123840

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


[PATCH] D123840: [Clang][Sema] Fix invalid redefinition error in if/switch/for statement

2022-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

I also find the code below really awkward:

  S->getParent()->getFlags() & Scope::ControlScope

I find that we have helpers like `Scope::isBlockScope()` 
`Scope::isisTryScope()` and etc, but no `Scope::isControlScope` and 
`Scope::isFnTryCatchScope`

I will add these helpers as a NFC patch after this one, that won't need a 
release note or review right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123840

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


[PATCH] D123840: [Clang][Sema] Fix invalid redefinition error in if/switch/for statement

2022-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 423085.
junaire added a comment.

Fix bad wording.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123840

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/IdentifierResolver.cpp
  clang/test/SemaCXX/cxx1z-init-statement.cpp


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,10 @@
   This fixes Issue `Issue 52802 
`_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed 
twice.
   This fixes Issue `Issue 54817 
`_.
+- Clang should no longer incorrectly diagnose a variable declaration inside of
+  a lambda expression inside the scope of a if/while/for/switch init statement
+  as a redeclaration.
+  This fixes `Issue 54913 
`_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,10 @@
   This fixes Issue `Issue 52802 `_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed twice.
   This fixes Issue `Issue 54817 `_.
+- Clang should no longer incorrectly diagnose a variable declaration inside of
+  a lambda expression inside the scope of a if/while/for/switch init statement
+  as a redeclaration.
+  This fixes `Issue 54913 `_.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123840: [Clang][Sema] Fix invalid redefinition error in if/switch/for statement

2022-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire marked an inline comment as done.
junaire added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:122
   This fixes Issue `Issue 54817 
`_.
+- No longer produce a wrong redefinition error if variables are defined in 
if/for/switch init statements
+  and lambda.

erichkeane wrote:
> I think this isn't accurate, right?  I thought this had to do with lambdas 
> alone? Is the following accurate?
> 
> `Clang should no longer incorrectly diagnose a variable declaration inside of 
> a lambda expression inside the scope of a if/while/for/switch init statement 
> as a redeclaration.  This fixes ...'.
> I think this isn't accurate, right?  I thought this had to do with lambdas 
> alone? Is the following accurate?
> 
> `Clang should no longer incorrectly diagnose a variable declaration inside of 
> a lambda expression inside the scope of a if/while/for/switch init statement 
> as a redeclaration.  This fixes ...'.

Thanks for the suggestion, It's my fault, I really shouldn't be sleeping in my 
English grammar class...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123840

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


[PATCH] D123840: [Clang][Sema] Fix invalid redefinition error in if/switch/for statement

2022-04-15 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 423086.
junaire marked an inline comment as done.
junaire added a comment.

Update release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123840

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/IdentifierResolver.cpp
  clang/test/SemaCXX/cxx1z-init-statement.cpp


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,10 @@
   This fixes Issue `Issue 52802 
`_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed 
twice.
   This fixes Issue `Issue 54817 
`_.
+- Clang should no longer incorrectly diagnose a variable declaration inside of
+  a lambda expression that shares the name of a variable in a containing
+  if/while/for/switch init statement as a redeclaration.
+  This fixes `Issue 54913 
`_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,10 @@
   This fixes Issue `Issue 52802 `_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed twice.
   This fixes Issue `Issue 54817 `_.
+- Clang should no longer incorrectly diagnose a variable declaration inside of
+  a lambda expression that shares the name of a variable in a containing
+  if/while/for/switch init statement as a redeclaration.
+  This fixes `Issue 54913 `_.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123840: [Clang][Sema] Fix invalid redefinition error in if/switch/for statement

2022-04-15 Thread Jun Zhang 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 rGbe0905a333d6: [Clang][Sema] Fix invalid redefinition error 
in if/switch/for statement (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123840

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/IdentifierResolver.cpp
  clang/test/SemaCXX/cxx1z-init-statement.cpp


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,10 @@
   This fixes Issue `Issue 52802 
`_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed 
twice.
   This fixes Issue `Issue 54817 
`_.
+- Clang should no longer incorrectly diagnose a variable declaration inside of
+  a lambda expression that shares the name of a variable in a containing
+  if/while/for/switch init statement as a redeclaration.
+  This fixes `Issue 54913 
`_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/test/SemaCXX/cxx1z-init-statement.cpp
===
--- clang/test/SemaCXX/cxx1z-init-statement.cpp
+++ clang/test/SemaCXX/cxx1z-init-statement.cpp
@@ -90,3 +90,18 @@
   static_assert(constexpr_switch_init(-2) == 0, "");
   static_assert(constexpr_switch_init(-5) == -1, "");
 }
+
+int test_lambda_init() {
+  if (int x = []() {int x = 42; return x; }(); x) {
+  };
+
+  switch (int y = []() {int y = 42; return y; }(); y) {
+  case 42:
+return 1;
+  }
+
+  for (int x = [] { int x = 0; return x; }();;)
+;
+
+  return 0;
+}
Index: clang/lib/Sema/IdentifierResolver.cpp
===
--- clang/lib/Sema/IdentifierResolver.cpp
+++ clang/lib/Sema/IdentifierResolver.cpp
@@ -121,7 +121,10 @@
   // of the controlled statement.
   //
   assert(S->getParent() && "No TUScope?");
-  if (S->getParent()->getFlags() & Scope::ControlScope) {
+  // If the current decl is in a lambda, we shouldn't consider this is a
+  // redefinition as lambda has its own scope.
+  if (S->getParent()->getFlags() & Scope::ControlScope &&
+  !S->isFunctionScope()) {
 S = S->getParent();
 if (S->isDeclScope(D))
   return true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -119,6 +119,10 @@
   This fixes Issue `Issue 52802 `_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed twice.
   This fixes Issue `Issue 54817 `_.
+- Clang should no longer incorrectly diagnose a variable declaration inside of
+  a lambda expression that shares the name of a variable in a containing
+  if/while/for/switch init statement as a redeclaration.
+  This fixes `Issue 54913 `_.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119103: [NFC][Analyzer] Use range based for loop.

2022-02-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: zaks.anna, dcoughlin.
Herald added subscribers: manas, steakhal, ASDenysPetrov, martong, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use range base loop loop to improve code readability.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119103

Files:
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp


Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -383,14 +383,14 @@
 }
 
 void AnalysisConsumer::storeTopLevelDecls(DeclGroupRef DG) {
-  for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {
+  for (auto &I : DG) {
 
 // Skip ObjCMethodDecl, wait for the objc container to avoid
 // analyzing twice.
-if (isa(*I))
+if (isa(I))
   continue;
 
-LocalTUDecls.push_back(*I);
+LocalTUDecls.push_back(I);
   }
 }
 
@@ -462,11 +462,9 @@
   SetOfConstDecls Visited;
   SetOfConstDecls VisitedAsTopLevel;
   llvm::ReversePostOrderTraversal RPOT(&CG);
-  for (llvm::ReversePostOrderTraversal::rpo_iterator
- I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
+  for (auto &N : RPOT) {
 NumFunctionTopLevel++;
 
-CallGraphNode *N = *I;
 Decl *D = N->getDecl();
 
 // Skip the abstract root node.


Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -383,14 +383,14 @@
 }
 
 void AnalysisConsumer::storeTopLevelDecls(DeclGroupRef DG) {
-  for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {
+  for (auto &I : DG) {
 
 // Skip ObjCMethodDecl, wait for the objc container to avoid
 // analyzing twice.
-if (isa(*I))
+if (isa(I))
   continue;
 
-LocalTUDecls.push_back(*I);
+LocalTUDecls.push_back(I);
   }
 }
 
@@ -462,11 +462,9 @@
   SetOfConstDecls Visited;
   SetOfConstDecls VisitedAsTopLevel;
   llvm::ReversePostOrderTraversal RPOT(&CG);
-  for (llvm::ReversePostOrderTraversal::rpo_iterator
- I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
+  for (auto &N : RPOT) {
 NumFunctionTopLevel++;
 
-CallGraphNode *N = *I;
 Decl *D = N->getDecl();
 
 // Skip the abstract root node.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119103: [NFC][Analyzer] Use range based for loop.

2022-02-06 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119103#3300037 , @steakhal wrote:

> Hmm, I guess you must take it by mutable reference since you push it to 
> `LocalTUDecls`.
> Thanks for the patch. Do you have push permissions? Otherwise, send me your 
> `name ` to let me commit this on your behalf.

Thanks for the feedback! I have commit access so I can push it on my own. :^)

> Do you plan to clean up other loops as well?

I'm a student and I'm learning clang static analyzer so I may send more 
patches. (of course including cleaning up work like this one)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119103

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


[PATCH] D119103: [NFC][Analyzer] Use range based for loop.

2022-02-07 Thread Jun Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG65adf7c2117a: [NFC][Analyzer] Use range based for loop. 
(authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119103

Files:
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp


Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -383,14 +383,14 @@
 }
 
 void AnalysisConsumer::storeTopLevelDecls(DeclGroupRef DG) {
-  for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {
+  for (auto &I : DG) {
 
 // Skip ObjCMethodDecl, wait for the objc container to avoid
 // analyzing twice.
-if (isa(*I))
+if (isa(I))
   continue;
 
-LocalTUDecls.push_back(*I);
+LocalTUDecls.push_back(I);
   }
 }
 
@@ -462,11 +462,9 @@
   SetOfConstDecls Visited;
   SetOfConstDecls VisitedAsTopLevel;
   llvm::ReversePostOrderTraversal RPOT(&CG);
-  for (llvm::ReversePostOrderTraversal::rpo_iterator
- I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
+  for (auto &N : RPOT) {
 NumFunctionTopLevel++;
 
-CallGraphNode *N = *I;
 Decl *D = N->getDecl();
 
 // Skip the abstract root node.


Index: clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -383,14 +383,14 @@
 }
 
 void AnalysisConsumer::storeTopLevelDecls(DeclGroupRef DG) {
-  for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) {
+  for (auto &I : DG) {
 
 // Skip ObjCMethodDecl, wait for the objc container to avoid
 // analyzing twice.
-if (isa(*I))
+if (isa(I))
   continue;
 
-LocalTUDecls.push_back(*I);
+LocalTUDecls.push_back(I);
   }
 }
 
@@ -462,11 +462,9 @@
   SetOfConstDecls Visited;
   SetOfConstDecls VisitedAsTopLevel;
   llvm::ReversePostOrderTraversal RPOT(&CG);
-  for (llvm::ReversePostOrderTraversal::rpo_iterator
- I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
+  for (auto &N : RPOT) {
 NumFunctionTopLevel++;
 
-CallGraphNode *N = *I;
 Decl *D = N->getDecl();
 
 // Skip the abstract root node.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119405: [Clang][Sema] Use C++ standard terminology in clang diagnostics.

2022-02-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: Quuxplusone, aaron.ballman.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang diagnostics should say "floating-point literal" instead of 
"floating-point constant"
according to C++ standard.

Close #53100


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119405

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td


Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -113,10 +113,10 @@
   "predefined identifier is only valid inside function">,
   InGroup>;
 def warn_float_overflow : Warning<
-  "magnitude of floating-point constant too large for type %0; maximum is %1">,
+  "magnitude of floating-point literal too large for type %0; maximum is %1">,
InGroup;
 def warn_float_underflow : Warning<
-  "magnitude of floating-point constant too small for type %0; minimum is %1">,
+  "magnitude of floating-point literal too small for type %0; minimum is %1">,
   InGroup;
 def warn_double_const_requires_fp64 : Warning<
   "double precision constant requires %select{cl_khr_fp64|cl_khr_fp64 and 
__opencl_c_fp64}0, "


Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -113,10 +113,10 @@
   "predefined identifier is only valid inside function">,
   InGroup>;
 def warn_float_overflow : Warning<
-  "magnitude of floating-point constant too large for type %0; maximum is %1">,
+  "magnitude of floating-point literal too large for type %0; maximum is %1">,
InGroup;
 def warn_float_underflow : Warning<
-  "magnitude of floating-point constant too small for type %0; minimum is %1">,
+  "magnitude of floating-point literal too small for type %0; minimum is %1">,
   InGroup;
 def warn_double_const_requires_fp64 : Warning<
   "double precision constant requires %select{cl_khr_fp64|cl_khr_fp64 and __opencl_c_fp64}0, "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119405: [Clang][Sema] Use C++ standard terminology in clang diagnostics.

2022-02-10 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119405#3310695 , @aaron.ballman 
wrote:

> Thank you for the patch!
>
> I don't think this is an improvement; the diagnostic text goes from being 
> correct in C but odd in C++ to being correct in C++ but odd in C (the two 
> standards use different terminology). We're already inconsistent with which 
> we prefer (we have diagnostics that use `literal` and others that use 
> `constant`), and perhaps it'd make sense to start using 
> `%select{constant|literal}N` in the individual diagnostics to switch the 
> wording based on the current language mode. That said, I don't know that 
> there's a ton of value in that change (it seems unlikely that anyone is 
> actually confused what the diagnostic is saying today).

Thanks for spending your valuable time reviewing this! I think your words make 
sense. And I wonder if the patch is rejected, what should I do? I mean does 
phabricator have something like close PR in github?

> Also, this changes the text of a diagnostic but doesn't update any tests, so 
> precommit CI is failing. :-)

Well, I already run `ninja check-clang` locally to make sure it doesn't break 
anything, and I didn't find any tests are falling in the CI, so I guess maybe 
the CI is just not stable enough?

> Before changing things in this review, I think we should go back to the bug 
> report to find out why the request was made and what issues there are with 
> the diagnostic. If it's a matter of "wrong terminology in a language mode", 
> I'm of the opinion that's not really an issue in this particular case (unless 
> there's other confusion that's caused by the terminology). I'll start the 
> discussion there.

Good point! thanks for telling me about how the community works, I'm still 
learning :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119405

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: aaron.ballman.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds a missing test, covering the different kinds of floating-point
literals, like hexadecimal floats, and testing extreme cases & normal cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119609: [Clang][Sema] Don't act on ReturnStmt when parsing the lambda declarator.

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: aaron.ballman, rsmith.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang will try to act on ReturnStmt when parsing the lambda declarator,
which is not desirable. LambdaScopeInfo is nonnull doesn't the lambda has
been built, we should also check LambdaScopeInfo->Lambda.

Fixes #issue53488(https://github.com/llvm/llvm-project/issues/53488)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119609

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/returnstmt-in-lambda-declarator.cpp


Index: clang/test/Sema/returnstmt-in-lambda-declarator.cpp
===
--- /dev/null
+++ clang/test/Sema/returnstmt-in-lambda-declarator.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11
+
+void g() {
+  auto f = [](char c = ({ return 42; })) {}; // expected-error {{cannot 
initialize a parameter of type 'char' with an rvalue of type 'void'}} 
expected-note {{passing argument to parameter 'c' here}}
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3560,6 +3560,10 @@
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+
+  if (CurLambda && !CurLambda->Lambda)
+return StmtError();
+
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 


Index: clang/test/Sema/returnstmt-in-lambda-declarator.cpp
===
--- /dev/null
+++ clang/test/Sema/returnstmt-in-lambda-declarator.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11
+
+void g() {
+  auto f = [](char c = ({ return 42; })) {}; // expected-error {{cannot initialize a parameter of type 'char' with an rvalue of type 'void'}} expected-note {{passing argument to parameter 'c' here}}
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3560,6 +3560,10 @@
   CapturingScopeInfo *CurCap = cast(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast(CurCap);
+
+  if (CurLambda && !CurLambda->Lambda)
+return StmtError();
+
   bool HasDeducedReturnType =
   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408129.
junaire added a comment.

Add tests for long double.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 4.9E-325; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+long double ld2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld3 = 0x0.42p42; // no-warning
+
+long double ld4 = 0x0.42p-4200; // expected-warning {{magnitude of 
floating-point constant too small for type 'double'; minimum is 
4.9406564584124654E-324}}
+
+long double ld5 = 0x0.42p+4200; // expected-warning {{magnitude of 
floating-point constant too large for type 'double'; maximum is 
1.7976931348623157E+308}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 4.9E-325; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+long double ld2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld3 = 0x0.42p42; // no-warning
+
+long double ld4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+long double ld5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commit

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

> I think we should probably have test coverage for `long double` as well, but 
> I also wonder whether it makes sense to add coverage for the small 
> floating-point types (like `_Float16`) as well, or whether we already have 
> coverage for those elsewhere.

Test long double is fine for me. But I'm not really sure if we need to test for 
these half-precision floats, as they are part of clang language extension and 
not supported in all targets. IMHO, maybe we can just simply test these normal 
or standard floats first?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

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


[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408133.
junaire added a comment.

long double should use `L` as literal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+long double ld3 = 0x0.42p42;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+long double ld3 = 0x0.42p42;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
___
cf

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-11 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408134.
junaire added a comment.

Add missing blank.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L;  // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
___
cfe-commits mail

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 408407.
junaire added a comment.

Add triple info to avoid tests failure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L; // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L; // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119528#3318913 , @aaron.ballman 
wrote:

> In D119528#3316311 , @junaire wrote:
>
>>> I think we should probably have test coverage for `long double` as well, 
>>> but I also wonder whether it makes sense to add coverage for the small 
>>> floating-point types (like `_Float16`) as well, or whether we already have 
>>> coverage for those elsewhere.
>>
>> Test long double is fine for me. But I'm not really sure if we need to test 
>> for these half-precision floats, as they are part of clang language 
>> extension and not supported in all targets. IMHO, maybe we can just simply 
>> test these normal or standard floats first?
>
> I'm fine with that approach. Thanks for adding the `long double` support, but 
> it looks like the precommit CI spotted an issue:
>
>   FAIL: Clang :: Sema/warn-literal-range.c (12332 of 29830)
>    TEST 'Clang :: Sema/warn-literal-range.c' FAILED 
> 
>   Script:
>   --
>   : 'RUN: at line 1';   
> c:\ws\w32-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 
> -internal-isystem 
> c:\ws\w32-1\llvm-project\premerge-checks\build\lib\clang\15.0.0\include 
> -nostdsysteminc -std=c99 -verify 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c
>   --
>   Exit Code: 1
>   
>   Command Output (stdout):
>   --
>   $ ":" "RUN: at line 1"
>   $ "c:\ws\w32-1\llvm-project\premerge-checks\build\bin\clang.exe" "-cc1" 
> "-internal-isystem" 
> "c:\ws\w32-1\llvm-project\premerge-checks\build\lib\clang\15.0.0\include" 
> "-nostdsysteminc" "-std=c99" "-verify" 
> "C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c"
>   # command stderr:
>   error: 'warning' diagnostics expected but not seen: 
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 29: magnitude of floating-point constant too small for type 'long 
> double'; minimum is 3.64519953188247460253E-4951
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 31: magnitude of floating-point constant too large for type 'long 
> double'; maximum is 1.18973149535723176502E+4932
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 35: magnitude of floating-point constant too small for type 'long 
> double'; minimum is 3.64519953188247460253E-4951
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 37: magnitude of floating-point constant too large for type 'long 
> double'; maximum is 1.18973149535723176502E+4932
>   
>   error: 'warning' diagnostics seen but not expected: 
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 29: magnitude of floating-point constant too small for type 'long 
> double'; minimum is 4.9406564584124654E-324
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 31: magnitude of floating-point constant too large for type 'long 
> double'; maximum is 1.7976931348623157E+308
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 35: magnitude of floating-point constant too small for type 'long 
> double'; minimum is 4.9406564584124654E-324
>   
> File 
> C:\ws\w32-1\llvm-project\premerge-checks\clang\test\Sema\warn-literal-range.c 
> Line 37: magnitude of floating-point constant too large for type 'long 
> double'; maximum is 1.7976931348623157E+308
>   
>   8 errors generated.
>   
>   
>   error: command failed with exit status: 1
>   
>   --
>   
>   

Thanks for spending time looking at the CI issue, I thought it was something 
wrong with itself!

> You might need to add a target triple to the test to specify exactly which 
> target you are testing for. Bonus points if you pick a second target with 
> different range of values. You can do that with something like:
>
>   // RUN: %clang_cc1 -triple=whatever -std=c99 -verify=whatever %s
>   // RUN: %clang_cc1 -triple=whatever-else -std=c99 -verify=whatever-else %s
>   
>   long double ld5 = 0x0.42p+42000L; // whatever-warning {{magnitude of 
> floating-point constant too large for type 'long double'; maximum is 
> 1.18973149535723176502E+4932}} \
> 
> whatever-else-warning {{magnitude of floating-point constant too large for 
> type 'long double'; maximum is 12}} \
>
> (the identifier after `-verify=` is used in place of the `expected` in 
> diagnostic verification so you can vary which warnings are checked against 
> which RUN lines.)

Thanks for telling me these about the regression tests! But I have no LLVM 
development set up in Windows so I guess one triple test should be fine. Maybe 
I can use the info given by the CI

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Jun Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeffd6dd63a65: [Clang][Sema] Add a missing regression test 
about Wliteral-range (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

Files:
  clang/test/Sema/warn-literal-range.c


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point 
constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point 
constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point 
constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point 
constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L; // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of 
floating-point constant too small for type 'long double'; minimum is 
3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude of 
floating-point constant too large for type 'long double'; maximum is 
1.18973149535723176502E+4932}}


Index: clang/test/Sema/warn-literal-range.c
===
--- /dev/null
+++ clang/test/Sema/warn-literal-range.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c99 -verify %s
+
+float f0 = 0.42f; // no-warning
+
+float f1 = 1.4E-46f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f2 = 3.4E+39f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+float f3 = 0x4.2p42f; // no-warning
+
+float f4 = 0x0.42p-1000f; // expected-warning {{magnitude of floating-point constant too small for type 'float'; minimum is 1.40129846E-45}}
+
+float f5 = 0x0.42p+1000f; // expected-warning {{magnitude of floating-point constant too large for type 'float'; maximum is 3.40282347E+38}}
+
+double d0 = 0.42; // no-warning
+
+double d1 = 3.6E-4952; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d2 = 1.7E+309; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+double d3 = 0x0.42p42; // no-warning
+
+double d4 = 0x0.42p-4200; // expected-warning {{magnitude of floating-point constant too small for type 'double'; minimum is 4.9406564584124654E-324}}
+
+double d5 = 0x0.42p+4200; // expected-warning {{magnitude of floating-point constant too large for type 'double'; maximum is 1.7976931348623157E+308}}
+
+long double ld0 = 0.42L; // no-warning
+
+long double ld1 = 3.6E-4952L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld2 = 1.2E+4932L; // expected-warning {{magnitude of floating-point constant too large for type 'long double'; maximum is 1.18973149535723176502E+4932}}
+
+long double ld3 = 0x0.42p42L; // no-warning
+
+long double ld4 = 0x0.42p-42000L; // expected-warning {{magnitude of floating-point constant too small for type 'long double'; minimum is 3.64519953188247460253E-4951}}
+
+long double ld5 = 0x0.42p+42000L; // expected-warning {{magnitude

[PATCH] D119528: [Clang][Sema] Add a missing regression test about Wliteral-range

2022-02-14 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119528#3319955 , @aaron.ballman 
wrote:

> LGTM, thank you for the additional test coverage! Do you need me to commit on 
> your behalf? If so, what name and email address would you like me to use for 
> patch attribution?

Thanks but I can push it on my own ;^)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119528

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


[PATCH] D119949: [Clang-tidy] Check the existence of ElaboratedType's qualifiers

2022-02-16 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: aaron.ballman, alexfh.
Herald added subscribers: carlosgalvezp, xazax.hun.
junaire requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The ElaboratedType can have no qualifiers, so we should check it before
use.

Fix #issue53874(https://github.com/llvm/llvm-project/issues/53874)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119949

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
@@ -197,6 +197,15 @@
 
   h<4>();
 }
+struct SP {
+  static int I;
+} P;
+
+void usep() {
+  P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  struct SP::I;{{$}}
+}
 
 // Overloaded member access operator
 struct Q {
Index: 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -19,14 +19,15 @@
 
 static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
   if (const ElaboratedType *ElType = QType->getAs()) {
-const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier();
-unsigned NameSpecifierNestingLevel = 1;
-do {
-  NameSpecifierNestingLevel++;
-  NestedSpecifiers = NestedSpecifiers->getPrefix();
-} while (NestedSpecifiers);
-
-return NameSpecifierNestingLevel;
+if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
+  unsigned NameSpecifierNestingLevel = 1;
+  do {
+NameSpecifierNestingLevel++;
+NestedSpecifiers = NestedSpecifiers->getPrefix();
+  } while (NestedSpecifiers);
+
+  return NameSpecifierNestingLevel;
+}
   }
   return 0;
 }


Index: clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
@@ -197,6 +197,15 @@
 
   h<4>();
 }
+struct SP {
+  static int I;
+} P;
+
+void usep() {
+  P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  struct SP::I;{{$}}
+}
 
 // Overloaded member access operator
 struct Q {
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -19,14 +19,15 @@
 
 static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
   if (const ElaboratedType *ElType = QType->getAs()) {
-const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier();
-unsigned NameSpecifierNestingLevel = 1;
-do {
-  NameSpecifierNestingLevel++;
-  NestedSpecifiers = NestedSpecifiers->getPrefix();
-} while (NestedSpecifiers);
-
-return NameSpecifierNestingLevel;
+if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
+  unsigned NameSpecifierNestingLevel = 1;
+  do {
+NameSpecifierNestingLevel++;
+NestedSpecifiers = NestedSpecifiers->getPrefix();
+  } while (NestedSpecifiers);
+
+  return NameSpecifierNestingLevel;
+}
   }
   return 0;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119949: [Clang-tidy] Check the existence of ElaboratedType's qualifiers

2022-02-16 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D119949#3328254 , @cloudhan wrote:

> As the original bug reporter, I don't think this is a proper fix for it. 
> There seems to be some kind of bug deep in the frontend. This just hide it 
> anyway.

Yeah, maybe there's a deeper issue need to be dug into. I just found the code 
below doesn't work as well:

  namespace N {
  
  struct S{
  static int i;
  } s;
  }
  
  int main()
  {
  return N::s.i;
  }

Without this fix, clang-tidy will crash, but after applying this patch, 
clang-tidy gives the wrong fixhint:

  /home/jun/workground/demo.cpp:10:9: warning: static member accessed through 
instance [readability-static-accessed-through-instance]
  return N::s.i;
 ^
 struct S::
// should be N::S::

I will try to look into this issue, any comments about it are welcome :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119949

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


[PATCH] D119949: [Clang-tidy] Check the existence of ElaboratedType's qualifiers

2022-02-17 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 409510.
junaire added a comment.

- Only suppress canonical types when it's a TypedefNameType.
- Add more tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119949

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
@@ -198,6 +198,28 @@
   h<4>();
 }
 
+struct SP {
+  static int I;
+} P;
+
+void usep() {
+  P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  SP::I;{{$}}
+}
+
+namespace NSP {
+struct SP {
+  static int I;
+} P;
+} // namespace NSP
+
+void usensp() {
+  NSP::P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  NSP::SP::I;{{$}}
+}
+
 // Overloaded member access operator
 struct Q {
   static int K;
@@ -237,9 +259,9 @@
 
 namespace Outer {
   inline namespace Inline {
-struct S {
-  static int I;
-};
+  struct S {
+static int I;
+  };
   }
 }
 
Index: 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -19,14 +19,15 @@
 
 static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
   if (const ElaboratedType *ElType = QType->getAs()) {
-const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier();
-unsigned NameSpecifierNestingLevel = 1;
-do {
-  NameSpecifierNestingLevel++;
-  NestedSpecifiers = NestedSpecifiers->getPrefix();
-} while (NestedSpecifiers);
-
-return NameSpecifierNestingLevel;
+if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
+  unsigned NameSpecifierNestingLevel = 1;
+  do {
+NameSpecifierNestingLevel++;
+NestedSpecifiers = NestedSpecifiers->getPrefix();
+  } while (NestedSpecifiers);
+
+  return NameSpecifierNestingLevel;
+}
   }
   return 0;
 }
@@ -68,6 +69,11 @@
   PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
   PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
   PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
+
+  bool ShouldPrintCanonicalTy =
+  BaseExpr->getType()->isTypedefNameType() ? false : true;
+  PrintingPolicyWithSupressedTag.PrintCanonicalTypes = ShouldPrintCanonicalTy;
+
   std::string BaseTypeName =
   BaseType.getAsString(PrintingPolicyWithSupressedTag);
 


Index: clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
@@ -198,6 +198,28 @@
   h<4>();
 }
 
+struct SP {
+  static int I;
+} P;
+
+void usep() {
+  P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  SP::I;{{$}}
+}
+
+namespace NSP {
+struct SP {
+  static int I;
+} P;
+} // namespace NSP
+
+void usensp() {
+  NSP::P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  NSP::SP::I;{{$}}
+}
+
 // Overloaded member access operator
 struct Q {
   static int K;
@@ -237,9 +259,9 @@
 
 namespace Outer {
   inline namespace Inline {
-struct S {
-  static int I;
-};
+  struct S {
+static int I;
+  };
   }
 }
 
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -19,14 +19,15 @@
 
 static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
   if (const ElaboratedType *ElType = QType->getAs()) {
-const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier();
-unsigned NameSpecifierNestingLevel = 1;
-do {
-  NameSpecifierNestingLevel++;
-  NestedSpecifiers = NestedSpecifiers->getPrefix();
-} while (NestedSpecifiers);
-
-return NameSpecifierNestingLevel;
+if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
+  unsigned NameSpecifierNestingLevel

[PATCH] D119949: [Clang-tidy] Check the existence of ElaboratedType's qualifiers

2022-02-17 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 409511.
junaire added a comment.

Simplify code a little bit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119949

Files:
  
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
@@ -198,6 +198,28 @@
   h<4>();
 }
 
+struct SP {
+  static int I;
+} P;
+
+void usep() {
+  P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  SP::I;{{$}}
+}
+
+namespace NSP {
+struct SP {
+  static int I;
+} P;
+} // namespace NSP
+
+void usensp() {
+  NSP::P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  NSP::SP::I;{{$}}
+}
+
 // Overloaded member access operator
 struct Q {
   static int K;
@@ -237,9 +259,9 @@
 
 namespace Outer {
   inline namespace Inline {
-struct S {
-  static int I;
-};
+  struct S {
+static int I;
+  };
   }
 }
 
Index: 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ 
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -19,14 +19,15 @@
 
 static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
   if (const ElaboratedType *ElType = QType->getAs()) {
-const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier();
-unsigned NameSpecifierNestingLevel = 1;
-do {
-  NameSpecifierNestingLevel++;
-  NestedSpecifiers = NestedSpecifiers->getPrefix();
-} while (NestedSpecifiers);
-
-return NameSpecifierNestingLevel;
+if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
+  unsigned NameSpecifierNestingLevel = 1;
+  do {
+NameSpecifierNestingLevel++;
+NestedSpecifiers = NestedSpecifiers->getPrefix();
+  } while (NestedSpecifiers);
+
+  return NameSpecifierNestingLevel;
+}
   }
   return 0;
 }
@@ -68,6 +69,10 @@
   PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
   PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
   PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
+
+  PrintingPolicyWithSupressedTag.PrintCanonicalTypes =
+  BaseExpr->getType()->isTypedefNameType() ? false : true;
+
   std::string BaseTypeName =
   BaseType.getAsString(PrintingPolicyWithSupressedTag);
 


Index: clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-static-accessed-through-instance.cpp
@@ -198,6 +198,28 @@
   h<4>();
 }
 
+struct SP {
+  static int I;
+} P;
+
+void usep() {
+  P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  SP::I;{{$}}
+}
+
+namespace NSP {
+struct SP {
+  static int I;
+} P;
+} // namespace NSP
+
+void usensp() {
+  NSP::P.I;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
+  // CHECK-FIXES: {{^}}  NSP::SP::I;{{$}}
+}
+
 // Overloaded member access operator
 struct Q {
   static int K;
@@ -237,9 +259,9 @@
 
 namespace Outer {
   inline namespace Inline {
-struct S {
-  static int I;
-};
+  struct S {
+static int I;
+  };
   }
 }
 
Index: clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -19,14 +19,15 @@
 
 static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
   if (const ElaboratedType *ElType = QType->getAs()) {
-const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier();
-unsigned NameSpecifierNestingLevel = 1;
-do {
-  NameSpecifierNestingLevel++;
-  NestedSpecifiers = NestedSpecifiers->getPrefix();
-} while (NestedSpecifiers);
-
-return NameSpecifierNestingLevel;
+if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
+  unsigned NameSpecifierNestingLevel = 1;
+  do {
+NameSpecifierNestingLevel++;
+NestedSpecifiers = NestedSpecifiers->getPre

[PATCH] D124434: [Clang][Test] Run tests in C++14 mode explicitly.

2022-04-25 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: dblaikie, nikic, tstellar.
Herald added a subscriber: mstorsjo.
Herald added a project: All.
junaire requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Some tests are not specify their langauge standard but using the default
value (currently is C++14), but this will cause problems when we want to
raise the default C++ version to C++17 in the future if the behavior
changes. This patch mostly just add `-std=c++14` or `-std=gnu++14` in
the RUN line, hopefully, it will remove one of the obstacles to out progress.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124434

Files:
  clang/test/AST/ast-dump-openmp-begin-declare-variant_11.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_template_3.cpp
  clang/test/AST/ast-dump-undeduced-expr.cpp
  clang/test/AST/sourceranges.cpp
  clang/test/Analysis/blocks.m
  clang/test/CXX/basic/basic.stc/basic.stc.dynamic/p2.cpp
  clang/test/CXX/class.access/class.friend/p1.cpp
  clang/test/CXX/class/class.friend/p2.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.stc/p2.cpp
  clang/test/CXX/except/except.spec/p2-dynamic-types.cpp
  clang/test/CXX/except/except.spec/p9-dynamic.cpp
  clang/test/CXX/stmt.stmt/stmt.select/p3.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
  clang/test/CXX/temp/temp.res/temp.local/p3.cpp
  clang/test/CodeGen/typedef_alignment_mismatch_warning.cpp
  clang/test/CodeGenCXX/align-avx-complete-objects.cpp
  clang/test/CodeGenCXX/copy-constructor-elim-2.cpp
  clang/test/CodeGenCXX/debug-info-template-parameter.cpp
  clang/test/CodeGenCXX/debug-info-template-partial-specialization.cpp
  clang/test/CodeGenCXX/exception-spec-decay.cpp
  clang/test/CodeGenCXX/exceptions-cxx-ehsc.cpp
  clang/test/CodeGenCXX/exceptions-no-rtti.cpp
  clang/test/CodeGenCXX/global-init.cpp
  clang/test/CodeGenCXX/no-exceptions.cpp
  clang/test/CodeGenCXX/override-bit-field-layout.cpp
  clang/test/CodeGenCXX/override-layout.cpp
  clang/test/CodeGenCXX/reference-temporary-ms.cpp
  clang/test/CodeGenCXX/rtti-linkage.cpp
  clang/test/Layout/ms-x86-vtordisp.cpp
  clang/test/Modules/update-exception-spec.cpp
  clang/test/OpenMP/declare_mapper_messages.cpp
  clang/test/PCH/cxx-functions.cpp
  clang/test/Parser/cxx-casting.cpp
  clang/test/Parser/cxx-class.cpp
  clang/test/Parser/cxx-template-argument.cpp
  clang/test/Parser/cxx-template-decl.cpp
  clang/test/Parser/cxx1z-nested-namespace-definition.cpp
  clang/test/Sema/ms_class_layout.cpp
  clang/test/SemaCXX/MicrosoftExtensions.cpp
  clang/test/SemaCXX/PR12778.cpp
  clang/test/SemaCXX/altivec.cpp
  clang/test/SemaCXX/bool.cpp
  clang/test/SemaCXX/default2.cpp
  clang/test/SemaCXX/exception-spec-no-exceptions.cpp
  clang/test/SemaCXX/exceptions.cpp
  clang/test/SemaCXX/expressions.cpp
  clang/test/SemaCXX/inline.cpp
  clang/test/SemaCXX/libstdcxx_is_pod_hack.cpp
  clang/test/SemaCXX/linkage2.cpp
  clang/test/SemaCXX/member-pointer.cpp
  clang/test/SemaCXX/missing-namespace-qualifier-typo-corrections.cpp
  clang/test/SemaCXX/new-delete.cpp
  clang/test/SemaCXX/static-data-member.cpp
  clang/test/SemaCXX/type-definition-in-specifier.cpp
  clang/test/SemaCXX/user-defined-conversions.cpp
  clang/test/SemaCXX/warn-new-overaligned-3.cpp
  clang/test/SemaCXX/warn-new-overaligned.cpp
  clang/test/SemaCXX/writable-strings-deprecated.cpp
  clang/test/SemaSYCL/zero-length-arrays.cpp
  clang/test/SemaTemplate/class-template-id.cpp
  clang/test/SemaTemplate/constructor-template.cpp
  clang/test/SemaTemplate/explicit-instantiation.cpp
  clang/test/SemaTemplate/instantiate-exception-spec.cpp
  clang/test/SemaTemplate/instantiation-default-2.cpp
  clang/test/SemaTemplate/temp_arg.cpp
  clang/test/SemaTemplate/temp_arg_template.cpp
  clang/test/SemaTemplate/typename-specifier-3.cpp
  clang/unittests/AST/ASTTraverserTest.cpp

Index: clang/unittests/AST/ASTTraverserTest.cpp
===
--- clang/unittests/AST/ASTTraverserTest.cpp
+++ clang/unittests/AST/ASTTraverserTest.cpp
@@ -280,7 +280,7 @@
 
 TEST(Traverse, IgnoreUnlessSpelledInSourceVars) {
 
-  auto AST = buildASTFromCode(R"cpp(
+  auto AST = buildASTFromCodeWithArgs(R"cpp(
 
 struct String
 {
@@ -346,7 +346,8 @@
   }
 }
 
-)cpp");
+)cpp",
+  {"-std=c++14"});
 
   {
 auto FN =
@@ -715,7 +716,7 @@
 
 TEST(Traverse, IgnoreUnlessSpelledInSourceReturns) {
 
-  auto AST = buildASTFromCode(R"cpp(
+  auto AST = buildASTFromCodeWithArgs(R"cpp(
 
 struct A
 {
@@ -784,7 +785,8 @@
   return c;
 }
 
-)cpp");
+)cpp",
+  {"-std=c++14"});
 
   auto getFunctionNode = [&AST](const std::string &name) {
 auto BN = ast_matchers::match(functionDecl(hasName(name)).bind("fn"),
Index: clang/test/SemaTemplate/typename-specifier-3.cpp
===
--- cl

[PATCH] D123436: [Clang] Pass llvm::BitstreamCursor by reference. NFC

2022-04-26 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 425134.
junaire added a comment.

use std::move().

I'm not sure this will be better but hope it will make others happy :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

Files:
  clang/lib/Serialization/GlobalModuleIndex.cpp


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -277,7 +277,7 @@
   return std::make_pair(nullptr, Res.takeError());
   }
 
-  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), Cursor),
+  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), 
std::move(Cursor)),
 llvm::Error::success());
 }
 


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -277,7 +277,7 @@
   return std::make_pair(nullptr, Res.takeError());
   }
 
-  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), Cursor),
+  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), std::move(Cursor)),
 llvm::Error::success());
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123436: [Clang] Use std::move in GlobalModuleIndex::readIndex. NFC

2022-04-26 Thread Jun Zhang 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 rG218dcdad8a0c: [Clang] Use std::move in 
GlobalModuleIndex::readIndex. NFC (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

Files:
  clang/lib/Serialization/GlobalModuleIndex.cpp


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -277,7 +277,7 @@
   return std::make_pair(nullptr, Res.takeError());
   }
 
-  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), Cursor),
+  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), 
std::move(Cursor)),
 llvm::Error::success());
 }
 


Index: clang/lib/Serialization/GlobalModuleIndex.cpp
===
--- clang/lib/Serialization/GlobalModuleIndex.cpp
+++ clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -277,7 +277,7 @@
   return std::make_pair(nullptr, Res.takeError());
   }
 
-  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), Cursor),
+  return std::make_pair(new GlobalModuleIndex(std::move(Buffer), std::move(Cursor)),
 llvm::Error::success());
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123436: [Clang] Use std::move in GlobalModuleIndex::readIndex. NFC

2022-04-26 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D123436#3475002 , @dblaikie wrote:

> In D123436#3462567 , @dblaikie 
> wrote:
>
>> Perhaps GlobalModuleIndex should create the cursor itself - it's being 
>> handed the buffer anyway?
>
> Ping on this ^ - would this be a better direction that addresses the concerns?

Sorry about missing this! :(
However, I'm not sure that I understand your idea. Do you mean we can simply 
pass the buffer to the `GlobalModuleIndex` then we can construct the cursor in 
the constructor itself? IMHO, we can't. that's because we need to use the 
cursor to sniff for the signature of the buffer, and we will return an error if 
it is failed. Please let me know if I understand you wrong :)

/// The main bitstream cursor for the main block.
llvm::BitstreamCursor Cursor(*Buffer);
  
// Sniff for the signature.
for (unsigned char C : {'B', 'C', 'G', 'I'}) {
  if (Expected Res = Cursor.Read(8)) {
if (Res.get() != C)
  return std::make_pair(
  nullptr, llvm::createStringError(std::errc::illegal_byte_sequence,
   "expected signature BCGI"));
  } else
return std::make_pair(nullptr, Res.takeError());
}
  
return std::make_pair(new GlobalModuleIndex(std::move(Buffer), 
std::move(Cursor)),
  llvm::Error::success());
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123436

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


[PATCH] D124434: [Clang][Test] Run tests in C++14 mode explicitly.

2022-04-27 Thread Jun Zhang via Phabricator via cfe-commits
junaire planned changes to this revision.
junaire added a comment.

> In general, my concern with the this patch is that it loses test coverage by 
> specifying an explicit language mode. We typically prefer to fix the tests so 
> that they can work in any language mode (and perhaps add additional RUN lines 
> in the process to do so).

OK, I'll do this. But I guess it is not sort of trivial work and will take 
plenty of time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124434

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


[PATCH] D128782: [CodeGen] Keep track of decls that were deferred and have been emitted.

2022-07-13 Thread Jun Zhang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8082a0028638: [CodeGen] Keep track of decls that were 
deferred and have been emitted. (authored by junaire).

Changed prior to commit:
  https://reviews.llvm.org/D128782?vs=441667&id=444228#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128782

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/Interpreter/code-undo.cpp


Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -20,4 +20,9 @@
 auto r3 = printf("foo() = %d\n", foo());
 // CHECK-NEXT: foo() = 2
 
+inline int bar() { return 42;}
+auto r4 = bar();
+%undo
+auto r5 = bar();
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -344,6 +344,20 @@
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
+  }
+
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+if (!llvm::isa(GD.getDecl()))
+  return;
+llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1516,6 +1530,11 @@
 NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
 NewBuilder->TBAA = std::move(TBAA);
+
+assert(NewBuilder->EmittedDeferredDecls.empty() &&
+   "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
+NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
   }
 
 private:
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -445,6 +445,7 @@
 
 void CodeGenModule::clear() {
   DeferredDeclsToEmit.clear();
+  EmittedDeferredDecls.clear();
   if (OpenMPRuntime)
 OpenMPRuntime->clear();
 }
@@ -510,6 +511,9 @@
 
 void CodeGenModule::Release() {
   EmitDeferred();
+  DeferredDecls.insert(EmittedDeferredDecls.begin(),
+   EmittedDeferredDecls.end());
+  EmittedDeferredDecls.clear();
   EmitVTablesOpportunistically();
   applyGlobalValReplacements();
   applyReplacements();


Index: clang/test/Interpreter/code-undo.cpp
===
--- clang/test/Interpreter/code-undo.cpp
+++ clang/test/Interpreter/code-undo.cpp
@@ -20,4 +20,9 @@
 auto r3 = printf("foo() = %d\n", foo());
 // CHECK-NEXT: foo() = 2
 
+inline int bar() { return 42;}
+auto r4 = bar();
+%undo
+auto r5 = bar();
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -344,6 +344,20 @@
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
+  }
+
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+if (!llvm::isa(GD.getDecl()))
+  return;
+llvm::GlobalVariable::LinkageTypes L = getFunctionLinkage(GD);
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1516,6 +1530,11 @@
 NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
 NewBuilder->TBAA = std::move(TBAA);
+
+assert(NewBuilder->EmittedDeferredDecls.empty() &&
+   "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
+NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
   }
 
 private:
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -445,6 +445,7 @@
 
 void CodeGenModule::clear() {
   DeferredDeclsToEmit.clear();
+  EmittedDeferredDecls.clear();
   if (OpenMPRuntime)
 OpenMPRuntime->clear();
 }
@@ -510,6 +511,9 @@
 
 void CodeGenModule::Release() {
   EmitDeferred();
+  DeferredDecls.insert(EmittedDeferredDecls.begin(),
+   EmittedDeferredDecls.end());
+  

[PATCH] D130420: [CodeGen] Consider MangleCtx when move lazy emission States

2022-07-23 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: v.g.vassilev.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Also move MangleCtx when moving some lazy emission states in
CodeGenModule. Without this patch clang-repl hits an invalid address
access when passing `-Xcc -O2` flag.

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130420

Files:
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -5,6 +5,7 @@
 // UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7000,4 +7000,6 @@
  "Still have (unmerged) EmittedDeferredDecls deferred decls");
 
   NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
+
+  NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }
Index: clang/lib/CodeGen/CGCXXABI.h
===
--- clang/lib/CodeGen/CGCXXABI.h
+++ clang/lib/CodeGen/CGCXXABI.h
@@ -41,6 +41,8 @@
 
 /// Implements C++ ABI-specific code generation functions.
 class CGCXXABI {
+  friend class CodeGenModule;
+
 protected:
   CodeGenModule &CGM;
   std::unique_ptr MangleCtx;


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -5,6 +5,7 @@
 // UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7000,4 +7000,6 @@
  "Still have (unmerged) EmittedDeferredDecls deferred decls");
 
   NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
+
+  NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }
Index: clang/lib/CodeGen/CGCXXABI.h
===
--- clang/lib/CodeGen/CGCXXABI.h
+++ clang/lib/CodeGen/CGCXXABI.h
@@ -41,6 +41,8 @@
 
 /// Implements C++ ABI-specific code generation functions.
 class CGCXXABI {
+  friend class CodeGenModule;
+
 protected:
   CodeGenModule &CGM;
   std::unique_ptr MangleCtx;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130422: [clang-repl] Fix incorrect return code

2022-07-23 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added a reviewer: v.g.vassilev.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Without this patch, clang-repl incorrectly pass some tests when there's
error occured.

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130422

Files:
  clang/test/Interpreter/fail.cpp
  clang/tools/clang-repl/ClangRepl.cpp


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -105,6 +105,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -112,13 +114,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp->Undo()) {
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+  HasError = true;
+}
 continue;
   }
 
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+HasError = true;
+  }
 }
   }
 
@@ -129,5 +135,5 @@
 
   llvm::llvm_shutdown();
 
-  return checkDiagErrors(Interp->getCompilerInstance());
+  return checkDiagErrors(Interp->getCompilerInstance(), HasError);
 }
Index: clang/test/Interpreter/fail.cpp
===
--- /dev/null
+++ clang/test/Interpreter/fail.cpp
@@ -0,0 +1,14 @@
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// XFAIL: *
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+BOOM!
+extern "C" int printf(const char *, ...);
+int i = 42;
+auto r1 = printf("i = %d\n", i);
+// CHECK: i = 42
+%quit


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -105,6 +105,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -112,13 +114,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp->Undo()) {
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+  HasError = true;
+}
 continue;
   }
 
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+HasError = true;
+  }
 }
   }
 
@@ -129,5 +135,5 

[PATCH] D130422: [clang-repl] Fix incorrect return code

2022-07-23 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 447103.
junaire added a comment.

Use `not`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130422

Files:
  clang/test/Interpreter/fail.cpp
  clang/tools/clang-repl/ClangRepl.cpp


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -105,6 +105,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -112,13 +114,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp->Undo()) {
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+  HasError = true;
+}
 continue;
   }
 
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+HasError = true;
+  }
 }
   }
 
@@ -129,5 +135,5 @@
 
   llvm::llvm_shutdown();
 
-  return checkDiagErrors(Interp->getCompilerInstance());
+  return checkDiagErrors(Interp->getCompilerInstance(), HasError);
 }
Index: clang/test/Interpreter/fail.cpp
===
--- /dev/null
+++ clang/test/Interpreter/fail.cpp
@@ -0,0 +1,13 @@
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | not clang-repl | FileCheck %s
+BOOM!
+extern "C" int printf(const char *, ...);
+int i = 42;
+auto r1 = printf("i = %d\n", i);
+// CHECK: i = 42
+%quit


Index: clang/tools/clang-repl/ClangRepl.cpp
===
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
 
 // If we are running with -verify a reported has to be returned as unsuccess.
 // This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
   unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
   if (CI->getDiagnosticOpts().VerifyDiagnostics) {
 // If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
 // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
 Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
   }
-  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+  return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
 }
 
 llvm::ExitOnError ExitOnErr;
@@ -105,6 +105,8 @@
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
   }
 
+  bool HasError = false;
+
   if (OptInputs.empty()) {
 llvm::LineEditor LE("clang-repl");
 // FIXME: Add LE.setListCompleter
@@ -112,13 +114,17 @@
   if (*Line == R"(%quit)")
 break;
   if (*Line == R"(%undo)") {
-if (auto Err = Interp->Undo())
+if (auto Err = Interp->Undo()) {
   llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+  HasError = true;
+}
 continue;
   }
 
-  if (auto Err = Interp->ParseAndExecute(*Line))
+  if (auto Err = Interp->ParseAndExecute(*Line)) {
 llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+HasError = true;
+  }
 }
   }
 
@@ -129,5 +135,5 @@
 
   llvm::llvm_shutdown();
 
-  return checkDiagErrors(Interp->getCompilerInstance());
+  return checkDiagErrors(Interp->getCompilerInstance(), HasError);
 }
Index: clang/test/Interpret

[PATCH] D130420: [CodeGen] Consider MangleCtx when move lazy emission States

2022-07-25 Thread Jun Zhang 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 rG58c94808450d: [CodeGen] Consider MangleCtx when move lazy 
emission States (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130420

Files:
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -5,6 +5,7 @@
 // UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7000,4 +7000,6 @@
  "Still have (unmerged) EmittedDeferredDecls deferred decls");
 
   NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
+
+  NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }
Index: clang/lib/CodeGen/CGCXXABI.h
===
--- clang/lib/CodeGen/CGCXXABI.h
+++ clang/lib/CodeGen/CGCXXABI.h
@@ -41,6 +41,8 @@
 
 /// Implements C++ ABI-specific code generation functions.
 class CGCXXABI {
+  friend class CodeGenModule;
+
 protected:
   CodeGenModule &CGM;
   std::unique_ptr MangleCtx;


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -5,6 +5,7 @@
 // UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7000,4 +7000,6 @@
  "Still have (unmerged) EmittedDeferredDecls deferred decls");
 
   NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
+
+  NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }
Index: clang/lib/CodeGen/CGCXXABI.h
===
--- clang/lib/CodeGen/CGCXXABI.h
+++ clang/lib/CodeGen/CGCXXABI.h
@@ -41,6 +41,8 @@
 
 /// Implements C++ ABI-specific code generation functions.
 class CGCXXABI {
+  friend class CodeGenModule;
+
 protected:
   CodeGenModule &CGM;
   std::unique_ptr MangleCtx;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114688: [Clang] Add __builtin_elementwise_ceil

2021-11-28 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
junaire added reviewers: fhahn, aaron.ballman, scanon, craig.topper.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch implements one of the missing builtin functions specified in 
https://reviews.llvm.org/D111529


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114688

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -36,3 +36,10 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_ceil() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -135,3 +135,24 @@
   c1 = __builtin_elementwise_min(c1, c2);
   // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
 }
+
+void test_builtin_elementwise_ceil(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_ceil(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_ceil();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_ceil(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_ceil(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_ceil(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_ceil(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -189,3 +189,20 @@
   // CHECK-NEXT: call i32 @llvm.smin.i32(i32 [[IAS1]], i32 [[B]])
   int_as_one = __builtin_elementwise_min(int_as_one, b);
 }
+
+void test_builtin_elementwise_ceil(float f1, float f2, double d1, double d2,
+   float4 vf1, float4 vf2, si8 vi1, si8 vi2,
+   long long int i1, long long int i2, short si) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_ceil(
+  // CHECK:  [[F1:%.+]] = load float, float* %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.ceil.f32(float [[F1]])
+  f2 = __builtin_elementwise_ceil(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, double* %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.ceil.f64(double [[D1]])
+  d2 = __builtin_elementwise_ceil(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, <4 x float>* %vf1.addr, align 16
+  // CHECK-NEXT: call <4 x float> @llvm.ceil.v4f32(<4 x float> [[VF1]])
+  vf2 = __builtin_elementwise_ceil(vf1);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2102,6 +2102,11 @@
 if (SemaBuiltinElementwiseMathOneArg(TheCall))
   return ExprError();
 break;
+  case Builtin::BI__builtin_elementwise_ceil:
+if (SemaBuiltinElementwiseMathFloatArg(TheCall))
+  return ExprError();
+break;
+
   case Builtin::BI__builtin_elementwise_min:
   case Builtin::BI__builtin_elementwise_max:
 if (SemaBuiltinElementwiseMath(TheCall))
@@ -16713,6 +16718,31 @@
   return false;
 }
 
+bool Sema::SemaBuiltinElementwiseMathFloatArg(CallExpr *TheCall) {
+  if (checkArgCount(*this, TheCall, 1))
+return true;
+
+  ExprResult A = UsualUnaryConversions(TheCall->getArg(0));
+  SourceLocation ArgLoc = TheCall->getArg(0)->getBeginLoc();
+  if (A.isInvalid())
+return true;
+
+  TheCall->setArg(0, A.get());
+  QualType TyA = A.get()->getType();
+  if (checkMathBuiltinElementType(*this, ArgLoc, TyA))
+return true;
+
+  QualType EltTy = TyA;
+  if (auto *VecTy = EltTy->getAs())
+EltTy = VecTy->getElementType();
+  if (EltTy->isUnsignedIntegerType() || EltTy->isInteger

[PATCH] D114688: [Clang] Add __builtin_elementwise_ceil

2021-11-30 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 390912.
junaire added a comment.

Reuse existing code.


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

https://reviews.llvm.org/D114688

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -36,3 +36,10 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_ceil() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -135,3 +135,24 @@
   c1 = __builtin_elementwise_min(c1, c2);
   // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
 }
+
+void test_builtin_elementwise_ceil(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_ceil(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_ceil();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_ceil(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_ceil(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_ceil(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_ceil(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -189,3 +189,20 @@
   // CHECK-NEXT: call i32 @llvm.smin.i32(i32 [[IAS1]], i32 [[B]])
   int_as_one = __builtin_elementwise_min(int_as_one, b);
 }
+
+void test_builtin_elementwise_ceil(float f1, float f2, double d1, double d2,
+   float4 vf1, float4 vf2, si8 vi1, si8 vi2,
+   long long int i1, long long int i2, short si) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_ceil(
+  // CHECK:  [[F1:%.+]] = load float, float* %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.ceil.f32(float [[F1]])
+  f2 = __builtin_elementwise_ceil(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, double* %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.ceil.f64(double [[D1]])
+  d2 = __builtin_elementwise_ceil(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, <4 x float>* %vf1.addr, align 16
+  // CHECK-NEXT: call <4 x float> @llvm.ceil.v4f32(<4 x float> [[VF1]])
+  vf2 = __builtin_elementwise_ceil(vf1);
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2099,9 +2099,14 @@
   }
 
   case Builtin::BI__builtin_elementwise_abs:
-if (SemaBuiltinElementwiseMathOneArg(TheCall))
+if (SemaBuiltinElementwiseMathNotUnsignedArg(TheCall))
   return ExprError();
 break;
+  case Builtin::BI__builtin_elementwise_ceil:
+if (SemaBuiltinElementwiseMathFloatArg(TheCall))
+  return ExprError();
+break;
+
   case Builtin::BI__builtin_elementwise_min:
   case Builtin::BI__builtin_elementwise_max:
 if (SemaBuiltinElementwiseMath(TheCall))
@@ -16702,9 +16707,22 @@
   if (checkMathBuiltinElementType(*this, ArgLoc, TyA))
 return true;
 
+  return false;
+}
+
+bool Sema::SemaBuiltinElementwiseMathNotUnsignedArg(CallExpr *TheCall) {
+  if (SemaBuiltinElementwiseMathOneArg(TheCall))
+return true;
+
+  ExprResult A = UsualUnaryConversions(TheCall->getArg(0));
+  QualType TyA = A.get()->getType();
+
+  SourceLocation ArgLoc = TheCall->getArg(0)->getBeginLoc();
   QualType EltTy = TyA;
-  if (auto *VecTy = EltTy->getAs())
+
+  if (auto *VecTy = EltTy->getAs()) {
 EltTy = VecTy->getElementType();
+  }
   if (EltTy->isUnsignedIntegerType())
 return Diag(ArgLoc, diag::err_builtin_invalid_arg_type)
<< 1 << /*signed integer or float ty*/ 3 <<

  1   2   3   4   >