[clang] 1089cdd - Revert "Driver: Don't warn on -mbranch-protection when linking"

2022-03-22 Thread Tom Stellard via cfe-commits

Author: Tom Stellard
Date: 2022-03-22T23:36:57-07:00
New Revision: 1089cdda776bbd437d6507242f2621ec83af7118

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

LOG: Revert "Driver: Don't warn on -mbranch-protection when linking"

This reverts commit 98fd3b359866f474ab1c097c22fb5c3be356b996.

This patch broke multiple bots.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/aarch64-security-options.c

Removed: 
clang/test/Driver/Inputs/main.c



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e35b36af91c33..2a23695c149fa 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3442,7 +3442,6 @@ def msign_return_address_EQ : Joined<["-"], 
"msign-return-address=">,
   Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
-  Group,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,

diff  --git a/clang/test/Driver/Inputs/main.c b/clang/test/Driver/Inputs/main.c
deleted file mode 100644
index 5c2fa9bb6a78e..0
--- a/clang/test/Driver/Inputs/main.c
+++ /dev/null
@@ -1,3 +0,0 @@
-int main(int argc, char **argv) {
-  return 0;
-}

diff  --git a/clang/test/Driver/aarch64-security-options.c 
b/clang/test/Driver/aarch64-security-options.c
index e9db540d53ede..6ea4b8ae58385 100644
--- a/clang/test/Driver/aarch64-security-options.c
+++ b/clang/test/Driver/aarch64-security-options.c
@@ -27,10 +27,6 @@
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar   
  2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
-// RUN: %clang -target aarch64--none-eabi -o %t-main.o 
-mbranch-protection=standard -c %S/Inputs/main.c
-// RUN: %clang -target aarch64--none-eabi -o %t-main 
-mbranch-protection=standard %t-main.o 2>&1 | \
-// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
-
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 
'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -50,7 +46,3 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in 
'-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in 
'-mbranch-protection={{.*}}'
-
-// Check that the linker driver doesn't warn about -mbranch-protection=standard
-// as an unused option.
-// LINKER-DRIVER-NOT: warning:



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


[PATCH] D121201: [clang] Merge the SourceRange into ParsedAttributes

2022-03-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 417509.

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

https://reviews.llvm.org/D121201

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaOpenCL/address-spaces.cl

Index: clang/test/SemaOpenCL/address-spaces.cl
===
--- clang/test/SemaOpenCL/address-spaces.cl
+++ clang/test/SemaOpenCL/address-spaces.cl
@@ -258,7 +258,7 @@
 
 void func_multiple_addr2(void) {
   typedef __private int private_int_t;
-  __private __attribute__((opencl_global)) int var1;   // expected-error {{multiple address spaces specified for type}} \
+  __attribute__((opencl_global)) __private int var1;   // expected-error {{multiple address spaces specified for type}} \
// expected-error {{function scope variable cannot be declared in global address space}}
   __private __attribute__((opencl_global)) int *var2;  // expected-error {{multiple address spaces specified for type}}
   __attribute__((opencl_global)) private_int_t var3;   // expected-error {{multiple address spaces specified for type}}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -368,7 +368,8 @@
 };
 
 static void processTypeAttrs(TypeProcessingState &state, QualType &type,
- TypeAttrLocation TAL, ParsedAttributesView &attrs);
+ TypeAttrLocation TAL,
+ const ParsedAttributesView &attrs);
 
 static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
QualType &type);
@@ -8138,7 +8139,12 @@
 
 static void processTypeAttrs(TypeProcessingState &state, QualType &type,
  TypeAttrLocation TAL,
- ParsedAttributesView &attrs) {
+ const ParsedAttributesView &attrs) {
+
+  state.setParsedNoDeref(false);
+  if (attrs.empty())
+return;
+
   // Scan through and apply attributes to this type where it makes sense.  Some
   // attributes (such as __address_space__, __vector_size__, etc) apply to the
   // type, but others can be present in the type specifiers even though they
@@ -8148,9 +8154,6 @@
   // sure we visit every element once. Copy the attributes list, and iterate
   // over that.
   ParsedAttributesView AttrsCopy{attrs};
-
-  state.setParsedNoDeref(false);
-
   for (ParsedAttr &attr : AttrsCopy) {
 
 // Skip attributes that were marked to be invalid.
Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -495,8 +495,7 @@
   }
 }
 
-void Sema::ProcessStmtAttributes(Stmt *S,
- const ParsedAttributesWithRange &InAttrs,
+void Sema::ProcessStmtAttributes(Stmt *S, const ParsedAttributes &InAttrs,
  SmallVectorImpl &OutAttrs) {
   for (const ParsedAttr &AL : InAttrs) {
 if (const Attr *A = ProcessStmtAttribute(*this, S, AL, InAttrs.Range))
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -587,7 +587,7 @@
   return AttributedStmt::Create(Context, AttrsLoc, Attrs, SubStmt);
 }
 
-StmtResult Sema::ActOnAttributedStmt(const ParsedAttributesWithRange &Attrs,
+StmtResult Sema::ActOnAttributedStmt(const ParsedAttributes &Attrs,
  Stmt *SubStmt) {
   SmallVector SemanticAttrs;
   ProcessStmtAttributes(SubStmt, Attrs, SemanticAttrs);
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -2615,12 +2615,11 @@
 /// example:
 ///class foo : public bar, virtual private baz {
 /// 'public bar' and 'virtual private baz' are each base-specifiers.
-BaseResult
-Sema::ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange,
- ParsedAttributes &Attributes,
- bool Virtual, AccessSpecifier Access,
-

[PATCH] D121983: Driver: Don't warn on -mbranch-protection when linking

2022-03-22 Thread Tom Stellard 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 rG98fd3b359866: Driver: Don't warn on -mbranch-protection 
when linking (authored by tstellar).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121983

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/Inputs/main.c
  clang/test/Driver/aarch64-security-options.c


Index: clang/test/Driver/aarch64-security-options.c
===
--- clang/test/Driver/aarch64-security-options.c
+++ clang/test/Driver/aarch64-security-options.c
@@ -27,6 +27,10 @@
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar   
  2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
+// RUN: %clang -target aarch64--none-eabi -o %t-main.o 
-mbranch-protection=standard -c %S/Inputs/main.c
+// RUN: %clang -target aarch64--none-eabi -o %t-main 
-mbranch-protection=standard %t-main.o 2>&1 | \
+// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
+
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 
'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -46,3 +50,7 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in 
'-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in 
'-mbranch-protection={{.*}}'
+
+// Check that the linker driver doesn't warn about -mbranch-protection=standard
+// as an unused option.
+// LINKER-DRIVER-NOT: warning:
Index: clang/test/Driver/Inputs/main.c
===
--- /dev/null
+++ clang/test/Driver/Inputs/main.c
@@ -0,0 +1,3 @@
+int main(int argc, char **argv) {
+  return 0;
+}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3442,6 +3442,7 @@
   Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
+  Group,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,


Index: clang/test/Driver/aarch64-security-options.c
===
--- clang/test/Driver/aarch64-security-options.c
+++ clang/test/Driver/aarch64-security-options.c
@@ -27,6 +27,10 @@
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar 2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
+// RUN: %clang -target aarch64--none-eabi -o %t-main.o -mbranch-protection=standard -c %S/Inputs/main.c
+// RUN: %clang -target aarch64--none-eabi -o %t-main -mbranch-protection=standard %t-main.o 2>&1 | \
+// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
+
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -46,3 +50,7 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in '-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in '-mbranch-protection={{.*}}'
+
+// Check that the linker driver doesn't warn about -mbranch-protection=standard
+// as an unused option.
+// LINKER-DRIVER-NOT: warning:
Index: clang/test/Driver/Inputs/main.c
===
--- /dev/null
+++ clang/test/Driver/Inputs/main.c
@@ -0,0 +1,3 @@
+int main(int argc, char **argv) {
+  return 0;
+}
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3442,6 +3442,7 @@
   Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
+  Group,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 98fd3b3 - Driver: Don't warn on -mbranch-protection when linking

2022-03-22 Thread Tom Stellard via cfe-commits

Author: Tom Stellard
Date: 2022-03-22T23:17:42-07:00
New Revision: 98fd3b359866f474ab1c097c22fb5c3be356b996

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

LOG: Driver: Don't warn on -mbranch-protection when linking

The -mbranch-protection definition in Options.td was not given a Group,
so this was causing clang to emit a -Wunused-command-line-argument
warning when this flag was passed to the linker driver.  This was a
problem, because some build systems, like cmake, automatically pass the
C flags to the linker.  Therefore, any program that was compiled with
-Werror and -mbranch-protection would fail to link with the error:

argument unused during compilation: '-mbranch-protection=standard' 
[-Werror,-Wunused-command-line-argument]

Reviewed By: vhscampos

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

Added: 
clang/test/Driver/Inputs/main.c

Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/aarch64-security-options.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2a23695c149fa..e35b36af91c33 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3442,6 +3442,7 @@ def msign_return_address_EQ : Joined<["-"], 
"msign-return-address=">,
   Flags<[CC1Option]>, Group, Values<"none,all,non-leaf">,
   HelpText<"Select return address signing scope">;
 def mbranch_protection_EQ : Joined<["-"], "mbranch-protection=">,
+  Group,
   HelpText<"Enforce targets of indirect branches and function returns">;
 
 def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,

diff  --git a/clang/test/Driver/Inputs/main.c b/clang/test/Driver/Inputs/main.c
new file mode 100644
index 0..5c2fa9bb6a78e
--- /dev/null
+++ b/clang/test/Driver/Inputs/main.c
@@ -0,0 +1,3 @@
+int main(int argc, char **argv) {
+  return 0;
+}

diff  --git a/clang/test/Driver/aarch64-security-options.c 
b/clang/test/Driver/aarch64-security-options.c
index 6ea4b8ae58385..e9db540d53ede 100644
--- a/clang/test/Driver/aarch64-security-options.c
+++ b/clang/test/Driver/aarch64-security-options.c
@@ -27,6 +27,10 @@
 // RUN: %clang -target aarch64--none-eabi -c %s -### -mbranch-protection=bar   
  2>&1 | \
 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION --check-prefix=WARN
 
+// RUN: %clang -target aarch64--none-eabi -o %t-main.o 
-mbranch-protection=standard -c %S/Inputs/main.c
+// RUN: %clang -target aarch64--none-eabi -o %t-main 
-mbranch-protection=standard %t-main.o 2>&1 | \
+// RUN: FileCheck --allow-empty %s --check-prefix=LINKER-DRIVER
+
 // WARN-NOT: warning: ignoring '-mbranch-protection=' option because the 
'aarch64' architecture does not support it [-Wbranch-protection]
 
 // RA-OFF: "-msign-return-address=none"
@@ -46,3 +50,7 @@
 
 // BAD-B-KEY-COMBINATION: invalid branch protection option 'b-key' in 
'-mbranch-protection={{.*}}'
 // BAD-LEAF-COMBINATION: invalid branch protection option 'leaf' in 
'-mbranch-protection={{.*}}'
+
+// Check that the linker driver doesn't warn about -mbranch-protection=standard
+// as an unused option.
+// LINKER-DRIVER-NOT: warning:



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


[PATCH] D122249: [Clang] Add a compatibiliy warning for non-literals in constexpr.

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/SemaCXX/constant-expression-cxx2b.cpp:219
+  NonLiteral n; // cxx2b-note {{non-literal type 'NonLiteral' cannot be 
used in a constant expression}} \
+// cxx2b-warning {{definition of a variable of non-literal 
type in a constexpr function is incompatible with C++ standards before C++2b}}
 return 0;

Not sure how much we want the message in this case. The lambda is not marked 
`constexpr` (although it is implicitly `constexpr` in C++2b).

Note that we don't get a message for this:
```
auto qq = [] { return 0; static int x = 42; };
constexpr int qx = qq();
```

I am not sure how difficult it would be to come at this from the 
used-in-constant-evaluation side, but there is probably a larger class of 
messages in the same situation (so it would probably be a separate endeavour).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122249

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


[PATCH] D122249: [Clang] Add a compatibiliy warning for non-literals in constexpr.

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:1905
+if (SemaRef.LangOpts.CPlusPlus2b) {
+  if (!VD->getType()->isLiteralType(SemaRef.Context))
+SemaRef.Diag(VD->getLocation(),

This seems to trigger even when the type is dependent:
```
:1:36: warning: definition of a variable of non-literal type in a 
constexpr function is incompatible with C++ standards before C++2b 
[-Wpre-c++2b-compat]
auto qq = [](auto x) { decltype(x) n; };
   ^
1 warning generated.
```

This also seems to emit even when `Kind` is not 
`Sema::CheckConstexprKind::Diagnose` (unlike the `static`/`thread_local` case 
above). Is the `CheckLiteralType` logic not reusable for this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122249

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


[PATCH] D115248: [Clang] Fix PR28101

2022-03-22 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 417504.
rZhBoYao set the repository for this revision to rG LLVM Github Monorepo.
rZhBoYao added a comment.

Diagnose "same name as its class" before setting the declarator invalid as 
otherwise it would not be diagnosed. This also aligns with gcc's behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115248

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/PR28101.cpp


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template  struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template  struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template  struct S {};
+
+template  struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U> class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template 
arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+template  struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,9 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  if (cast(CurContext)->getDeclName() == Name)
+Diag(Loc, diag::err_member_name_of_class) << Name;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template  struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template  struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template  struct S {};
+
+template  struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U> class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}\
+  // expected-error{{member 'A' has the same name as its class}}
+};
+
+template  struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,9 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  if (cast(CurContext)->getDeclName() == Name)
+Diag(Loc, diag::err_member_name_of_class) << Name;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122104: [X86][regcall] Support passing / returning structures

2022-03-22 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei updated this revision to Diff 417502.
pengfei added a comment.

clang-formatted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122104

Files:
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aarch64-neon-tbl.c
  clang/test/CodeGen/regcall2.c

Index: clang/test/CodeGen/regcall2.c
===
--- /dev/null
+++ clang/test/CodeGen/regcall2.c
@@ -0,0 +1,28 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -target-feature +avx512vl -triple=x86_64-pc-win32 | FileCheck %s --check-prefix=Win
+// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -target-feature +avx512vl -triple=x86_64-pc-linux-gnu | FileCheck %s --check-prefix=Lin
+
+#include 
+
+typedef struct {
+  __m512d r1[4];
+  __m512 r2[4];
+} __sVector;
+__sVector A;
+
+__sVector __regcall foo(int a) {
+  return A;
+}
+
+double __regcall bar(__sVector a) {
+  return a.r1[0][4];
+}
+
+// FIXME: Do we need to change for Windows?
+// Win: define dso_local x86_regcallcc void @__regcall3__foo(%struct.__sVector* noalias sret(%struct.__sVector) align 64 %agg.result, i32 noundef %a) #0
+// Win: define dso_local x86_regcallcc double @__regcall3__bar(%struct.__sVector* noundef %a) #0
+// Win: attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-builtins" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+avx,+avx2,+avx512f,+avx512vl,+crc32,+cx8,+f16c,+fma,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" }
+
+// Lin: define dso_local x86_regcallcc %struct.__sVector @__regcall3__foo(i32 noundef %a) #0
+// Lin: define dso_local x86_regcallcc double @__regcall3__bar([4 x <8 x double>] %a.coerce0, [4 x <16 x float>] %a.coerce1) #0
+// Lin: attributes #0 = { noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="512" "no-builtins" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+avx,+avx2,+avx512f,+avx512vl,+crc32,+cx8,+f16c,+fma,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave" }
Index: clang/test/CodeGen/aarch64-neon-tbl.c
===
--- clang/test/CodeGen/aarch64-neon-tbl.c
+++ clang/test/CodeGen/aarch64-neon-tbl.c
@@ -42,7 +42,7 @@
   return vtbl2_s8(a, b);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl2_s8([2 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl2_s8([2 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #1 {
 // CHECK:   [[__P0_I:%.*]] = alloca %struct.int8x16x2_t, align 16
 // CHECK:   [[A:%.*]] = alloca %struct.int8x16x2_t, align 16
 // CHECK:   [[COERCE_DIVE:%.*]] = getelementptr inbounds %struct.int8x16x2_t, %struct.int8x16x2_t* [[A]], i32 0, i32 0
@@ -89,7 +89,7 @@
   return vtbl3_s8(a, b);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl3_s8([3 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl3_s8([3 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #1 {
 // CHECK:   [[__P0_I:%.*]] = alloca %struct.int8x16x3_t, align 16
 // CHECK:   [[A:%.*]] = alloca %struct.int8x16x3_t, align 16
 // CHECK:   [[COERCE_DIVE:%.*]] = getelementptr inbounds %struct.int8x16x3_t, %struct.int8x16x3_t* [[A]], i32 0, i32 0
@@ -142,7 +142,7 @@
   return vtbl4_s8(a, b);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl4_s8([4 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbl4_s8([4 x <16 x i8>] %a.coerce, <8 x i8> noundef %b) #1 {
 // CHECK:   [[__P0_I:%.*]] = alloca %struct.int8x16x4_t, align 16
 // CHECK:   [[A:%.*]] = alloca %struct.int8x16x4_t, align 16
 // CHECK:   [[COERCE_DIVE:%.*]] = getelementptr inbounds %struct.int8x16x4_t, %struct.int8x16x4_t* [[A]], i32 0, i32 0
@@ -352,7 +352,7 @@
   return vqtbx1_s8(a, b, c);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbx2_s8(<8 x i8> noundef %a, [2 x <16 x i8>] %b.coerce, <8 x i8> noundef %c) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbx2_s8(<8 x i8> noundef %a, [2 x <16 x i8>] %b.coerce, <8 x i8> noundef %c) #1 {
 // CHECK:   [[__P1_I:%.*]] = alloca %struct.int8x16x2_t, align 16
 // CHECK:   [[B:%.*]] = alloca %struct.int8x16x2_t, align 16
 // CHECK:   [[COERCE_DIVE:%.*]] = getelementptr inbounds %struct.int8x16x2_t, %struct.int8x16x2_t* [[B]], i32 0, i32 0
@@ -373,7 +373,7 @@
   return vqtbx2_s8(a, b, c);
 }
 
-// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbx3_s8(<8 x i8> noundef %a, [3 x <16 x i8>] %b.coerce, <8 x i8> noundef %c) #0 {
+// CHECK-LABEL: define{{.*}} <8 x i8> @test_vqtbx3_s8(<8 x i8> noundef %a, [3 x <16 x i8>] %b.coerce, <8 x i8> noundef %c) #1 {
 // CHECK:

[PATCH] D122271: [Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators

2022-03-22 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

LGTM. Maybe @efriedma can look at this as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122271

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


[PATCH] D122277: [analyzer] Fix crash in RangedConstraintManager.cpp

2022-03-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Thanks! I agree that this assertion doesn't make much sense. Judging by the 
name, the function should be able to handle all symbols.




Comment at: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:61
+// to canonicalize "a - b" and "b - a", which would allow us to treat 
"a
+// != b" and "b != a" the same.
+

The new line break in the middle of `a != b` doesn't make much sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122277

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


[PATCH] D122285: [analyzer] Add path note tags to standard library function summaries.

2022-03-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:41
 //
-// The following standard C functions are currently supported:
-//

This comment has been out of date for years and I don't think it makes sense to 
have it in the first place.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:1215-1217
   // The locale-specific range.
   // No post-condition. We are completely unaware of
   // locale-specific return values.

I'm not adding notes to these ranges because these days I think they were a 
mistake. A three-way (sometimes four-way) state split is pretty hard to 
justify. It's much safer to drop the case and stick to the two ASCII cases.


Repository:
  rC Clang

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

https://reviews.llvm.org/D122285

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


[PATCH] D122285: [analyzer] Add path note tags to standard library function summaries.

2022-03-22 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: t-rasmud, Szelethus, martong, steakhal, ASDenysPetrov, 
balazske, gamesh411.
Herald added subscribers: manas, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: All.
NoQ requested review of this revision.

This is a solution to the issue with `getenv()` 
(https://github.com/llvm/llvm-project/issues/53276) but I covered a few more 
functions just because I could.

The patch is straightforward except the tiny fix in `BugReporterVisitors.cpp` 
that suppresses a default note for "Assuming pointer value is null" when a note 
tag from the checker is present. This is probably the right thing to do but 
also definitely not a complete solution to the problem of different sources of 
path notes being unaware of each other, which is a large and annoying issue 
that we have to deal with. Note tags really help there because they're nicely 
introspectable. The problem is demonstrated by the newly added `getenv()` test; 
I did not investigate why doesn't the original buggy report have the same note 
but I agree that this might be interesting to figure out.

The notes are currently optional but I think we should eventually implement all 
of them and then make them mandatory.

The notes are prunable, i.e. they won't bring-in entire stack frames worth of 
notes just because they're there, but they will be always visible regardless of 
whether the value is of interest to the bug report. I think this is debatable, 
the arguably better solution is to make them non-prunable but conditional to 
the value being tracked back to the call, which would probably need a better 
tracking infrastructure.


Repository:
  rC Clang

https://reviews.llvm.org/D122285

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-path-notes.c

Index: clang/test/Analysis/std-c-library-functions-path-notes.c
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-path-notes.c
@@ -0,0 +1,46 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN: -analyzer-checker=core,apiModeling \
+// RUN: -analyzer-config assume-controlled-environment=false \
+// RUN: -analyzer-output=text
+
+#define NULL ((void *)0)
+
+char *getenv(const char *);
+int isalpha(int);
+int isdigit(int);
+
+char test_getenv() {
+  char *env = getenv("VAR"); // \
+  // expected-note{{Assuming the environment variable does not exist}} \
+  // expected-note{{'env' initialized here}}
+
+  return env[0]; // \
+  // expected-warning{{Array access (from variable 'env') results in a null pointer dereference}} \
+  // expected-note   {{Array access (from variable 'env') results in a null pointer dereference}}
+}
+
+int test_isalpha(int *x, char c) {
+  if (isalpha(c)) {// \
+// expected-note{{Assuming the character is alphabetical}} \
+// expected-note{{Taking true branch}}
+x = NULL; // \
+// expected-note{{Null pointer value stored to 'x'}}
+  }
+
+  return *x; // \
+  // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
+  // expected-note   {{Dereference of null pointer (loaded from variable 'x')}}
+}
+
+int test_isdigit(int *x, char c) {
+  if (!isdigit(c)) {// \
+// expected-note{{Assuming the character is not a digit}} \
+// expected-note{{Taking true branch}}
+x = NULL; // \
+// expected-note{{Null pointer value stored to 'x'}}
+  }
+
+  return *x; // \
+  // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} \
+  // expected-note   {{Dereference of null pointer (loaded from variable 'x')}}
+}
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -38,7 +38,8 @@
 }
 
 void test_alnum_symbolic(int x) {
-  int ret = isalnum(x);
+  int ret = isalnum(x); // \
+  // bugpath-note{{Assuming the character is non-alphanumeric}}
   (void)ret;
 
   clang_analyzer_eval(EOF <= x && x <= 255); // \
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1691,6 +1691,13 @@
 
 // Construct a new PathDiagnosticPiece.
 ProgramPoint P = N->getLocation();
+
+// If this node already have a specialized note, it's probably better
+// than our generic note.
+// FIXME: This only looks for note tags, not for other ways to add a note.
+if (isa_and_nonnull(P.getTag()))
+  return nullptr;
+
 PathDiagnosticLocation L =

[PATCH] D118493: Set rpath on openmp executables

2022-03-22 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

In D118493#3398808 , @JonChesterfield 
wrote:

> It lets applications run with the libomp and libomptarget built with the 
> toolchain. For users, they don't have to be root. For compiler devs, we test 
> our work instead of whatever the distro had installed.
>
> There's no info at that link. What's 'broken rpath'? If they mean runpath, 
> then it's really on fedora to have Wl,--rpath set rpath instead of runpath. 
> Setting the default in the linker to the one your own build tools reject will 
> break everything, not just llvm openmp.
>
> Edit: https://fedoraproject.org/wiki/Changes/Broken_RPATH_will_fail_rpmbuild
> Doesn't mean runpath. There's a list of strings Fedora (IBM?) have decided 
> they don't like, named 'broken' or 'invalid', and declared shall not be 
> present. Page doesn't go into the rpath/runpath distinction, maybe they mean 
> for the string restrictions to apply to both.

I'm not sure I follow this, but there is a script run after every RPM built for 
fedora that checks for RUNPATH (among other things in the binary).  I have been 
building packages for Fedora with clang14 and the script fails for packages 
built with clang + -fopenmp

> Can't tell which rule we're violating (will need to work out what the install 
> directory resolves to on fedora), though the one about executing untrusted 
> code seems likely, where untrusted seems to be anything not owned by root. 
> E.g. applications people have written themselves.

The rule that is broken is "standard RPATHs" Fedora installs libomp to 
/usr/lib64.

> We can introduce a cmake flag that changes the default on this commandline 
> argument, set when building on Fedora (and maybe redhat, centos-stream, 
> others). That'll annoy anyone developing openmp on, or using a local llvm 
> build on, Fedora but that might be zero people and they could override the 
> cmake flag and disable the build checking scripts.

I don't really like adding CMake options for things like this.  I think what 
we'll do in Fedora is just add -fno-openmp-implicit-rpath to the default CFLAGS 
so we can get the old behavior for official RPMs.

> Or disable building openmp on Fedora, that seems reasonable too.

We want to be able to build packages that use OpenMP, so disabling is not 
really an option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118493

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


[PATCH] D107141: [Inline-asm] Add diagnosts for unsupported inline assembly arguments

2022-03-22 Thread Phoebe Wang 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 rG32103608fc07: [Inline-asm] Add diagnosts for unsupported 
inline assembly arguments (authored by pengfei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107141

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/test/Sema/asm.c

Index: clang/test/Sema/asm.c
===
--- clang/test/Sema/asm.c
+++ clang/test/Sema/asm.c
@@ -313,3 +313,54 @@
   asm ("jne %l0":::);
   asm goto ("jne %l0"lab);
 }
+
+typedef struct _st_size64 {
+  int a;
+  char b;
+} st_size64;
+
+typedef struct _st_size96 {
+  int a;
+  int b;
+  int c;
+} st_size96;
+
+typedef struct _st_size16 {
+  char a;
+  char b;
+} st_size16;
+
+typedef struct _st_size32 {
+  char a;
+  char b;
+  char c;
+  char d;
+} st_size32;
+
+typedef struct _st_size128 {
+  int a;
+  int b;
+  int c;
+  int d;
+} st_size128;
+
+void test19(long long x)
+{
+  st_size64 a;
+  st_size96 b;
+  st_size16 c;
+  st_size32 d;
+  st_size128 e;
+  asm ("" : "=rm" (a): "0" (1)); // no-error
+  asm ("" : "=rm" (d): "0" (1)); // no-error
+  asm ("" : "=rm" (c): "0" (x)); // no-error
+  // FIXME: This case is actually supported by codegen.
+  asm ("" : "=rm" (x): "0" (a)); // expected-error {{unsupported inline asm: input with type 'st_size64' (aka 'struct _st_size64') matching output with type 'long long'}}
+  // FIXME: This case is actually supported by codegen.
+  asm ("" : "=rm" (a): "0" (d)); // expected-error {{unsupported inline asm: input with type 'st_size32' (aka 'struct _st_size32') matching output with type 'st_size64' (aka 'struct _st_size64')}}
+  asm ("" : "=rm" (b): "0" (1)); // expected-error {{impossible constraint in asm: can't store value into a register}}
+  // FIXME: This case should be supported by codegen, but it fails now.
+  asm ("" : "=rm" (e): "0" (1)); // no-error
+  // FIXME: This case should be supported by codegen, but it fails now.
+  asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: input with type 'st_size128' (aka 'struct _st_size128') matching output with type 'long long'}}
+}
Index: clang/lib/Sema/SemaStmtAsm.cpp
===
--- clang/lib/Sema/SemaStmtAsm.cpp
+++ clang/lib/Sema/SemaStmtAsm.cpp
@@ -667,8 +667,17 @@
 // output was a register, just extend the shorter one to the size of the
 // larger one.
 if (!SmallerValueMentioned && InputDomain != AD_Other &&
-OutputConstraintInfos[TiedTo].allowsRegister())
+OutputConstraintInfos[TiedTo].allowsRegister()) {
+  // FIXME: GCC supports the OutSize to be 128 at maximum. Currently codegen
+  // crash when the size larger than the register size. So we limit it here.
+  if (OutTy->isStructureType() &&
+  Context.getIntTypeForBitwidth(OutSize, /*Signed*/ false).isNull()) {
+targetDiag(OutputExpr->getExprLoc(), diag::err_store_value_to_reg);
+return NS;
+  }
+
   continue;
+}
 
 // Either both of the operands were mentioned or the smaller one was
 // mentioned.  One more special case that we'll allow: if the tied input is
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2744,9 +2744,8 @@
   QualType Ty = getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
   if (Ty.isNull()) {
 const Expr *OutExpr = S.getOutputExpr(i);
-CGM.Error(
-OutExpr->getExprLoc(),
-"impossible constraint in asm: can't store value into a register");
+CGM.getDiags().Report(OutExpr->getExprLoc(),
+  diag::err_store_value_to_reg);
 return;
   }
   Dest = MakeAddrLValue(A, Ty);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8783,6 +8783,8 @@
 " in asm %select{input|output}1 with a memory constraint '%2'">;
   def err_asm_input_duplicate_match : Error<
 "more than one input constraint matches the same output '%0'">;
+  def err_store_value_to_reg : Error<
+"impossible constraint in asm: can't store value into a register">;
 
   def warn_asm_label_on_auto_decl : Warning<
 "ignored asm label '%0' on automatic variable">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3210360 - [Inline-asm] Add diagnosts for unsupported inline assembly arguments

2022-03-22 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2022-03-23T11:25:19+08:00
New Revision: 32103608fc073700f04238872d8b22655ddec3fb

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

LOG: [Inline-asm] Add diagnosts for unsupported inline assembly arguments

GCC supports power-of-2 size structures for the arguments. Clang supports fewer 
than GCC. But Clang always crashes for the unsupported cases.

This patch adds sema checks to do the diagnosts to solve these crashes.

Reviewed By: jyu2

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGStmt.cpp
clang/lib/Sema/SemaStmtAsm.cpp
clang/test/Sema/asm.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dbde2af216d97..14b276cf82295 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8783,6 +8783,8 @@ let CategoryName = "Inline Assembly Issue" in {
 " in asm %select{input|output}1 with a memory constraint '%2'">;
   def err_asm_input_duplicate_match : Error<
 "more than one input constraint matches the same output '%0'">;
+  def err_store_value_to_reg : Error<
+"impossible constraint in asm: can't store value into a register">;
 
   def warn_asm_label_on_auto_decl : Warning<
 "ignored asm label '%0' on automatic variable">;

diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 5796bb849971f..2b27d64bc93ef 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2744,9 +2744,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
   QualType Ty = getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
   if (Ty.isNull()) {
 const Expr *OutExpr = S.getOutputExpr(i);
-CGM.Error(
-OutExpr->getExprLoc(),
-"impossible constraint in asm: can't store value into a register");
+CGM.getDiags().Report(OutExpr->getExprLoc(),
+  diag::err_store_value_to_reg);
 return;
   }
   Dest = MakeAddrLValue(A, Ty);

diff  --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp
index 49f7a8d573d5a..fbca36b1216a8 100644
--- a/clang/lib/Sema/SemaStmtAsm.cpp
+++ b/clang/lib/Sema/SemaStmtAsm.cpp
@@ -667,8 +667,17 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, 
bool IsSimple,
 // output was a register, just extend the shorter one to the size of the
 // larger one.
 if (!SmallerValueMentioned && InputDomain != AD_Other &&
-OutputConstraintInfos[TiedTo].allowsRegister())
+OutputConstraintInfos[TiedTo].allowsRegister()) {
+  // FIXME: GCC supports the OutSize to be 128 at maximum. Currently 
codegen
+  // crash when the size larger than the register size. So we limit it 
here.
+  if (OutTy->isStructureType() &&
+  Context.getIntTypeForBitwidth(OutSize, /*Signed*/ false).isNull()) {
+targetDiag(OutputExpr->getExprLoc(), diag::err_store_value_to_reg);
+return NS;
+  }
+
   continue;
+}
 
 // Either both of the operands were mentioned or the smaller one was
 // mentioned.  One more special case that we'll allow: if the tied input is

diff  --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c
index 540a2769fa3b3..3c7952f410c6d 100644
--- a/clang/test/Sema/asm.c
+++ b/clang/test/Sema/asm.c
@@ -313,3 +313,54 @@ lab2:;
   asm ("jne %l0":::);
   asm goto ("jne %l0"lab);
 }
+
+typedef struct _st_size64 {
+  int a;
+  char b;
+} st_size64;
+
+typedef struct _st_size96 {
+  int a;
+  int b;
+  int c;
+} st_size96;
+
+typedef struct _st_size16 {
+  char a;
+  char b;
+} st_size16;
+
+typedef struct _st_size32 {
+  char a;
+  char b;
+  char c;
+  char d;
+} st_size32;
+
+typedef struct _st_size128 {
+  int a;
+  int b;
+  int c;
+  int d;
+} st_size128;
+
+void test19(long long x)
+{
+  st_size64 a;
+  st_size96 b;
+  st_size16 c;
+  st_size32 d;
+  st_size128 e;
+  asm ("" : "=rm" (a): "0" (1)); // no-error
+  asm ("" : "=rm" (d): "0" (1)); // no-error
+  asm ("" : "=rm" (c): "0" (x)); // no-error
+  // FIXME: This case is actually supported by codegen.
+  asm ("" : "=rm" (x): "0" (a)); // expected-error {{unsupported inline asm: 
input with type 'st_size64' (aka 'struct _st_size64') matching output with type 
'long long'}}
+  // FIXME: This case is actually supported by codegen.
+  asm ("" : "=rm" (a): "0" (d)); // expected-error {{unsupported inline asm: 
input with type 'st_size32' (aka 'struct _st_size32') matching output with type 
'st_size64' (aka 'struct _st_size64')}}
+  asm ("" : "=rm" (b): "0" (1)); // expected-error {{impossible constraint in 
asm:

[PATCH] D121868: [cc1as] Add support for emitting the build version load command for -darwin-target-variant

2022-03-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.
Herald added a subscriber: StephenFan.

This may need a test in `clang/test/Misc/cc1as-*`.

Can you add to the description what the `clang -cc1as` usage looks like?




Comment at: clang/tools/driver/cc1as_main.cpp:217
+llvm::Triple TVT(A->getValue());
+Opts.DarwinTargetVariantTriple = TVT;
+  }





Comment at: clang/tools/driver/cc1as_main.cpp:419
+  if (Opts.DarwinTargetVariantTriple) {
+MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple);
+  }

https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121868

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


[PATCH] D120397: [C++20] [Modules] Make the linkage consistent for template and its specialization

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked an inline comment as done.
ChuanqiXu added a comment.

In D120397#3399808 , @aaron.ballman 
wrote:

> Can you also add a release note that explains we've fixed the crash?

My thought is to edit a release note standalone. Since there are already many 
works in modules now. I guess it might be better to try to give a summarize.


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

https://reviews.llvm.org/D120397

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


[PATCH] D120397: [C++20] [Modules] Make the linkage consistent for template and its specialization

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 417479.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D120397

Files:
  clang/lib/AST/Decl.cpp
  clang/unittests/AST/DeclTest.cpp


Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -171,3 +171,26 @@
   selectFirst("f", match(functionDecl().bind("f"), Ctx));
   EXPECT_TRUE(f->isInExportDeclContext());
 }
+
+TEST(Decl, InConsistLinkageForTemplates) {
+  llvm::Annotations Code(R"(
+export module m;
+export template 
+void f() {}
+
+template <>
+void f() {})");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  llvm::SmallVector Funcs =
+  match(functionDecl().bind("f"), Ctx);
+
+  EXPECT_EQ(Funcs.size(), 2);
+  const FunctionDecl *TemplateF = Funcs[0].getNodeAs("f");
+  const FunctionDecl *SpecializedF = Funcs[1].getNodeAs("f");
+  EXPECT_EQ(TemplateF->getLinkageInternal(),
+SpecializedF->getLinkageInternal());
+}
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -391,11 +391,18 @@
   bool considerVisibility =
 shouldConsiderTemplateVisibility(fn, specInfo);
 
-  // Merge information from the template parameters.
   FunctionTemplateDecl *temp = specInfo->getTemplate();
-  LinkageInfo tempLV =
-getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
-  LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
+
+  // Merge information from the template declaration.
+  LinkageInfo tempLV = getLVForDecl(temp, computation);
+  // The linkage of the specialization should be consistent with the
+  // template declaration.
+  LV.setLinkage(tempLV.getLinkage());
+
+  // Merge information from the template parameters.
+  LinkageInfo paramsLV =
+  getLVForTemplateParameterList(temp->getTemplateParameters(), 
computation);
+  LV.mergeMaybeWithVisibility(paramsLV, considerVisibility);
 
   // Merge information from the template arguments.
   const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments;


Index: clang/unittests/AST/DeclTest.cpp
===
--- clang/unittests/AST/DeclTest.cpp
+++ clang/unittests/AST/DeclTest.cpp
@@ -171,3 +171,26 @@
   selectFirst("f", match(functionDecl().bind("f"), Ctx));
   EXPECT_TRUE(f->isInExportDeclContext());
 }
+
+TEST(Decl, InConsistLinkageForTemplates) {
+  llvm::Annotations Code(R"(
+export module m;
+export template 
+void f() {}
+
+template <>
+void f() {})");
+
+  auto AST =
+  tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  llvm::SmallVector Funcs =
+  match(functionDecl().bind("f"), Ctx);
+
+  EXPECT_EQ(Funcs.size(), 2);
+  const FunctionDecl *TemplateF = Funcs[0].getNodeAs("f");
+  const FunctionDecl *SpecializedF = Funcs[1].getNodeAs("f");
+  EXPECT_EQ(TemplateF->getLinkageInternal(),
+SpecializedF->getLinkageInternal());
+}
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -391,11 +391,18 @@
   bool considerVisibility =
 shouldConsiderTemplateVisibility(fn, specInfo);
 
-  // Merge information from the template parameters.
   FunctionTemplateDecl *temp = specInfo->getTemplate();
-  LinkageInfo tempLV =
-getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
-  LV.mergeMaybeWithVisibility(tempLV, considerVisibility);
+
+  // Merge information from the template declaration.
+  LinkageInfo tempLV = getLVForDecl(temp, computation);
+  // The linkage of the specialization should be consistent with the
+  // template declaration.
+  LV.setLinkage(tempLV.getLinkage());
+
+  // Merge information from the template parameters.
+  LinkageInfo paramsLV =
+  getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
+  LV.mergeMaybeWithVisibility(paramsLV, considerVisibility);
 
   // Merge information from the template arguments.
   const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D107141: [Inline-asm] Add diagnosts for unsupported inline assembly arguments

2022-03-22 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks @jyu2 !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107141

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


[PATCH] D107141: [Inline-asm] Add diagnosts for unsupported inline assembly arguments

2022-03-22 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 accepted this revision.
jyu2 added a comment.
This revision is now accepted and ready to land.

This is okay with me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107141

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


[PATCH] D120874: [C++20] [Modules] Use '-' as the separator of partitions when searching in filesystems

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@iains  ping~


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

https://reviews.llvm.org/D120874

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


[PATCH] D119409: [C++20] [Modules] Remain dynamic initializing internal-linkage variables in module interface unit

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a subscriber: urnathan.
ChuanqiXu added a comment.

In D119409#3400287 , @dblaikie wrote:

> In D119409#3398483 , @ChuanqiXu 
> wrote:
>
>> In D119409#3396690 , @dblaikie 
>> wrote:
>>
>>> Not even necessarily then - if you have code like protobufs (large amounts 
>>> of autogenerated code, much of which you might never call) - or even just 
>>> libraries where you only use a subset of their features - then you might 
>>> have more code generated with an inline-function-homing
>>
>> From the perspective of code size, it would be larger in 
>> inline-function-homing strategies in cases you described. But I guess it 
>> wouldn't hurt in compilation speed, is it?
>
> Depending on optimizations, some amount of compilation time is proportional 
> to code size.

Yeah, I am not strict enough. I mean the compilation time of the importee 
wouldn't be hurt. The compilation time of the module itself would be more of 
course. Given the module is imported in many places, it would be a win. But if 
it is not, then it might be a bad idea.
So the conclusion would be that inline-function-homing wouldn't be a pure win 
all the time.  I just want to say it might be a win in a lot of cases.

>> For the consideration of code size, I think we could mitigate the problem by 
>> thinLTO. (Although we couldn't solve the problem completely since thinLTO 
>> couldn't help for *.o, *.a and *.so files.)
>
> Yep. But with ThinLTO we wouldn't need to produce `available_externally` 
> definitions anyway, since ThinLTO can cross-object import anyway.

Yeah. My point is that with the inline-function-homing strategy, we could not 
produce `available_externally`  functions in the frontend so that we could get 
a big compilation speedup. In some of my experiments, the speed could be 5x 
than before : ) It is exciting.

>>> Possibly - there's still the possibility that even without any importing (& 
>>> just homing into the module object file) that it'll cost more than it 
>>> benefits due to inline functions that are never called.
>>
>> Yeah, I met the situation before. In a simple case, that the time spent on 
>> the deserialization looks more than the time we saved. By from my experience 
>> (my experience is not complete though), this kind of cases is relatively 
>> small.
>>
>> ---
>>
>> @dblaikie given that the talk involves further optimization, which is beyond 
>> the scope of current patch. Would you like to accept this one?
>
> I don't have enough context for the current state of this patch - might be 
> useful to post a summary of the current state?

Yeah. Let me try to give a summary. The intention of the patch is fix the 
following problem:

  // Hello.cppm
  module;
  #include 
  export module Hello;
  export void SayHello()
  {
  std::printf("Hello World.\n");
  
  }
  // main.cpp
  import Hello;
  int main() {
 SayHello();
 return 0;
  }

The program compiled in this way would met a segment fault at run time if it 
uses libstdc++. The root cause is that libstdc++ uses the constructor of the 
following static variable to do resources initializations.

  // For construction of filebuffers for cout, cin, cerr, clog et. al.
  static ios_base::Init __ioinit;

And in the original implementation, the static variable (with internal linkage) 
is considered invisible to the outside so it wouldn't be generated in the PCM 
(the binary form of AST).

To solve the problem, the patch intends to remain the static variable (or say, 
variable with internal linkage). Then @urnathan pointed that we should only 
generate the static variables with dynamic initializer. Then this is the 
current status of patch.

Although the discuss is very long, almost of them talks about the 
inline-function-strategy. We talked a lot about that whether it is valid or 
whether it is useful. But all of them are beyond the scope of the patch : )


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

https://reviews.llvm.org/D119409

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


[PATCH] D115248: [Clang] Fix PR28101

2022-03-22 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 417475.
rZhBoYao added a comment.

Don't break template declarations.
re-clang-format


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

https://reviews.llvm.org/D115248

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/PR28101.cpp


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template  struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template  struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template  struct S {};
+
+template  struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U> class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template 
arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}
+};
+
+template  struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,7 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template  struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template  struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template  struct S {};
+
+template  struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U> class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}
+};
+
+template  struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,7 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122119: [C++20][Modules] Adjust handling of exports of namespaces and using-decls.

2022-03-22 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D122119#3400032 , @urnathan wrote:

> In D122119#3398949 , @ChuanqiXu 
> wrote:
>
>> 
>
>
>
>> The first feeling I saw the change is that not every C++ programmer knows 
>> about linkage. OK, it depends on the environment really and every one might 
>> has their own opinion.
>
> You may be confusing object-file linkage with the linkage concepts of C++, 
> which are specified in [basic.link]?  Sadly we have to live with the 
> overloaded term.
>
>> Another thought is that 10.2.6 (http://eel.is/c++draft/module.interface#6) 
>> doesn't talk anything about linkage:
>>
>>> A redeclaration of an entity X is implicitly exported if X was introduced 
>>> by an exported declaration; otherwise it shall not be exported.
>>
>> So it looks like confusing to talk about linkage this time. In my 
>> imagination, there might be a such situation:
>>
>> A programmer met the error when he tries to export a redeclaration which is 
>> internal linkage (maybe a simple const variable). Then the message told him 
>> the internal linkage is not allowed to re-export. Then he removes the const 
>> specifier. Now he meets the error again. It tells that we couldn't export 
>> redeclaration which is module linkage. I guess he would feel bad. Then he 
>> might try to export the first declaration to get passed. However, the 
>> `const` specifier is lost in the case. And in the current message, I guess 
>> he would add export to the first declaration directly after he reads the 
>> message.
>
> further, with attachment, the original error 'cannot export as previous was 
> not exported' is not correct in general.  Consider:
>
> module;
> // Pretend this is from #include, ok?
> void Foo ();
> module bob;
> extern "C++" export void Foo ();  // can export even though prior was not 
> exported

I think the example is invalid since it violates [[ 
http://eel.is/c++draft/module.interface#6 | [module.interface]p6 ]] explicitly. 
If this is intended behavior or by design, we should change the wording.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122119

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


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-22 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.

LGTM too!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121812

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


[PATCH] D121176: [ASTStructuralEquivalence] Add support for comparing ObjCCategoryDecl.

2022-03-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

@shafik, can you please check the patch? Or maybe recommend somebody who worked 
both on ASTStructuralEquivalence and Objective-C part of clang?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121176

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


[PATCH] D118525: [modules] Merge ObjC interface ivars with anonymous types.

2022-03-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 417468.
vsapsai added a comment.

Fix bug with anonymous enum constant lookup in C++.

Turns out the lookup was broken by using `ObjCInterfaceDecl` as a semantic decl
context for anonymous enums. Fixing that fixed the lookup.

Also added in tests checking scoped enums in C++. Scoped enums cannot be
anonymous, so test only named enum definitions inside Objective-C code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118525

Files:
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/AST/ast-dump-decl.mm
  clang/test/Modules/merge-anon-record-definition-in-objc.m
  clang/test/SemaObjC/check-dup-decls-inside-objc.m

Index: clang/test/SemaObjC/check-dup-decls-inside-objc.m
===
--- /dev/null
+++ clang/test/SemaObjC/check-dup-decls-inside-objc.m
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class -x objective-c++ %s
+
+// Test decls inside Objective-C entities are considered to be duplicates of same-name decls outside of these entities.
+
+@protocol SomeProtocol
+struct InProtocol {}; // expected-note {{previous definition is here}}
+- (union MethodReturnType { int x; float y; })returningMethod; // expected-note {{previous definition is here}}
+#ifdef __cplusplus
+// expected-error@-2 {{'MethodReturnType' cannot be defined in a parameter type}}
+#endif
+@end
+
+@interface Container {
+  struct InInterfaceCurliesWithField {} field; // expected-note {{previous definition is here}}
+  union InInterfaceCurlies { int x; float y; }; // expected-note {{previous definition is here}}
+}
+enum InInterface { kX = 0, }; // expected-note {{previous definition is here}}
+#ifdef __cplusplus
+enum class InInterfaceScoped { kXScoped = 0, }; // expected-note {{previous definition is here}}
+#endif
+@end
+
+@interface Container(Category)
+union InCategory { int x; float y; }; // expected-note {{previous definition is here}}
+@end
+
+@interface Container() {
+  enum InExtensionCurliesWithField: int { kY = 1, } extensionField; // expected-note {{previous definition is here}}
+  struct InExtensionCurlies {}; // expected-note {{previous definition is here}}
+}
+union InExtension { int x; float y; }; // expected-note {{previous definition is here}}
+@end
+
+@implementation Container {
+  union InImplementationCurliesWithField { int x; float y; } implField; // expected-note {{previous definition is here}}
+  enum InImplementationCurlies { kZ = 2, }; // expected-note {{previous definition is here}}
+}
+struct InImplementation {}; // expected-note {{previous definition is here}}
+@end
+
+@implementation Container(Category)
+enum InCategoryImplementation { kW = 3, }; // expected-note {{previous definition is here}}
+@end
+
+
+struct InProtocol { int a; }; // expected-error {{redefinition of 'InProtocol'}}
+union MethodReturnType { int a; long b; }; // expected-error {{redefinition of 'MethodReturnType'}}
+
+struct InInterfaceCurliesWithField { int a; }; // expected-error {{redefinition of 'InInterfaceCurliesWithField'}}
+union InInterfaceCurlies { int a; long b; }; // expected-error {{redefinition of 'InInterfaceCurlies'}}
+enum InInterface { kA = 10, }; // expected-error {{redefinition of 'InInterface'}}
+#ifdef __cplusplus
+enum class InInterfaceScoped { kAScoped = 10, }; // expected-error {{redefinition of 'InInterfaceScoped'}}
+#endif
+
+union InCategory { int a; long b; }; // expected-error {{redefinition of 'InCategory'}}
+
+enum InExtensionCurliesWithField: int { kB = 11, }; // expected-error {{redefinition of 'InExtensionCurliesWithField'}}
+struct InExtensionCurlies { int a; }; // expected-error {{redefinition of 'InExtensionCurlies'}}
+union InExtension { int a; long b; }; // expected-error {{redefinition of 'InExtension'}}
+
+union InImplementationCurliesWithField { int a; long b; }; // expected-error {{redefinition of 'InImplementationCurliesWithField'}}
+enum InImplementationCurlies { kC = 12, }; // expected-error {{redefinition of 'InImplementationCurlies'}}
+struct InImplementation { int a; }; // expected-error {{redefinition of 'InImplementation'}}
+
+enum InCategoryImplementation { kD = 13, }; // expected-error {{redefinition of 'InCategoryImplementation'}}
Index: clang/test/Modules/merge-anon-record-definition-in-objc.m
===
--- /dev/null
+++ clang/test/Modules/merge-anon-record-definition-in-objc.m
@@ -0,0 +1,84 @@
+// UNSUPPORTED: -zos, -aix
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -fsyntax-only -F%t/Frameworks %t/test.m -Wno-objc-property-implementation -Wno-incomplete-implementation \
+// RUN:-fmodules -fmodule-name=Target -fimplicit-modul

[PATCH] D121359: [AVR] Add more devices

2022-03-22 Thread Ben Shi 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 rG6edfe45a6312: [AVR] Add more devices (authored by benshi001).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121359

Files:
  clang/lib/Basic/Targets/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/lib/Target/AVR/AVRDevices.td

Index: llvm/lib/Target/AVR/AVRDevices.td
===
--- llvm/lib/Target/AVR/AVRDevices.td
+++ llvm/lib/Target/AVR/AVRDevices.td
@@ -245,6 +245,7 @@
 def : Device<"avrtiny", FamilyTiny, ELFArchTiny>;
 
 // Specific MCUs
+// NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
 def : Device<"at90s1200", FamilyAVR0, ELFArchAVR1>;
 def : Device<"attiny11", FamilyAVR1, ELFArchAVR1>;
 def : Device<"attiny12", FamilyAVR1, ELFArchAVR1>;
@@ -299,6 +300,8 @@
 def : Device<"at90usb82", FamilyAVR35, ELFArchAVR35>;
 def : Device<"at90usb162", FamilyAVR35, ELFArchAVR35>;
 def : Device<"ata5505", FamilyAVR35, ELFArchAVR35>;
+def : Device<"ata6617c", FamilyAVR35, ELFArchAVR35>;
+def : Device<"ata664251", FamilyAVR35, ELFArchAVR35>;
 def : Device<"atmega8u2", FamilyAVR35, ELFArchAVR35>;
 def : Device<"atmega16u2", FamilyAVR35, ELFArchAVR35>;
 def : Device<"atmega32u2", FamilyAVR35, ELFArchAVR35>;
@@ -310,6 +313,7 @@
  [FeatureMultiplication, FeatureMOVW, FeatureLPMX, FeatureSPM]>;
 def : Device<"ata6285", FamilyAVR4, ELFArchAVR4>;
 def : Device<"ata6286", FamilyAVR4, ELFArchAVR4>;
+def : Device<"ata6612c", FamilyAVR4, ELFArchAVR4>;
 def : Device<"atmega48", FamilyAVR4, ELFArchAVR4>;
 def : Device<"atmega48a", FamilyAVR4, ELFArchAVR4>;
 def : Device<"atmega48pa", FamilyAVR4, ELFArchAVR4>;
@@ -331,8 +335,17 @@
 def : Device<"at90pwm3", FamilyAVR4, ELFArchAVR4>;
 def : Device<"at90pwm3b", FamilyAVR4, ELFArchAVR4>;
 def : Device<"at90pwm81", FamilyAVR4, ELFArchAVR4>;
+def : Device<"ata5702m322", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata5782", FamilyAVR5, ELFArchAVR5>;
 def : Device<"ata5790", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata5790n", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata5791", FamilyAVR5, ELFArchAVR5>;
 def : Device<"ata5795", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata5831", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata6613c", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata6614q", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata8210", FamilyAVR5, ELFArchAVR5>;
+def : Device<"ata8510", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega16", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega16a", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega161", FamilyAVR3, ELFArchAVR5,
@@ -411,6 +424,7 @@
 def : Device<"atmega32hvb", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega32hvbrevb", FamilyAVR5, ELFArchAVR5>;
 def : Device<"atmega64hve", FamilyAVR5, ELFArchAVR5>;
+def : Device<"atmega64hve2", FamilyAVR5, ELFArchAVR5>;
 def : Device<"at90can32", FamilyAVR5, ELFArchAVR5>;
 def : Device<"at90can64", FamilyAVR5, ELFArchAVR5>;
 def : Device<"at90pwm161", FamilyAVR5, ELFArchAVR5>;
@@ -452,7 +466,9 @@
 def : Device<"atxmega16d4", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega32a4", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega32a4u", FamilyXMEGAU, ELFArchXMEGA2>;
+def : Device<"atxmega32c3", FamilyXMEGAU, ELFArchXMEGA2>;
 def : Device<"atxmega32c4", FamilyXMEGAU, ELFArchXMEGA2>;
+def : Device<"atxmega32d3", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega32d4", FamilyXMEGA, ELFArchXMEGA2>;
 def : Device<"atxmega32e5", FamilyXMEGAU, ELFArchXMEGA2>;
 def : Device<"atxmega16e5", FamilyXMEGAU, ELFArchXMEGA2>;
Index: clang/test/Misc/target-invalid-cpu-note.c
===
--- clang/test/Misc/target-invalid-cpu-note.c
+++ clang/test/Misc/target-invalid-cpu-note.c
@@ -77,7 +77,7 @@
 
 // RUN: not %clang_cc1 -triple avr--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AVR
 // AVR: error: unknown target CPU 'not-a-cpu'
-// AVR-NEXT: note: valid target CPU values are: avr1, avr2, avr25, avr3, avr31, avr35, avr4, avr5, avr51, avr6, avrxmega1, avrxmega2, avrxmega3, avrxmega4, avrxmega5, avrxmega6, avrxmega7, avrtiny, at90s1200, attiny11, attiny12, attiny15, attiny28, at90s2313, at90s2323, at90s2333, at90s2343, attiny22, attiny26, at86rf401, at90s4414, at90s4433, at90s4434, at90s8515, at90c8534, at90s8535, ata5272, attiny13, attiny13a, attiny2313, attiny2313a, attiny24, attiny24a, attiny4313, attiny44, attiny44a, attiny84, attiny84a, attiny25, attiny45, attiny85, attiny261, attiny261a, attiny441, attiny461, attiny461a, attiny841, attiny861, attiny861a, attiny87, attiny43u, attiny48, attiny88, attiny828, at43usb355, at76c711, atmega103, at43usb320, attiny167, at90usb82, at90usb162, ata5505, atmega8u2, atmega16u2, atmega32u2, attiny1634, atmega8, ata6289, atmeg

[clang] 6edfe45 - [AVR] Add more devices

2022-03-22 Thread Ben Shi via cfe-commits

Author: Ben Shi
Date: 2022-03-23T02:00:15Z
New Revision: 6edfe45a63125a8938a5bea13534a118b0e31023

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

LOG: [AVR] Add more devices

Synchronize AVR device lists with gcc-avr-5.4.0 and avr-libc-2.0.0.

Reviewed By: dylanmckay, aykevl

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

Added: 


Modified: 
clang/lib/Basic/Targets/AVR.cpp
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Misc/target-invalid-cpu-note.c
llvm/lib/Target/AVR/AVRDevices.td

Removed: 




diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 6266ed72cd5c0..dfc98c3d085d9 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -27,7 +27,7 @@ struct LLVM_LIBRARY_VISIBILITY MCUInfo {
   const int NumFlashBanks; // -1 means the device does not support LPM/ELPM.
 };
 
-// This list should be kept up-to-date with AVRDevices.td in LLVM.
+// NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
 static MCUInfo AVRMcus[] = {
 {"at90s1200", "__AVR_AT90S1200__", 0},
 {"attiny11", "__AVR_ATtiny11__", 0},
@@ -83,6 +83,8 @@ static MCUInfo AVRMcus[] = {
 {"at90usb82", "__AVR_AT90USB82__", 1},
 {"at90usb162", "__AVR_AT90USB162__", 1},
 {"ata5505", "__AVR_ATA5505__", 1},
+{"ata6617c", "__AVR_ATA6617C__", 1},
+{"ata664251", "__AVR_ATA664251__", 1},
 {"atmega8u2", "__AVR_ATmega8U2__", 1},
 {"atmega16u2", "__AVR_ATmega16U2__", 1},
 {"atmega32u2", "__AVR_ATmega32U2__", 1},
@@ -92,6 +94,7 @@ static MCUInfo AVRMcus[] = {
 {"atmega8a", "__AVR_ATmega8A__", 1},
 {"ata6285", "__AVR_ATA6285__", 1},
 {"ata6286", "__AVR_ATA6286__", 1},
+{"ata6612c", "__AVR_ATA6612C__", 1},
 {"atmega48", "__AVR_ATmega48__", 1},
 {"atmega48a", "__AVR_ATmega48A__", 1},
 {"atmega48pa", "__AVR_ATmega48PA__", 1},
@@ -111,8 +114,17 @@ static MCUInfo AVRMcus[] = {
 {"at90pwm3", "__AVR_AT90PWM3__", 1},
 {"at90pwm3b", "__AVR_AT90PWM3B__", 1},
 {"at90pwm81", "__AVR_AT90PWM81__", 1},
+{"ata5702m322", "__AVR_ATA5702M322__", 1},
+{"ata5782", "__AVR_ATA5782__", 1},
 {"ata5790", "__AVR_ATA5790__", 1},
+{"ata5790n", "__AVR_ATA5790N__", 1},
+{"ata5791", "__AVR_ATA5791__", 1},
 {"ata5795", "__AVR_ATA5795__", 1},
+{"ata5831", "__AVR_ATA5831__", 1},
+{"ata6613c", "__AVR_ATA6613C__", 1},
+{"ata6614q", "__AVR_ATA6614Q__", 1},
+{"ata8210", "__AVR_ATA8210__", 1},
+{"ata8510", "__AVR_ATA8510__", 1},
 {"atmega16", "__AVR_ATmega16__", 1},
 {"atmega16a", "__AVR_ATmega16A__", 1},
 {"atmega161", "__AVR_ATmega161__", 1},
@@ -189,6 +201,7 @@ static MCUInfo AVRMcus[] = {
 {"atmega32hvb", "__AVR_ATmega32HVB__", 1},
 {"atmega32hvbrevb", "__AVR_ATmega32HVBREVB__", 1},
 {"atmega64hve", "__AVR_ATmega64HVE__", 1},
+{"atmega64hve2", "__AVR_ATmega64HVE2__", 1},
 {"at90can32", "__AVR_AT90CAN32__", 1},
 {"at90can64", "__AVR_AT90CAN64__", 1},
 {"at90pwm161", "__AVR_AT90PWM161__", 1},
@@ -229,7 +242,9 @@ static MCUInfo AVRMcus[] = {
 {"atxmega16d4", "__AVR_ATxmega16D4__", 1},
 {"atxmega32a4", "__AVR_ATxmega32A4__", 1},
 {"atxmega32a4u", "__AVR_ATxmega32A4U__", 1},
+{"atxmega32c3", "__AVR_ATxmega32C3__", 1},
 {"atxmega32c4", "__AVR_ATxmega32C4__", 1},
+{"atxmega32d3", "__AVR_ATxmega32D3__", 1},
 {"atxmega32d4", "__AVR_ATxmega32D4__", 1},
 {"atxmega32e5", "__AVR_ATxmega32E5__", 1},
 {"atxmega16e5", "__AVR_ATxmega16E5__", 1},

diff  --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 2cf16cf9fdb49..5577c709a09fc 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -28,6 +28,7 @@ using namespace llvm::opt;
 
 namespace {
 
+// NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
 constexpr struct {
   StringRef Name;
   StringRef SubPath;
@@ -88,6 +89,8 @@ constexpr struct {
 {"at90usb82", "avr35", "avr35", 0x800100},
 {"at90usb162", "avr35", "avr35", 0x800100},
 {"ata5505", "avr35", "avr35", 0x800100},
+{"ata6617c", "avr35", "avr35", 0x800100},
+{"ata664251", "avr35", "avr35", 0x800100},
 {"atmega8u2", "avr35", "avr35", 0x800100},
 {"atmega16u2", "avr35", "avr35", 0x800100},
 {"atmega32u2", "avr35", "avr35", 0x800100},
@@ -97,6 +100,7 @@ constexpr struct {
 {"atmega8a", "avr4", "avr4", 0x800060},
 {"ata6285", "avr4", "avr4", 0x800100},
 {"ata6286", "avr4", "avr4", 0x800100},
+{"ata6612c", "avr4", "avr4", 0x800100},
 {"atmega48", "avr4", "avr4", 0x800100},
 {"atmega48a", "avr4", "avr4", 0x800100},
 {"atmega48pa", "avr4", "avr4", 0x800100},
@@ -116,8 +120,17 @@ constexpr struct {
 {"at90pwm3", "avr4

[PATCH] D115248: [Clang] Fix PR28101

2022-03-22 Thread PoYao Chang via Phabricator via cfe-commits
rZhBoYao updated this revision to Diff 417461.
rZhBoYao retitled this revision from "[clang] Fix PR28101" to "[Clang] Fix 
PR28101".
rZhBoYao edited the summary of this revision.
rZhBoYao added a reviewer: cor3ntin.
rZhBoYao set the repository for this revision to rG LLVM Github Monorepo.
rZhBoYao added a comment.
Herald added a project: All.

The previous diff was indeed very specific and doesn't handle

  template 
  struct A {
A(void*) {}
T A{}; // expected-error{{member 'A' cannot have template arguments}}
  };
  
  A instantiate() { return {nullptr}; }

I have since realized the invalid decorator is the problem and the parentheses 
are insignificant. It's like:

  template  struct S {};
  int S{};

which gcc diagnoses to

> error: invalid declarator before '{' token

Then I found there was a new diagnostic added by D120881 
. So the fix is pretty straightforward at 
this point. I simply stand on the shoulder of the giant and set the invalid 
flag of the declarator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115248

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/PR28101.cpp


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template 
+struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template 
+struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template 
+struct S {};
+
+template 
+struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U>
+class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template 
arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}
+};
+
+template 
+struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,7 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {


Index: clang/test/SemaCXX/PR28101.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR28101.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_1 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_2 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_3 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -DCASE_4 -std=c++17 %s
+
+// Don't crash.
+
+#ifdef CASE_1
+
+template 
+struct A {
+  A(void *) {}
+  T(A){}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_2
+
+template 
+struct A {
+  A(void *) {}
+  T A{}; // expected-error{{member 'A' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_3
+
+template 
+struct S {};
+
+template 
+struct A {
+  A(void *) {}
+  T S{}; // expected-error{{member 'S' cannot have template arguments}}
+};
+
+A instantiate() { return {nullptr}; }
+
+#elifdef CASE_4
+
+template  typename U>
+class A {
+public:
+  A(void *) {}
+  T(A>) {} // expected-error{{member 'A' cannot have template arguments}}\
+  // expected-error{{expected ';' at end of declaration list}}
+};
+
+template 
+struct S {};
+
+A foo() { return A(nullptr); }
+
+#endif
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3427,6 +3427,7 @@
   << SourceRange(D.getName().TemplateId->LAngleLoc,
  D.getName().TemplateId->RAngleLoc)
   << D.getName().TemplateId->LAngleLoc;
+  D.setInvalidType();
 }
 
 if (SS.isSet() && !SS.isInvalid()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 818e72d - [NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in

2022-03-22 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2022-03-22T18:39:16-07:00
New Revision: 818e72d1b09bc5fc3b7a2c9f90b981a9c0d2a5db

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

LOG: [NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in
TargetInfo.cpp

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 915ffca27bd1c..61d1444916150 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -100,6 +100,11 @@ Address ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address 
VAListAddr,
   return Address::invalid();
 }
 
+static llvm::Type *getVAListElementType(CodeGenFunction &CGF) {
+  return CGF.ConvertTypeForMem(
+  CGF.getContext().getBuiltinVaListType()->getPointeeType());
+}
+
 bool ABIInfo::isPromotableIntegerTypeForABI(QualType Ty) const {
   if (Ty->isPromotableIntegerType())
 return true;
@@ -375,7 +380,7 @@ static Address emitVoidPtrVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   }
 
   // Cast the address we've calculated to the right type.
-  llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy);
+  llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy), *ElementTy = DirectTy;
   if (IsIndirect)
 DirectTy = DirectTy->getPointerTo(0);
 
@@ -384,7 +389,7 @@ static Address emitVoidPtrVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
  SlotSizeAndAlign, AllowHigherAlign);
 
   if (IsIndirect) {
-Addr = Address::deprecated(CGF.Builder.CreateLoad(Addr), ValueInfo.Align);
+Addr = Address(CGF.Builder.CreateLoad(Addr), ElementTy, ValueInfo.Align);
   }
 
   return Addr;
@@ -688,11 +693,11 @@ Address EmitVAArgInstr(CodeGenFunction &CGF, Address 
VAListAddr, QualType Ty,
 auto TyInfo = CGF.getContext().getTypeInfoInChars(Ty);
 CharUnits TyAlignForABI = TyInfo.Align;
 
-llvm::Type *BaseTy =
-llvm::PointerType::getUnqual(CGF.ConvertTypeForMem(Ty));
+llvm::Type *ElementTy = CGF.ConvertTypeForMem(Ty);
+llvm::Type *BaseTy = llvm::PointerType::getUnqual(ElementTy);
 llvm::Value *Addr =
 CGF.Builder.CreateVAArg(VAListAddr.getPointer(), BaseTy);
-return Address::deprecated(Addr, TyAlignForABI);
+return Address(Addr, ElementTy, TyAlignForABI);
   } else {
 assert((AI.isDirect() || AI.isExtend()) &&
"Unexpected ArgInfo Kind in generic VAArg emitter!");
@@ -4826,7 +4831,7 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
&CGF, Address VAList,
 
   Builder.CreateCondBr(CC, UsingRegs, UsingOverflow);
 
-  llvm::Type *DirectTy = CGF.ConvertType(Ty);
+  llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy;
   if (isIndirect) DirectTy = DirectTy->getPointerTo(0);
 
   // Case 1: consume registers.
@@ -4835,8 +4840,8 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
&CGF, Address VAList,
 CGF.EmitBlock(UsingRegs);
 
 Address RegSaveAreaPtr = Builder.CreateStructGEP(VAList, 4);
-RegAddr = Address::deprecated(Builder.CreateLoad(RegSaveAreaPtr),
-  CharUnits::fromQuantity(8));
+RegAddr = Address(Builder.CreateLoad(RegSaveAreaPtr), CGF.Int8Ty,
+  CharUnits::fromQuantity(8));
 assert(RegAddr.getElementType() == CGF.Int8Ty);
 
 // Floating-point registers start after the general-purpose registers.
@@ -4883,14 +4888,15 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
&CGF, Address VAList,
 }
 
 Address OverflowAreaAddr = Builder.CreateStructGEP(VAList, 3);
-Address OverflowArea = Address::deprecated(
-Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), OverflowAreaAlign);
+Address OverflowArea =
+Address(Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), CGF.Int8Ty,
+OverflowAreaAlign);
 // Round up address of argument to alignment
 CharUnits Align = CGF.getContext().getTypeAlignInChars(Ty);
 if (Align > OverflowAreaAlign) {
   llvm::Value *Ptr = OverflowArea.getPointer();
-  OverflowArea = Address::deprecated(
-  emitRoundPointerUpToAlignment(CGF, Ptr, Align), Align);
+  OverflowArea = Address(emitRoundPointerUpToAlignment(CGF, Ptr, Align),
+ OverflowArea.getElementType(), Align);
 }
 
 MemAddr = Builder.CreateElementBitCast(OverflowArea, DirectTy);
@@ -4909,8 +4915,8 @@ Address PPC32_SVR4_ABIInfo::EmitVAArg(CodeGenFunction 
&CGF, Address VAList,
 
   // Load the pointer if the argument was passed indirectly.
   if (isIndirect) {
-Result = Address::deprecated(Builder.CreateLoad(Result, "aggr"),
- getContext().getTypeAlignInChars(Ty));
+Result = Address(

[PATCH] D122199: [NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in TargetInfo.cpp

2022-03-22 Thread Akira Hatanaka 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 rG818e72d1b09b: [NFC][Clang][OpaquePtr] Remove calls to 
Address::deprecated in (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122199

Files:
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -100,6 +100,11 @@
   return Address::invalid();
 }
 
+static llvm::Type *getVAListElementType(CodeGenFunction &CGF) {
+  return CGF.ConvertTypeForMem(
+  CGF.getContext().getBuiltinVaListType()->getPointeeType());
+}
+
 bool ABIInfo::isPromotableIntegerTypeForABI(QualType Ty) const {
   if (Ty->isPromotableIntegerType())
 return true;
@@ -375,7 +380,7 @@
   }
 
   // Cast the address we've calculated to the right type.
-  llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy);
+  llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy), *ElementTy = DirectTy;
   if (IsIndirect)
 DirectTy = DirectTy->getPointerTo(0);
 
@@ -384,7 +389,7 @@
  SlotSizeAndAlign, AllowHigherAlign);
 
   if (IsIndirect) {
-Addr = Address::deprecated(CGF.Builder.CreateLoad(Addr), ValueInfo.Align);
+Addr = Address(CGF.Builder.CreateLoad(Addr), ElementTy, ValueInfo.Align);
   }
 
   return Addr;
@@ -688,11 +693,11 @@
 auto TyInfo = CGF.getContext().getTypeInfoInChars(Ty);
 CharUnits TyAlignForABI = TyInfo.Align;
 
-llvm::Type *BaseTy =
-llvm::PointerType::getUnqual(CGF.ConvertTypeForMem(Ty));
+llvm::Type *ElementTy = CGF.ConvertTypeForMem(Ty);
+llvm::Type *BaseTy = llvm::PointerType::getUnqual(ElementTy);
 llvm::Value *Addr =
 CGF.Builder.CreateVAArg(VAListAddr.getPointer(), BaseTy);
-return Address::deprecated(Addr, TyAlignForABI);
+return Address(Addr, ElementTy, TyAlignForABI);
   } else {
 assert((AI.isDirect() || AI.isExtend()) &&
"Unexpected ArgInfo Kind in generic VAArg emitter!");
@@ -4826,7 +4831,7 @@
 
   Builder.CreateCondBr(CC, UsingRegs, UsingOverflow);
 
-  llvm::Type *DirectTy = CGF.ConvertType(Ty);
+  llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy;
   if (isIndirect) DirectTy = DirectTy->getPointerTo(0);
 
   // Case 1: consume registers.
@@ -4835,8 +4840,8 @@
 CGF.EmitBlock(UsingRegs);
 
 Address RegSaveAreaPtr = Builder.CreateStructGEP(VAList, 4);
-RegAddr = Address::deprecated(Builder.CreateLoad(RegSaveAreaPtr),
-  CharUnits::fromQuantity(8));
+RegAddr = Address(Builder.CreateLoad(RegSaveAreaPtr), CGF.Int8Ty,
+  CharUnits::fromQuantity(8));
 assert(RegAddr.getElementType() == CGF.Int8Ty);
 
 // Floating-point registers start after the general-purpose registers.
@@ -4883,14 +4888,15 @@
 }
 
 Address OverflowAreaAddr = Builder.CreateStructGEP(VAList, 3);
-Address OverflowArea = Address::deprecated(
-Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), OverflowAreaAlign);
+Address OverflowArea =
+Address(Builder.CreateLoad(OverflowAreaAddr, "argp.cur"), CGF.Int8Ty,
+OverflowAreaAlign);
 // Round up address of argument to alignment
 CharUnits Align = CGF.getContext().getTypeAlignInChars(Ty);
 if (Align > OverflowAreaAlign) {
   llvm::Value *Ptr = OverflowArea.getPointer();
-  OverflowArea = Address::deprecated(
-  emitRoundPointerUpToAlignment(CGF, Ptr, Align), Align);
+  OverflowArea = Address(emitRoundPointerUpToAlignment(CGF, Ptr, Align),
+ OverflowArea.getElementType(), Align);
 }
 
 MemAddr = Builder.CreateElementBitCast(OverflowArea, DirectTy);
@@ -4909,8 +4915,8 @@
 
   // Load the pointer if the argument was passed indirectly.
   if (isIndirect) {
-Result = Address::deprecated(Builder.CreateLoad(Result, "aggr"),
- getContext().getTypeAlignInChars(Ty));
+Result = Address(Builder.CreateLoad(Result, "aggr"), ElementTy,
+ getContext().getTypeAlignInChars(Ty));
   }
 
   return Result;
@@ -6060,7 +6066,7 @@
   Address BaseAddr(CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, reg_top, reg_offs),
CGF.Int8Ty, CharUnits::fromQuantity(IsFPR ? 16 : 8));
   Address RegAddr = Address::invalid();
-  llvm::Type *MemTy = CGF.ConvertTypeForMem(Ty);
+  llvm::Type *MemTy = CGF.ConvertTypeForMem(Ty), *ElementTy = MemTy;
 
   if (IsIndirect) {
 // If it's been passed indirectly (actually a struct), whatever we find from
@@ -6143,8 +6149,8 @@
 
 OnStackPtr = CGF.Builder.CreateIntToPtr(OnStackPtr, CGF.Int8PtrTy);
   }
-  Address OnStackAddr = Address::deprecated(
-  OnStackPtr, std::max(CharUnits::fromQuantity(8), TyAlign));
+  Add

[PATCH] D121969: Pass split-machine-functions to code generator when flto is used

2022-03-22 Thread Junfeng Dong via Phabricator via cfe-commits
junfd updated this revision to Diff 417458.
junfd added a comment.

Apply clang format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121969

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fsplit-machine-functions2.c


Index: clang/test/Driver/fsplit-machine-functions2.c
===
--- /dev/null
+++ clang/test/Driver/fsplit-machine-functions2.c
@@ -0,0 +1,12 @@
+// Test -fsplit-machine-functions option pass-through with lto
+// RUN: %clang -### -target x86_64-unknown-linux -flto 
-fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+
+// Test no pass-through to ld without lto
+// RUN: %clang -### -target x86_64-unknown-linux -fsplit-machine-functions %s 
2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
+
+// Test the mix of -fsplit-machine-functions and -fno-split-machine-functions
+// RUN: %clang -### -target x86_64-unknown-linux -flto 
-fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-NOPASS
+// RUN: %clang -### -target x86_64-unknown-linux -flto 
-fno-split-machine-functions -fsplit-machine-functions %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-PASS
+
+// CHECK-PASS:  "-plugin-opt=-split-machine-functions"
+// CHECK-NOPASS-NOT:"-plugin-opt=-split-machine-functions"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -574,6 +574,13 @@
 CmdArgs.push_back("-plugin-opt=-data-sections");
   }
 
+  // Pass an option to enable split machine functions.
+  if (auto *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
+options::OPT_fno_split_machine_functions)) {
+if (A->getOption().matches(options::OPT_fsplit_machine_functions))
+  CmdArgs.push_back("-plugin-opt=-split-machine-functions");
+  }
+
   if (Arg *A = getLastProfileSampleUseArg(Args)) {
 StringRef FName = A->getValue();
 if (!llvm::sys::fs::exists(FName))


Index: clang/test/Driver/fsplit-machine-functions2.c
===
--- /dev/null
+++ clang/test/Driver/fsplit-machine-functions2.c
@@ -0,0 +1,12 @@
+// Test -fsplit-machine-functions option pass-through with lto
+// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+
+// Test no pass-through to ld without lto
+// RUN: %clang -### -target x86_64-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
+
+// Test the mix of -fsplit-machine-functions and -fno-split-machine-functions
+// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
+// RUN: %clang -### -target x86_64-unknown-linux -flto -fno-split-machine-functions -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+
+// CHECK-PASS:  "-plugin-opt=-split-machine-functions"
+// CHECK-NOPASS-NOT:"-plugin-opt=-split-machine-functions"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -574,6 +574,13 @@
 CmdArgs.push_back("-plugin-opt=-data-sections");
   }
 
+  // Pass an option to enable split machine functions.
+  if (auto *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
+options::OPT_fno_split_machine_functions)) {
+if (A->getOption().matches(options::OPT_fsplit_machine_functions))
+  CmdArgs.push_back("-plugin-opt=-split-machine-functions");
+  }
+
   if (Arg *A = getLastProfileSampleUseArg(Args)) {
 StringRef FName = A->getValue();
 if (!llvm::sys::fs::exists(FName))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122278: [clang] Improve diagnostic for reopened inline namespace

2022-03-22 Thread Fabian Wolff via Phabricator via cfe-commits
fwolff created this revision.
fwolff added reviewers: rsmith, cor3ntin, mizvekov.
fwolff added a project: clang.
Herald added a project: All.
fwolff requested review of this revision.
Herald added a subscriber: cfe-commits.

Fixes #50794 . Reopening an 
inline namespace without the `inline` keyword yields a warning:

  inline namespace abc {}
  namespace abc {}
  namespace abc {}

  :2:11: warning: inline namespace reopened as a non-inline namespace 
[-Winline-namespace-reopened-noninline]
  namespace abc {}
^
  inline 
  :1:18: note: previous definition is here
  inline namespace abc {}
   ^
  :3:11: warning: inline namespace reopened as a non-inline namespace 
[-Winline-namespace-reopened-noninline]
  namespace abc {}
^
  inline 
  :2:11: note: previous definition is here
  namespace abc {}
^

But you'll notice that the second "previous definition is here" is actually not 
helpful, because this previous definition isn't explicitly marked `inline`. I 
think that the note should point to the first definition instead, which must 
always  have the `inline` if 
the namespace is supposed to be an inline namespace.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122278

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
  clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp


Index: clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -Wall -verify -std=c++11 %s
+
+// Regression test for #50794.
+
+// expected-note@+1 2 {{previous definition is here}}
+inline namespace X {}
+
+namespace X {} // expected-warning {{inline namespace reopened as a non-inline 
namespace}}
+namespace X {} // expected-warning {{inline namespace reopened as a non-inline 
namespace}}
Index: clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
===
--- clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
+++ clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
@@ -17,7 +17,7 @@
 // expected-warning@+2 {{inline nested namespace definition is incompatible 
with C++ standards before C++20}}
 #endif
 namespace valid1::valid2::inline valid3::inline valid4::valid5 {}
-// expected-note@-1 2 {{previous definition is here}}
+// expected-note@-1 4 {{previous definition is here}}
 
 #if __cplusplus <= 201402L
 // expected-warning@+3 {{nested namespace definition is a C++17 extension; 
define each namespace separately}}
@@ -34,7 +34,6 @@
 // expected-warning@+2 {{inline nested namespace definition is incompatible 
with C++ standards before C++20}}
 #endif
 namespace valid1::valid2::inline valid3::inline valid4::valid5 {}
-// expected-note@-1 2 {{previous definition is here}}
 
 namespace valid1 {
 namespace valid2 {
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -11059,6 +11059,12 @@
 NamespaceDecl *PrevNS) {
   assert(*IsInline != PrevNS->isInline());
 
+  if (auto *FirstNS = PrevNS->getFirstDecl())
+// 'inline' must appear on the original definition, but not necessarily
+// on all extension definitions, so the note should point to the first
+// definition to avoid confusion.
+PrevNS = FirstNS;
+
   if (PrevNS->isInline())
 // The user probably just forgot the 'inline', so suggest that it
 // be added back.


Index: clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-inline-namespace-reopened-twice.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -Wall -verify -std=c++11 %s
+
+// Regression test for #50794.
+
+// expected-note@+1 2 {{previous definition is here}}
+inline namespace X {}
+
+namespace X {} // expected-warning {{inline namespace reopened as a non-inline namespace}}
+namespace X {} // expected-warning {{inline namespace reopened as a non-inline namespace}}
Index: clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
===
--- clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
+++ clang/test/Parser/cxx2a-inline-nested-namespace-definition.cpp
@@ -17,7 +17,7 @@
 // expected-warning@+2 {{inline nested namespace definition is incompatible with C++ standards before C++20}}
 #endif
 namespace valid1::valid2::inline valid3::inline valid4::valid5 {}
-// expected-note@-1 2 {{previous definition is here}}
+// expected-note@-1 4 {{

[PATCH] D122175: [clang][extract-api] Enable processing of multiple headers

2022-03-22 Thread Juergen Ributzka via Phabricator via cfe-commits
ributzka added inline comments.



Comment at: clang/include/clang/SymbolGraph/FrontendActions.h:35
+  /// This is called before executing the action on any inputs. This merges all
+  /// the provided headers into a single header for processing.
+  bool PrepareToExecuteAction(CompilerInstance &CI) override;

This comment confused me a bit. By looking at the code further down, it only 
adds include statements for each header, which is different from merging all 
headers into a single header/buffer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122175

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


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:176-188
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ 
]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl &Matches) 
{
+  for (int i = Matches.size() - 1; i > 0; i--) {

owenpan wrote:
> If these are the same as in `Format.cpp` above, we should move the 
> definitions to `HeaderIncludes.h`.
> If these are the same as in `Format.cpp` above, we should move the 
> definitions to `HeaderIncludes.h`.

I meant we should remove the definitions from `Format.cpp` and add the 
declarations to `HeaderIncludes.h`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D122277: [analyzer] Fix crash in RangedConstraintManager.cpp

2022-03-22 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 417450.
vabridgers added a comment.

remove assert that was commented out


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122277

Files:
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/symbol-simplification-bo-div.c

Index: clang/test/Analysis/symbol-simplification-bo-div.c
===
--- /dev/null
+++ clang/test/Analysis/symbol-simplification-bo-div.c
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
+// RUN:-triple x86_64-pc-linux-gnu -verify
+
+// don't crash
+// expected-no-diagnostics
+
+int a, b;
+int c(void) {
+  unsigned d = a;
+  --d;
+  short e = b / b - a;
+  ++e;
+  return d <= 0 && e && e;
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -48,47 +48,48 @@
 
   if (const auto *SSE = dyn_cast(Sym)) {
 BinaryOperator::Opcode Op = SSE->getOpcode();
-assert(BinaryOperator::isComparisonOp(Op));
-
-// We convert equality operations for pointers only.
-if (Loc::isLocType(SSE->getLHS()->getType()) &&
-Loc::isLocType(SSE->getRHS()->getType())) {
-  // Translate "a != b" to "(b - a) != 0".
-  // We invert the order of the operands as a heuristic for how loop
-  // conditions are usually written ("begin != end") as compared to length
-  // calculations ("end - begin"). The more correct thing to do would be to
-  // canonicalize "a - b" and "b - a", which would allow us to treat
-  // "a != b" and "b != a" the same.
-
-  SymbolManager &SymMgr = getSymbolManager();
-  QualType DiffTy = SymMgr.getContext().getPointerDiffType();
-  SymbolRef Subtraction =
-  SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
-
-  const llvm::APSInt &Zero = getBasicVals().getValue(0, DiffTy);
-  Op = BinaryOperator::reverseComparisonOp(Op);
-  if (!Assumption)
-Op = BinaryOperator::negateComparisonOp(Op);
-  return assumeSymRel(State, Subtraction, Op, Zero);
-}
+if (BinaryOperator::isComparisonOp(Op)) {
+
+  // We convert equality operations for pointers only.
+  if (Loc::isLocType(SSE->getLHS()->getType()) &&
+  Loc::isLocType(SSE->getRHS()->getType())) {
+// Translate "a != b" to "(b - a) != 0".
+// We invert the order of the operands as a heuristic for how loop
+// conditions are usually written ("begin != end") as compared to length
+// calculations ("end - begin"). The more correct thing to do would be
+// to canonicalize "a - b" and "b - a", which would allow us to treat "a
+// != b" and "b != a" the same.
+
+SymbolManager &SymMgr = getSymbolManager();
+QualType DiffTy = SymMgr.getContext().getPointerDiffType();
+SymbolRef Subtraction =
+SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
+
+const llvm::APSInt &Zero = getBasicVals().getValue(0, DiffTy);
+Op = BinaryOperator::reverseComparisonOp(Op);
+if (!Assumption)
+  Op = BinaryOperator::negateComparisonOp(Op);
+return assumeSymRel(State, Subtraction, Op, Zero);
+  }
 
-if (BinaryOperator::isEqualityOp(Op)) {
-  SymbolManager &SymMgr = getSymbolManager();
+  if (BinaryOperator::isEqualityOp(Op)) {
+SymbolManager &SymMgr = getSymbolManager();
 
-  QualType ExprType = SSE->getType();
-  SymbolRef CanonicalEquality =
-  SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
+QualType ExprType = SSE->getType();
+SymbolRef CanonicalEquality =
+SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
 
-  bool WasEqual = SSE->getOpcode() == BO_EQ;
-  bool IsExpectedEqual = WasEqual == Assumption;
+bool WasEqual = SSE->getOpcode() == BO_EQ;
+bool IsExpectedEqual = WasEqual == Assumption;
 
-  const llvm::APSInt &Zero = getBasicVals().getValue(0, ExprType);
+const llvm::APSInt &Zero = getBasicVals().getValue(0, ExprType);
 
-  if (IsExpectedEqual) {
-return assumeSymNE(State, CanonicalEquality, Zero, Zero);
-  }
+if (IsExpectedEqual) {
+  return assumeSymNE(State, CanonicalEquality, Zero, Zero);
+}
 
-  return assumeSymEQ(State, CanonicalEquality, Zero, Zero);
+return assumeSymEQ(State, CanonicalEquality, Zero, Zero);
+  }
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122277: [analyzer] Fix crash in RangedConstraintManager.cpp

2022-03-22 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers created this revision.
vabridgers added reviewers: martong, NoQ.
Herald added subscribers: manas, steakhal, ASDenysPetrov, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a project: All.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change fixes a crash in RangedConstraintManager.cpp:assumeSym due to an
unhandled BO_Div case.

clang: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:51:

  virtual clang::ento::ProgramStateRef
  clang::ento::RangedConstraintManager::assumeSym(clang::ento::ProgramStateRef,
clang::ento::SymbolRef, bool):
  Assertion `BinaryOperator::isComparisonOp(Op)' failed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122277

Files:
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/symbol-simplification-bo-div.c

Index: clang/test/Analysis/symbol-simplification-bo-div.c
===
--- /dev/null
+++ clang/test/Analysis/symbol-simplification-bo-div.c
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core %s \
+// RUN:-triple x86_64-pc-linux-gnu -verify
+
+// don't crash
+// expected-no-diagnostics
+
+int a, b;
+int c(void) {
+  unsigned d = a;
+  --d;
+  short e = b / b - a;
+  ++e;
+  return d <= 0 && e && e;
+}
Index: clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -48,47 +48,49 @@
 
   if (const auto *SSE = dyn_cast(Sym)) {
 BinaryOperator::Opcode Op = SSE->getOpcode();
-assert(BinaryOperator::isComparisonOp(Op));
-
-// We convert equality operations for pointers only.
-if (Loc::isLocType(SSE->getLHS()->getType()) &&
-Loc::isLocType(SSE->getRHS()->getType())) {
-  // Translate "a != b" to "(b - a) != 0".
-  // We invert the order of the operands as a heuristic for how loop
-  // conditions are usually written ("begin != end") as compared to length
-  // calculations ("end - begin"). The more correct thing to do would be to
-  // canonicalize "a - b" and "b - a", which would allow us to treat
-  // "a != b" and "b != a" the same.
-
-  SymbolManager &SymMgr = getSymbolManager();
-  QualType DiffTy = SymMgr.getContext().getPointerDiffType();
-  SymbolRef Subtraction =
-  SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
-
-  const llvm::APSInt &Zero = getBasicVals().getValue(0, DiffTy);
-  Op = BinaryOperator::reverseComparisonOp(Op);
-  if (!Assumption)
-Op = BinaryOperator::negateComparisonOp(Op);
-  return assumeSymRel(State, Subtraction, Op, Zero);
-}
+// assert(BinaryOperator::isComparisonOp(Op));
+if (BinaryOperator::isComparisonOp(Op)) {
+
+  // We convert equality operations for pointers only.
+  if (Loc::isLocType(SSE->getLHS()->getType()) &&
+  Loc::isLocType(SSE->getRHS()->getType())) {
+// Translate "a != b" to "(b - a) != 0".
+// We invert the order of the operands as a heuristic for how loop
+// conditions are usually written ("begin != end") as compared to length
+// calculations ("end - begin"). The more correct thing to do would be
+// to canonicalize "a - b" and "b - a", which would allow us to treat "a
+// != b" and "b != a" the same.
+
+SymbolManager &SymMgr = getSymbolManager();
+QualType DiffTy = SymMgr.getContext().getPointerDiffType();
+SymbolRef Subtraction =
+SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
+
+const llvm::APSInt &Zero = getBasicVals().getValue(0, DiffTy);
+Op = BinaryOperator::reverseComparisonOp(Op);
+if (!Assumption)
+  Op = BinaryOperator::negateComparisonOp(Op);
+return assumeSymRel(State, Subtraction, Op, Zero);
+  }
 
-if (BinaryOperator::isEqualityOp(Op)) {
-  SymbolManager &SymMgr = getSymbolManager();
+  if (BinaryOperator::isEqualityOp(Op)) {
+SymbolManager &SymMgr = getSymbolManager();
 
-  QualType ExprType = SSE->getType();
-  SymbolRef CanonicalEquality =
-  SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
+QualType ExprType = SSE->getType();
+SymbolRef CanonicalEquality =
+SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
 
-  bool WasEqual = SSE->getOpcode() == BO_EQ;
-  bool IsExpectedEqual = WasEqual == Assumption;
+bool WasEqual = SSE->getOpcode() == BO_EQ;
+bool IsExpectedEqual = WasEqual == Assumption;
 
-  const llvm::APSInt &Zero = getBasicVals().getValue(0, ExprType);
+const llvm::APSInt &Zero = getBasicVals().g

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/Format.cpp:2692-2695
+  for (int i = Matches.size() - 1; i > 0; i--) {
+if (!Matches[i].empty())
+  return Matches[i];
+  }

I think you missed `Matches[0]`.



Comment at: clang/lib/Format/Format.cpp:3056
 
+inline StringRef trimInclude(StringRef IncludeName) {
+  return IncludeName.trim("\"<>;");

We should make it `static` if it's only used in this file.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:176-188
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ 
]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl &Matches) 
{
+  for (int i = Matches.size() - 1; i > 0; i--) {

If these are the same as in `Format.cpp` above, we should move the definitions 
to `HeaderIncludes.h`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D121927: [Clang] Work with multiple pragmas weak before definition

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast updated this revision to Diff 417443.
hubert.reinterpretcast added a comment.

- Address review comments: Add release notes, expand comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121927

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Weak.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/pragma-weak.c
  clang/test/PCH/pragma-weak-functional.c
  clang/test/PCH/pragma-weak-functional.h

Index: clang/test/PCH/pragma-weak-functional.h
===
--- /dev/null
+++ clang/test/PCH/pragma-weak-functional.h
@@ -0,0 +1,6 @@
+// Header for PCH test pragma-weak-functional.c
+
+#pragma weak undecfunc_alias2 = undecfunc
+#pragma weak undecfunc_alias4 = undecfunc_alias1
+#pragma weak undecfunc_alias3 = undecfunc_alias1
+#pragma weak undecfunc_alias1 = undecfunc
Index: clang/test/PCH/pragma-weak-functional.c
===
--- /dev/null
+++ clang/test/PCH/pragma-weak-functional.c
@@ -0,0 +1,17 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/pragma-weak-functional.h %s -verify -emit-llvm -o - | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -x c-header -emit-pch -o %t %S/pragma-weak-functional.h
+// RUN: %clang_cc1 -include-pch %t %s -verify -emit-llvm -o - | FileCheck %s
+
+// CHECK-DAG: @undecfunc_alias1 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias2 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias3 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias4 = weak{{.*}} alias void (), void ()* @undecfunc
+
+/ PR28611: Try multiple aliases of same undeclared symbol or alias
+void undecfunc_alias1(void);
+void undecfunc(void) { }
+// expected-warning@pragma-weak-functional.h:4 {{alias will always resolve to undecfunc}}
+// expected-warning@pragma-weak-functional.h:5 {{alias will always resolve to undecfunc}}
Index: clang/test/CodeGen/pragma-weak.c
===
--- clang/test/CodeGen/pragma-weak.c
+++ clang/test/CodeGen/pragma-weak.c
@@ -17,6 +17,10 @@
 // CHECK-DAG: @mix2 = weak{{.*}} alias void (), void ()* @__mix2
 // CHECK-DAG: @a1 = weak{{.*}} alias void (), void ()* @__a1
 // CHECK-DAG: @xxx = weak{{.*}} alias void (), void ()* @__xxx
+// CHECK-DAG: @undecfunc_alias1 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias2 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias3 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias4 = weak{{.*}} alias void (), void ()* @undecfunc
 
 
 
@@ -136,6 +140,15 @@
 __attribute((pure,noinline,const)) void __xxx(void) { }
 // CHECK: void @__xxx() [[RN:#[0-9]+]]
 
+/ PR28611: Try multiple aliases of same undeclared symbol or alias
+#pragma weak undecfunc_alias1 = undecfunc
+#pragma weak undecfunc_alias1 = undecfunc // Try specifying same alias/target pair a second time.
+#pragma weak undecfunc_alias3 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}
+#pragma weak undecfunc_alias4 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}
+#pragma weak undecfunc_alias2 = undecfunc
+void undecfunc_alias2(void);
+void undecfunc(void) { }
+
 / PR10878: Make sure we can call a weak alias
 void SHA512Pad(void *context) {}
 #pragma weak SHA384Pad = SHA512Pad
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4559,13 +4559,14 @@
   // entire table, since later PCH files in a PCH chain are only interested in
   // the results at the end of the chain.
   RecordData WeakUndeclaredIdentifiers;
-  for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) {
-IdentifierInfo *II = WeakUndeclaredIdentifier.first;
-WeakInfo &WI = WeakUndeclaredIdentifier.second;
-AddIdentifierRef(II, WeakUndeclaredIdentifiers);
-AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers);
-AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers);
-WeakUndeclaredIdentifiers.push_back(WI.getUsed());
+  for (const auto &WeakUndeclaredIdentifierList :
+   SemaRef.WeakUndeclaredIdentifiers) {
+const IdentifierInfo *const II = WeakUndeclaredIdentifierList.first;
+for (const auto &WI : WeakUndeclaredIdentifierList.second) {
+  AddIdentifierRef(II, WeakUndeclaredIdentifiers);
+  AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers);
+  AddSourceLocation(WI.getLocati

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-22 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa updated this revision to Diff 417439.
yihanaa added a comment.

Remove useless comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dump-struct-builtin.c

Index: clang/test/CodeGen/dump-struct-builtin.c
===
--- clang/test/CodeGen/dump-struct-builtin.c
+++ clang/test/CodeGen/dump-struct-builtin.c
@@ -126,7 +126,7 @@
   .a = 12,
   };
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U1]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[FIELD_U1]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U1]], i32 0, i32 0), i16 [[LOAD1]])
@@ -144,7 +144,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U2]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* [[FIELD_U2]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U2]], i32 0, i32 0), i16 [[LOAD1]])
@@ -162,7 +162,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U3]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* [[FIELD_U3]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U3]], i32 0, i32 0), i32 [[LOAD1]])
@@ -180,7 +180,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U4]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* [[FIELD_U4]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U4]], i32 0, i32 0), i32 [[LOAD1]])
@@ -198,7 +198,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U5]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* [[FIELD_U5]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U5]], i32 0, i32 0), i64 [[LOAD1]])
@@ -216,7 +216,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U6]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* [[FIELD_U6]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U6]], i32 0, i32 0), i64 [[LOAD1]])
@@ -234,7 +234,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U7]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @pri

[PATCH] D122202: [clang][extract-api] Add struct support

2022-03-22 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 417438.
zixuw marked 3 inline comments as done.
zixuw added a comment.

Address review issues: fix Symbol Graph struct kind identifiers and display 
names


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122202

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/struct.c

Index: clang/test/ExtractAPI/struct.c
===
--- /dev/null
+++ clang/test/ExtractAPI/struct.c
@@ -0,0 +1,303 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+/// Color in RGBA
+struct Color {
+  unsigned Red;
+  unsigned Green;
+  unsigned Blue;
+  /// Alpha channel for transparency
+  unsigned Alpha;
+};
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Red",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Green",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Blue",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Alpha",
+  "target": "c:@S@Color"
+}
+  ],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "struct"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Color"
+}
+  ],
+  "docComment": {
+"lines": [
+  {
+"range": {
+  "end": {
+"character": 18,
+"line": 1
+  },
+  "start": {
+"character": 5,
+"line": 1
+  }
+},
+"text": "Color in RGBA"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color"
+  },
+  "kind": {
+"displayName": "Structure",
+"identifier": "c.struct"
+  },
+  "location": {
+"character": 8,
+"line": 2,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Color"
+  }
+],
+"title": "Color"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Red"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color@FI@Red"
+  },
+  "kind": {
+"displayName": "Instance Property",
+"identifier": "c.property"
+  },
+  "location": {
+"character": 12,
+"line": 3,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Red"
+  }
+],
+"title": "Red"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Green"
+}
+  

[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-22 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

In D122248#3400408 , @xbolva00 wrote:

>>> the remaining changes are code formatting
>
> Please remove code formatting changes.

Okay, i have removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-22 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa updated this revision to Diff 417435.
yihanaa added a reviewer: xbolva00.
yihanaa added a comment.

Remove code formatting changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/dump-struct-builtin.c

Index: clang/test/CodeGen/dump-struct-builtin.c
===
--- clang/test/CodeGen/dump-struct-builtin.c
+++ clang/test/CodeGen/dump-struct-builtin.c
@@ -126,7 +126,7 @@
   .a = 12,
   };
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U1]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U1A, %struct.U1A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* [[FIELD_U1]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U1]], i32 0, i32 0), i16 [[LOAD1]])
@@ -144,7 +144,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U2]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U2A, %struct.U2A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* [[FIELD_U2]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i16, i16* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U2]], i32 0, i32 0), i16 [[LOAD1]])
@@ -162,7 +162,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U3]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U3A, %struct.U3A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* [[FIELD_U3]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U3]], i32 0, i32 0), i32 [[LOAD1]])
@@ -180,7 +180,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U4]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U4A, %struct.U4A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* [[FIELD_U4]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i32, i32* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[FORMAT_U4]], i32 0, i32 0), i32 [[LOAD1]])
@@ -198,7 +198,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U5]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U5A, %struct.U5A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* [[FIELD_U5]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U5]], i32 0, i32 0), i64 [[LOAD1]])
@@ -216,7 +216,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U6]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U6A, %struct.U6A* %a, i32 0, i32 0
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* [[FIELD_U6]], i32 0, i32 0))
   // CHECK: [[LOAD1:%[0-9]+]] = load i64, i64* [[RES1]],
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* [[FORMAT_U6]], i32 0, i32 0), i64 [[LOAD1]])
@@ -234,7 +234,7 @@
   };
 
   // CHECK: call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* [[STRUCT_STR_U7]], i32 0, i32 0))
-  // CHECK: [[RES1:%[0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, i32 0
+  // CHECK: [[RES1:%[−a−zA−Z._0-9]+]] = getelementptr inbounds %struct.U7A, %struct.U7A* %a, i32 0, 

[PATCH] D122111: [clang-tidy] Fix false positives in `misc-redundant-expression` check

2022-03-22 Thread Fabian Wolff via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
fwolff marked an inline comment as done.
Closed by commit rG07675b0b38e9: [clang-tidy] Fix false positives in 
`misc-redundant-expression` check (authored by fwolff).

Changed prior to commit:
  https://reviews.llvm.org/D122111?vs=417054&id=417433#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122111

Files:
  clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
@@ -369,6 +369,11 @@
 bool operator<=(const S &s, int i) { return s.x <= i; } // not modifying
 bool operator>=(const S &s, const int &i) { return s.x >= i; } // not modifying
 
+bool operator==(int i, const S &s) { return s == i; } // not modifying
+bool operator<(const int &i, const S &s) { return s > i; } // not modifying
+bool operator<=(const int &i, const S &s) { return s >= i; } // not modifying
+bool operator>(const int &i, const S &s) { return s < i; } // not modifying
+
 struct S2 {
   S2() { x = 1; }
   int x;
@@ -452,6 +457,25 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: logical expression is always false
   if (s1 >= 1 || s1 <= 1) return true;
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always true
+  if (s1 >= 2 && s1 <= 0) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always false
+
+  // Same test as above but with swapped LHS/RHS on one side of the logical operator.
+  if (1 == s1 && s1 == 1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: equivalent expression on both sides of logical operator
+  if (1 == s1 || s1 != 1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always true
+  if (1 < s1 && s1 < 1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: logical expression is always false
+  if (1 <= s1 || s1 <= 1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: logical expression is always true
+  if (2 < s1 && 0 > s1) return true;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: logical expression is always false
+
+  // Test for absence of false positives (issue #54011).
+  if (s1 == 1 || s1 == 2) return true;
+  if (s1 > 1 && s1 < 3) return true;
+  if (s1 >= 2 || s1 <= 0) return true;
 
   // Test for overloaded operators that may modify their params.
   S2 s2;
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -116,6 +116,9 @@
   ` when a pure virtual function
   overrided has a const return type. Removed the fix for a virtual function.
 
+- Fixed a false positive in :doc:`misc-redundant-expression `
+  involving overloaded comparison operators.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -569,6 +569,7 @@
   std::string SwapId = (Id + "-swap").str();
   std::string NegateId = (Id + "-negate").str();
   std::string OverloadId = (Id + "-overload").str();
+  std::string ConstId = (Id + "-const").str();
 
   const auto RelationalExpr = ignoringParenImpCasts(binaryOperator(
   isComparisonOperator(), expr().bind(Id),
@@ -600,7 +601,9 @@
   cxxOperatorCallExpr(
   hasAnyOverloadedOperatorName("==", "!=", "<", "<=", ">", ">="),
   // Filter noisy false positives.
-  unless(isMacro()), unless(isInTemplateInstantiation()))
+  unless(isMacro()), unless(isInTemplateInstantiation()),
+  anyOf(hasLHS(ignoringParenImpCasts(integerLiteral().bind(ConstId))),
+hasRHS(ignoringParenImpCasts(integerLiteral().bind(ConstId)
   .bind(OverloadId);
 
   return anyOf(RelationalExpr, CastExpr, NegateRelationalExpr,
@@ -674,16 +677,38 @@
 if (canOverloadedOperatorArgsBeModified(OverloadedOperatorExpr, false))
   return false;
 
+bool IntegerConstantIsFirstArg = false;
+
 if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
   if (!Arg->isValueDependent() &&
-  !Arg->isIntegerConstantExpr(*Result.Context))
-return false;
-}
-Symbol = OverloadedOperatorExpr->getArg(0);
+  !Arg->isIntegerConstantExpr(*Result.Context)) {
+IntegerConstantIsFirstArg = true;
+if (const auto *Arg =

[clang-tools-extra] 07675b0 - [clang-tidy] Fix false positives in `misc-redundant-expression` check

2022-03-22 Thread Fabian Wolff via cfe-commits

Author: Fabian Wolff
Date: 2022-03-23T00:32:45+01:00
New Revision: 07675b0b38e930c2c582122ac93efcdf7859a772

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

LOG: [clang-tidy] Fix false positives in `misc-redundant-expression` check

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index f8073bff5ea98..e68384348bd9c 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -569,6 +569,7 @@ matchRelationalIntegerConstantExpr(StringRef Id) {
   std::string SwapId = (Id + "-swap").str();
   std::string NegateId = (Id + "-negate").str();
   std::string OverloadId = (Id + "-overload").str();
+  std::string ConstId = (Id + "-const").str();
 
   const auto RelationalExpr = ignoringParenImpCasts(binaryOperator(
   isComparisonOperator(), expr().bind(Id),
@@ -600,7 +601,9 @@ matchRelationalIntegerConstantExpr(StringRef Id) {
   cxxOperatorCallExpr(
   hasAnyOverloadedOperatorName("==", "!=", "<", "<=", ">", ">="),
   // Filter noisy false positives.
-  unless(isMacro()), unless(isInTemplateInstantiation()))
+  unless(isMacro()), unless(isInTemplateInstantiation()),
+  anyOf(hasLHS(ignoringParenImpCasts(integerLiteral().bind(ConstId))),
+hasRHS(ignoringParenImpCasts(integerLiteral().bind(ConstId)
   .bind(OverloadId);
 
   return anyOf(RelationalExpr, CastExpr, NegateRelationalExpr,
@@ -674,16 +677,38 @@ static bool retrieveRelationalIntegerConstantExpr(
 if (canOverloadedOperatorArgsBeModified(OverloadedOperatorExpr, false))
   return false;
 
+bool IntegerConstantIsFirstArg = false;
+
 if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
   if (!Arg->isValueDependent() &&
-  !Arg->isIntegerConstantExpr(*Result.Context))
-return false;
-}
-Symbol = OverloadedOperatorExpr->getArg(0);
+  !Arg->isIntegerConstantExpr(*Result.Context)) {
+IntegerConstantIsFirstArg = true;
+if (const auto *Arg = OverloadedOperatorExpr->getArg(0)) {
+  if (!Arg->isValueDependent() &&
+  !Arg->isIntegerConstantExpr(*Result.Context))
+return false;
+} else
+  return false;
+  }
+} else
+  return false;
+
+Symbol = OverloadedOperatorExpr->getArg(IntegerConstantIsFirstArg ? 1 : 0);
 OperandExpr = OverloadedOperatorExpr;
 Opcode = 
BinaryOperator::getOverloadedOpcode(OverloadedOperatorExpr->getOperator());
 
-return BinaryOperator::isComparisonOp(Opcode);
+if (!retrieveIntegerConstantExpr(Result, Id, Value, ConstExpr))
+  return false;
+
+if (!BinaryOperator::isComparisonOp(Opcode))
+  return false;
+
+// The call site of this function expects the constant on the RHS,
+// so change the opcode accordingly.
+if (IntegerConstantIsFirstArg)
+  Opcode = BinaryOperator::reverseComparisonOp(Opcode);
+
+return true;
   } else {
 return false;
   }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 551e36dea0937..9e68fb1c7b0f8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -116,6 +116,9 @@ Changes in existing checks
   ` when a pure virtual 
function
   overrided has a const return type. Removed the fix for a virtual function.
 
+- Fixed a false positive in :doc:`misc-redundant-expression 
`
+  involving overloaded comparison operators.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
index 075c3aca9d03f..31fe8e0275b02 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc-redundant-expression.cpp
@@ -369,6 +369,11 @@ struct S {
 bool operator<=(const S &s, int i) { return s.x <= i; } // not modifying
 bool operator>=(const S &s, const int &i) { return s.x >= i; } // not modifying
 
+bool operator==(int i, const S &s) { return s == i; } // not modifying
+bool operator<(const int &i, const S &s) { return s > i; } // not modifying
+bool operator<=(const int &i, const S &s) { return s >= i; } // not modifying
+bool operator>(const int &i, const S &

[PATCH] D122271: [Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators

2022-03-22 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
xbolva00 added reviewers: efriedma, yonghong-song.
Herald added a project: All.
xbolva00 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang fails to diagnose:

  void test() {
  int j = 0;
  for (int i = 0; i < 1000; i++)
  j++;
  return;
  }

Reason: Missing support for UnaryOperator.

We should not warn with volatile variables... so add check for it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122271

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Sema/warn-unused-but-set-variables.c
  clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp


Index: clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
===
--- clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -7,6 +7,7 @@
 struct __attribute__((warn_unused)) SWarnUnused {
   int j;
   void operator +=(int);
+  void operator ++();
 };
 
 int f0() {
@@ -62,3 +63,9 @@
   SWarnUnused swu;
   swu += n;
 }
+
+template  void f5() {
+  // Don't warn for overloaded pre/post operators in template code.
+  SWarnUnused swu;
+  ++swu;
+}
Index: clang/test/Sema/warn-unused-but-set-variables.c
===
--- clang/test/Sema/warn-unused-but-set-variables.c
+++ clang/test/Sema/warn-unused-but-set-variables.c
@@ -73,3 +73,20 @@
   __attribute__((__cleanup__(for_cleanup))) int x;
   x = 5;
 }
+
+void f4(void) {
+  int x1 = 0; // expected-warning{{variable 'x1' set but not used}}
+  x1++;
+  int x2 = 0; // expected-warning{{variable 'x2' set but not used}}
+  x2--;
+  int x3 = 0; // expected-warning{{variable 'x3' set but not used}}
+  ++x3;
+  int x4 = 0; // expected-warning{{variable 'x4' set but not used}}
+  --x4;
+
+  volatile int v1 = 0;
+  ++v1;
+  typedef volatile int volint;
+  volint v2 = 0;
+  v2++;
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -7926,6 +7926,7 @@
 Expr *E, llvm::DenseMap &RefsMinusAssignments) {
   DeclRefExpr *LHS = nullptr;
   bool IsCompoundAssign = false;
+  bool isIncrementDecrementUnaryOp = false;
   if (BinaryOperator *BO = dyn_cast(E)) {
 if (BO->getLHS()->getType()->isDependentType() ||
 BO->getRHS()->getType()->isDependentType()) {
@@ -7940,6 +7941,11 @@
 if (COCE->getOperator() != OO_Equal)
   return;
 LHS = dyn_cast(COCE->getArg(0));
+  } else if (UnaryOperator *UO = dyn_cast(E)) {
+if (!UO->isIncrementDecrementOp())
+  return;
+isIncrementDecrementUnaryOp = true;
+LHS = dyn_cast(UO->getSubExpr());
   }
   if (!LHS)
 return;
@@ -7947,8 +7953,10 @@
   if (!VD)
 return;
   // Don't decrement RefsMinusAssignments if volatile variable with compound
-  // assignment (+=, ...) to avoid potential unused-but-set-variable warning.
-  if (IsCompoundAssign && VD->getType().isVolatileQualified())
+  // assignment (+=, ...) or increment/decrement unary operator to avoid
+  // potential unused-but-set-variable warning.
+  if ((IsCompoundAssign || isIncrementDecrementUnaryOp) &&
+  VD->getType().isVolatileQualified())
 return;
   auto iter = RefsMinusAssignments.find(VD);
   if (iter == RefsMinusAssignments.end())


Index: clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
===
--- clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -7,6 +7,7 @@
 struct __attribute__((warn_unused)) SWarnUnused {
   int j;
   void operator +=(int);
+  void operator ++();
 };
 
 int f0() {
@@ -62,3 +63,9 @@
   SWarnUnused swu;
   swu += n;
 }
+
+template  void f5() {
+  // Don't warn for overloaded pre/post operators in template code.
+  SWarnUnused swu;
+  ++swu;
+}
Index: clang/test/Sema/warn-unused-but-set-variables.c
===
--- clang/test/Sema/warn-unused-but-set-variables.c
+++ clang/test/Sema/warn-unused-but-set-variables.c
@@ -73,3 +73,20 @@
   __attribute__((__cleanup__(for_cleanup))) int x;
   x = 5;
 }
+
+void f4(void) {
+  int x1 = 0; // expected-warning{{variable 'x1' set but not used}}
+  x1++;
+  int x2 = 0; // expected-warning{{variable 'x2' set but not used}}
+  x2--;
+  int x3 = 0; // expected-warning{{variable 'x3' set but not used}}
+  ++x3;
+  int x4 = 0; // expected-warning{{variable 'x4' set but not used}}
+  --x4;
+
+  volatile int v1 = 0;
+  ++v1;
+  typedef volatile int volint;
+  volint v2 = 0;
+  v2++;
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -7926,6 +7926,7 @@
 Expr *E, llvm

[PATCH] D122202: [clang][extract-api] Add struct support

2022-03-22 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 417430.
zixuw added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122202

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/struct.c

Index: clang/test/ExtractAPI/struct.c
===
--- /dev/null
+++ clang/test/ExtractAPI/struct.c
@@ -0,0 +1,303 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+/// Color in RGBA
+struct Color {
+  unsigned Red;
+  unsigned Green;
+  unsigned Blue;
+  /// Alpha channel for transparency
+  unsigned Alpha;
+};
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Red",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Green",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Blue",
+  "target": "c:@S@Color"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Color@FI@Alpha",
+  "target": "c:@S@Color"
+}
+  ],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "struct"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Color"
+}
+  ],
+  "docComment": {
+"lines": [
+  {
+"range": {
+  "end": {
+"character": 18,
+"line": 1
+  },
+  "start": {
+"character": 5,
+"line": 1
+  }
+},
+"text": "Color in RGBA"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color"
+  },
+  "kind": {
+"displayName": "Struct",
+"identifier": "c.struct"
+  },
+  "location": {
+"character": 8,
+"line": 2,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Color"
+  }
+],
+"title": "Color"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Red"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color@FI@Red"
+  },
+  "kind": {
+"displayName": "Struct Field",
+"identifier": "c.struct.field"
+  },
+  "location": {
+"character": 12,
+"line": 3,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Red"
+  }
+],
+"title": "Red"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Green"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Color@FI@Green"
+  },
+  

[PATCH] D121969: Pass split-machine-functions to code generator when flto is used

2022-03-22 Thread Wenlei He via Phabricator via cfe-commits
wenlei added a comment.

The linter warning seems legit, otherwise looks good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121969

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


[PATCH] D121873: [clang][extract-api] Add enum support

2022-03-22 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 417424.
zixuw added a comment.

Rebase on main with changed and merged refactoring in D122160 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121873

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/ExtractAPI/enum.c

Index: clang/test/ExtractAPI/enum.c
===
--- /dev/null
+++ clang/test/ExtractAPI/enum.c
@@ -0,0 +1,505 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
+// RUN: %t/reference.output.json
+// RUN: %clang -extract-api -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: diff %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+/// Kinds of vehicles
+enum Vehicle {
+  Bicycle,
+  Car,
+  Train, ///< Move this to the top! -Sheldon
+  Ship,
+  Airplane,
+};
+
+enum Direction : unsigned char {
+  North = 0,
+  East,
+  South,
+  West
+};
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationhips": [
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Bicycle",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Car",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Train",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Ship",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Vehicle@Airplane",
+  "target": "c:@E@Vehicle"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Direction@North",
+  "target": "c:@E@Direction"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Direction@East",
+  "target": "c:@E@Direction"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Direction@South",
+  "target": "c:@E@Direction"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@E@Direction@West",
+  "target": "c:@E@Direction"
+}
+  ],
+  "symbols": [
+{
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "enum"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Vehicle"
+},
+{
+  "kind": "text",
+  "spelling": ": "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:i",
+  "spelling": "unsigned int"
+}
+  ],
+  "docComment": {
+"lines": [
+  {
+"range": {
+  "end": {
+"character": 22,
+"line": 1
+  },
+  "start": {
+"character": 5,
+"line": 1
+  }
+},
+"text": "Kinds of vehicles"
+  }
+]
+  },
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@E@Vehicle"
+  },
+  "kind": {
+"displayName": "Enumeration",
+"identifier": "c.enum"
+  },
+  "location": {
+"character": 6,
+"line": 2,
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Vehicle"
+  }
+],
+"title": "Vehicle"
+  }
+},
+{
+  "declarationFragments": [
+{
+  "kind": "identifier",
+  "spelling": "Bicycle"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@E@Vehicle@Bicycle"
+  },
+  "kind": {
+"displayName": "Enumeration Case",
+"identifier": "c.enum.case"
+  },
+  "location":

[PATCH] D120573: [OpenMP] Support runtime user conditions in metadirective

2022-03-22 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:1793
+void CodeGenFunction::EmitOMPMetaDirective(const OMPMetaDirective &D) {
+  llvm::BasicBlock *AfterBlock =
+  createBasicBlock("omp.meta.user.condition.after");

Why are you skipping the AST building part? Any special significance of this 
approach?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120573

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


[PATCH] D121951: [AMDGPU] Only warn when mixing printf and hostcall

2022-03-22 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D121951#3393928 , @sameerds wrote:

> In D121951#3392470 , @scott.linder 
> wrote:
>
>> In D121951#3391472 , @sameerds 
>> wrote:
>>
>>> The check for "__ockl_hostcall_internal" is not longer relevant with the 
>>> new hostcall attribute. Can we simply remove this check? What is the 
>>> situation where the warning is still useful?
>>
>> I wasn't aware of the new attribute, I'm happy to just delete it.
>
> Yeah, it happened in D119216 .
>
> But I am still curious about the check itself. Do we need to worry about a 
> situation where it is important to check whether OpenCL printf (non-hostcall) 
> and some other hostcall service are active in the same application?

I don't know how important it is to notify the user, but my understanding is 
pre-code-object-v5 we will use the same kernarg for both the printf and 
hostcall pointers. I don't know what actually happens (does the runtime notice 
it can't actually construct the kernarg and fail? does the code just fail when 
one of the two uses of the kernarg are incorrect?). Should I try to nail down 
exactly what currently happens?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121951

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


[PATCH] D122265: [Clang][NFC] Cleanup dcl.constexpr/p3 tests

2022-03-22 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Check for warnings instead of using -Werror, to avoid masking the

type of diagnostic emitted

- use different -verify labels instead of using conditional

compilation of diagnostic checks


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122265

Files:
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp

Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++11 -Werror=c++14-extensions -Werror=c++20-extensions -Werror=c++2b-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++14 -DCXX14 -Werror=c++20-extensions -Werror=c++2b-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++20 -DCXX14 -DCXX20 -Werror=c++2b-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++2b -DCXX14 -DCXX20 -DCXX2b %s
+// RUN: %clang_cc1 -fcxx-exceptions -verify=expected,beforecxx14,beforecxx20,beforecxx2b -std=c++11 %s
+// RUN: %clang_cc1 -fcxx-exceptions -verify=expected,aftercxx14,beforecxx20,beforecxx2b -std=c++14 %s
+// RUN: %clang_cc1 -fcxx-exceptions -verify=expected,aftercxx14,aftercxx20,beforecxx2b -std=c++20  %s
+// RUN: %clang_cc1 -fcxx-exceptions -verify=expected,aftercxx14,aftercxx20 -std=c++2b %s
 
 namespace N {
   typedef char C;
@@ -21,10 +21,7 @@
 };
 
 struct S {
-  virtual int ImplicitlyVirtual() const = 0;
-#if __cplusplus <= 201703L
-  // expected-note@-2 {{overridden virtual function}}
-#endif
+  virtual int ImplicitlyVirtual() const = 0; // beforecxx20-note {{overridden virtual function}}
 };
 struct SS : S {
   int ImplicitlyVirtual() const;
@@ -37,31 +34,17 @@
   constexpr int f() const;
 
   //  - it shall not be virtual; [until C++20]
-  virtual constexpr int ExplicitlyVirtual() const { return 0; }
-#if __cplusplus <= 201703L
-  // expected-error@-2 {{virtual function cannot be constexpr}}
-#endif
+  virtual constexpr int ExplicitlyVirtual() const { return 0; } // beforecxx20-error {{virtual function cannot be constexpr}}
 
-  constexpr int ImplicitlyVirtual() const { return 0; }
-#if __cplusplus <= 201703L
-  // expected-error@-2 {{virtual function cannot be constexpr}}
-#endif
+  constexpr int ImplicitlyVirtual() const { return 0; } // beforecxx20-error {{virtual function cannot be constexpr}}
 
-  virtual constexpr int OutOfLineVirtual() const;
-#if __cplusplus <= 201703L
-  // expected-error@-2 {{virtual function cannot be constexpr}}
-#endif
+  virtual constexpr int OutOfLineVirtual() const; // beforecxx20-error {{virtual function cannot be constexpr}}
 
   //  - its return type shall be a literal type;
   constexpr NonLiteral NonLiteralReturn() const { return {}; } // expected-error {{constexpr function's return type 'NonLiteral' is not a literal type}}
-  constexpr void VoidReturn() const { return; }
-#ifndef CXX14
-  // expected-error@-2 {{constexpr function's return type 'void' is not a literal type}}
-#endif
-  constexpr ~T();
-#ifndef CXX20
-  // expected-error@-2 {{destructor cannot be declared constexpr}}
-#endif
+  constexpr void VoidReturn() const { return; }// beforecxx14-error {{constexpr function's return type 'void' is not a literal type}}
+  constexpr ~T();  // beforecxx20-error {{destructor cannot be declared constexpr}}
+
   typedef NonLiteral F() const;
   constexpr F NonLiteralReturn2; // ok until definition
 
@@ -78,29 +61,21 @@
   // destructor can be defaulted. Destructors can't be constexpr since they
   // don't have a literal return type. Defaulted assignment operators can't be
   // constexpr since they can't be const.
-  constexpr T &operator=(const T&) = default;
-#ifndef CXX14
-  // expected-error@-2 {{an explicitly-defaulted copy assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}}
-  // expected-warning@-3 {{C++14}}
-#else
-  // expected-error@-5 {{defaulted definition of copy assignment operator is not constexpr}}
-#endif
+  constexpr T &operator=(const T &) = default; // beforecxx14-error {{an explicitly-defaulted copy assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}} \
+   // beforecxx14-warning {{C++14}} \
+   // aftercxx14-error{{defaulted definition of copy assignment operator is not constexpr}}
 };
 
 constexpr int T::OutOfLineVirtual() const { return 0; }
-#ifdef CXX14
+#if __cplusplus >= 201402L
 struct T2 {
   int n = 0;
   constexpr T2 &operator=(const T2&) = default; //

[PATCH] D120573: [OpenMP] Support runtime user conditions in metadirective

2022-03-22 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:1852
+int BestIdx = getBestVariantMatchForContext(StaticVMIs, OMPCtx);
+
+EmitStmt(StaticWhenClauses[BestIdx]->getDirective());

This approach is valid for static conditions. How you are going to take care of 
multiple dynamic/runtime conditions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120573

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


[PATCH] D118935: [SYCL] Disallow explicit casts between mismatching address spaces

2022-03-22 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk added a comment.

In D118935#3399095 , @Fznamznon wrote:

> I was under impression that the change is small and therefore easy to 
> understand. Would some comment like "SYCL re-uses OpenCL mode diagnostics to 
> emit errors in case the cast happens between disjoint address spaces" help?

Speaking only for myself, but it was clear to me that that's what it did. What 
wasn't clear to me was why that's okay, and that was because I was under the 
impression that there were ways around this in OpenCL that are unavailable in 
SYCL. What might have helped me was a comment not saying that the cast is also 
an error is OpenCL mode, but that there is no way at all to express the 
conversion in OpenCL mode. This is all in hindsight though, I am not sure to 
what extent my confusion was foreseeable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118935

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


[PATCH] D121824: [clang] Do not crash on arrow operator on dependent type.

2022-03-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Oops, forgot conclusion:
Thanks for incorporating my testcase, and the patch LGTM in its current form 
(most of the alternatives discussed also sound OK).
I'll leave to Haojian to stamp.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121824

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


[PATCH] D121824: [clang] Do not crash on arrow operator on dependent type.

2022-03-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a subscriber: rsmith.
sammccall added a comment.

In D121824#3400720 , @hokein wrote:

> Sorry, I thought this crash is fixed as a bonus effort by improving the AST 
> for reference-type var-decl.
>
> Beyond the crash cased by the dependent-type `RecoveryExpr` built in 
> `Sema::BuildDeclarationNameExpr`, I think there is another issue which is 
> worth fixing: whether we should mark the reference-type var-decl valid if it 
> doesn't have an initializer (either the initializer is not provided in the 
> source code or too broken to preserve). The current AST behavior is 
> inconsistent:

Agree about the inconsistency. I think ideally we'd move in the direction of 
*not* marking such things invalid. Here's the quote from Richard:

In D76831#1973053 , @rsmith wrote:

> Generally I think we should be moving towards finer-grained "invalid" / 
> "contains errors" bits, so that we can preserve as much of the AST as 
> possible and produce accurate diagnostics for independent errors wherever 
> possible. To that end, I think generally the "invalid" bit on a declaration 
> should concern *only* the "declaration" part of that declaration (how it's 
> seen from other contexts that don't "look too closely"). So in particular:
>
> - The initializer of a variable should play no part in its "invalid" bit. If 
> the initializer expression is marked as "contains errors", then things that 
> care about the initializer (in particular, constant evaluation and any 
> diagnostics that look into the initializer) may need to bail out, but we 
> should be able to form a `DeclRefExpr` referring to that variable -- even if 
> (say) the variable is `constexpr`. Exception: if the variable has a deduced 
> type and the type can't be deduced due to an invalid initializer, then the 
> declaration should be marked invalid.
> - The body of a function should play no part in its "invalid" bit. (This came 
> up in a different code review recently.)

But practically, it's at least as important to make changes that make 
diagnostics better and not worse, and don't introduce new crashes. This is hard 
to do while keeping scope limited, so I'm OK with bending principle too.

> Another option would be to mark `a` valid regardless of the initializer. 
> Pros: preserve more AST nodes for `a`; the valid bit are consistent among 
> three cases. Cons: unknown? whether it'll break some subtle invariants in 
> clang; the bogus `requires an initializer` diagnostic is still there.
> But yeah, this is a separate issue, we should fix the crash first.

+1




Comment at: clang/lib/Sema/TreeTransform.h:14708
   } else if (Op == OO_Arrow) {
+if (First->getType()->isDependentType())
+  return ExprError();

hokein wrote:
> I'm not sure this is the only place triggering the crash, it looks like that 
> we're fixing a symptom.
> 
> While here, `First` refers to a dependent-type `RecoveryExpr` (which is built 
> from the code path: `TransformDeclRefExpr` -> `RebuildDeclRefExpr`-> 
> `Sema::BuildDeclarationNameExpr`). So I think we have a high chance that the 
> `RecoveryExpr` will spread multiple places in the `TreeTransform` and cause 
> similar violations in other places.
> 
> A safe fix will be to not build the `RecoveryExpr` in 
> `TreeTransform::TransformDeclRefExpr` -- `Sema::BuildDeclarationNameExpr` has 
> a `AcceptInvalidDecl` parameter (by default it is false), we could reuse it 
> to control whether we should build a `RecoveryExpr`.
>  
I agree with this FWIW: in principle it makes sense to have RecoveryExpr 
produced in template instantiation, in practice we probably haven't weakened 
the assumptions in template instantiation enough to do so safely, in the way 
that we have for "regular" sema.

We could try to do so in an ongoing way, but at least for syntax based tools 
like clangd the payoff won't be large as long as we keep mostly ignoring 
template instantiations.

That said, the current form of the patch is simple and fixes the crash in an 
obvious way, if this really is a more general problem then we'll see it again 
and have more data to generalize.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121824

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


[PATCH] D120134: [analyzer] refactor makeIntValWithPtrWidth, remove getZeroWithPtrWidth (NFC)

2022-03-22 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers marked an inline comment as done.
vabridgers added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp:2570
+  State, TotalSize.castAs(),
+  svalBuilder.makeIntValWithPtrWidth(Arg1->getType(), 0));
 

NoQ wrote:
> steakhal wrote:
> > We peobably wanted to use a different tspe for this expressuon. 
> > 'getArrayIndexType()' is a better fit IMO.
> > We shall see.
> `TotalSize` is literally `size_t` so `ASTContext.getSizeType()` is the right 
> type. `getArrayIndexType()` is signed so it's different.
Thanks @NoQ , the review is update. Best


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120134

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


[PATCH] D120134: [analyzer] refactor makeIntValWithPtrWidth, remove getZeroWithPtrWidth (NFC)

2022-03-22 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 417415.
vabridgers added a comment.

update per @NoQ's latest comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120134

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/SValBuilder.cpp


Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -742,9 +742,6 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
-  //and `getIntWithPtrWidth()` functions to prevent future
-  //confusion
   if (!Ty->isReferenceType())
 return makeNonLoc(Sym, BO_NE, BasicVals.getZeroWithTypeSize(Ty),
   CastTy);
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1344,8 +1344,9 @@
 case Stmt::GNUNullExprClass: {
   // GNU __null is a pointer-width integer, not an actual pointer.
   ProgramStateRef state = Pred->getState();
-  state = state->BindExpr(S, Pred->getLocationContext(),
-  svalBuilder.makeIntValWithPtrWidth(0, false));
+  state = state->BindExpr(
+  S, Pred->getLocationContext(),
+  svalBuilder.makeIntValWithWidth(getContext().VoidPtrTy, 0));
   Bldr.generateNode(S, Pred, state);
   break;
 }
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2608,8 +2608,9 @@
 
   // Compare the size argument to 0.
   DefinedOrUnknownSVal SizeZero =
-svalBuilder.evalEQ(State, TotalSize.castAs(),
-   svalBuilder.makeIntValWithPtrWidth(0, false));
+  svalBuilder.evalEQ(State, TotalSize.castAs(),
+ svalBuilder.makeIntValWithWidth(
+ svalBuilder.getContext().getSizeType(), 0));
 
   ProgramStateRef StatePtrIsNull, StatePtrNotNull;
   std::tie(StatePtrIsNull, StatePtrNotNull) = State->assume(PtrEQ);
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -332,9 +332,8 @@
 return nonloc::ConcreteInt(BasicVals.getIntValue(integer, isUnsigned));
   }
 
-  NonLoc makeIntValWithPtrWidth(uint64_t integer, bool isUnsigned) {
-return nonloc::ConcreteInt(
-BasicVals.getIntWithPtrWidth(integer, isUnsigned));
+  NonLoc makeIntValWithWidth(QualType ptrType, uint64_t integer) {
+return nonloc::ConcreteInt(BasicVals.getValue(integer, ptrType));
   }
 
   NonLoc makeLocAsInteger(Loc loc, unsigned bits) {
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -220,14 +220,6 @@
 return getValue(0, Ctx.getTypeSize(T), true);
   }
 
-  const llvm::APSInt &getZeroWithPtrWidth(bool isUnsigned = true) {
-return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
-  }
-
-  const llvm::APSInt &getIntWithPtrWidth(uint64_t X, bool isUnsigned) {
-return getValue(X, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned);
-  }
-
   const llvm::APSInt &getTruthValue(bool b, QualType T) {
 return getValue(b ? 1 : 0, Ctx.getIntWidth(T),
 T->isUnsignedIntegerOrEnumerationType());


Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -742,9 +742,6 @@
   // This change is needed for architectures with varying
   // pointer widths. See the amdgcn opencl reproducer with
   // this change as an example: solver-sym-simplification-ptr-bool.cl
-  // FIXME: Cleanup remainder of `getZeroWithPtrWidth ()`
-  //and `getIntWithPtrWidth()` functions to preven

[PATCH] D121078: Replace links to archived mailing lists by links to Discourse forums

2022-03-22 Thread Danny Mösch via Phabricator via cfe-commits
SimplyDanny added a comment.

@tonic, can you please have another look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121078

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


[PATCH] D121969: Pass split-machine-functions to code generator when flto is used

2022-03-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy accepted this revision.
hoy added a comment.
This revision is now accepted and ready to land.

lgtm, thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121969

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


[PATCH] D121328: Disable -Wmissing-prototypes for internal linkage functions that aren't explicitly marked "static"""

2022-03-22 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

Given that this is an error `error: functions cannot be declared in an 
anonymous struct` (thus you can assume that function declarations inside a 
struct imply that the struct MUST have a linkage name)

  struct {
static int foo();
  };

then I don't think there's any conceptual reason why we cannot emit the desired 
diagnostics without the undesired side-effect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121328

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


[PATCH] D121824: [clang] Do not crash on arrow operator on dependent type.

2022-03-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Sorry, I thought this crash is fixed as a bonus effort by improving the AST for 
reference-type var-decl.

Beyond the crash cased by the dependent-type `RecoveryExpr` built in 
`Sema::BuildDeclarationNameExpr`, I think there is another issue which is worth 
fixing: whether we should mark the reference-type var-decl valid if it doesn't 
have an initializer (either the initializer is not provided in the source code 
or too broken to preserve). The current AST behavior is inconsistent:

  int &a; // var-decl a is invalid without an initializer
  int &b = undefine[]; // var-decl b is valid without an initializer
  int &c = undefine; // var-decl c is valid with a recovery-expr initializer

From the AST point of view, there is no difference between `a` and `b`, they 
both don't have an initializer, but their valid bits are different. IMO marking 
b invalid is an improvement, the valid bit is consistent for refer-type 
var-decls without initializers; it avoids the bogus `requires an initializer` 
diagnostic during template instantiations; as a bonus, it seems to "fix" the 
crash (at least for the original testcase).

Another option would be to mark `a` valid regardless of the initializer. Pros: 
preserve more AST nodes for `a`; the valid bit are consistent among three 
cases. Cons: unknown? whether it'll break some subtle invariants in clang; the 
bogus `requires an initializer` diagnostic is still there.

But yeah, this is a separate issue, we should fix the crash first.




Comment at: clang/lib/Sema/TreeTransform.h:14708
   } else if (Op == OO_Arrow) {
+if (First->getType()->isDependentType())
+  return ExprError();

I'm not sure this is the only place triggering the crash, it looks like that 
we're fixing a symptom.

While here, `First` refers to a dependent-type `RecoveryExpr` (which is built 
from the code path: `TransformDeclRefExpr` -> `RebuildDeclRefExpr`-> 
`Sema::BuildDeclarationNameExpr`). So I think we have a high chance that the 
`RecoveryExpr` will spread multiple places in the `TreeTransform` and cause 
similar violations in other places.

A safe fix will be to not build the `RecoveryExpr` in 
`TreeTransform::TransformDeclRefExpr` -- `Sema::BuildDeclarationNameExpr` has a 
`AcceptInvalidDecl` parameter (by default it is false), we could reuse it to 
control whether we should build a `RecoveryExpr`.
 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121824

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


[clang] b62d402 - [NFC][clang][extract-api] Use proper name string for Objective-C language

2022-03-22 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-22T14:18:26-07:00
New Revision: b62d40216f4742d46b1d2942617cf567e74272c4

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

LOG: [NFC][clang][extract-api] Use proper name string for Objective-C language

Change the Symbol Graph serializer for ExtractAPI to use `objective-c`
for the language name string for Objective-C, to align with clang
frontend standards.

Added: 


Modified: 
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index b0bc2034fe970..b12d911390426 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -159,7 +159,7 @@ StringRef getLanguageName(const LangOptions &LangOpts) {
   case Language::C:
 return "c";
   case Language::ObjC:
-return "objc";
+return "objective-c";
 
   // Unsupported language currently
   case Language::CXX:



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


[PATCH] D122255: Meta directive runtime support

2022-03-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

In D122255#3400636 , 
@abidmalikwaterloo wrote:

> Is it okay if I can put comments on the patch?

Not sure what you mean but feel free.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122255

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


[PATCH] D121927: [Clang] Work with multiple pragmas weak before definition

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/include/clang/Sema/Weak.h:33
+  : alias(Alias), loc(Loc) {}
+  inline IdentifierInfo *getAlias() const { return alias; }
   inline SourceLocation getLocation() const { return loc; }

hubert.reinterpretcast wrote:
> aaron.ballman wrote:
> > Would it be onerous to make the return type be `const IdentifierInfo *` 
> > given that the function is `const`? (If it is, just ignore the suggestion 
> > -- I love adding const correctness where we can get it basically for free.)
> It's not free but I can post an NFC patch to add the `const` through. On the 
> chain of calls that `const` needs to be added to, the pointer eventually 
> feeds a `DeclarationName` (which already takes `const IdentifierInfo *`).
https://reviews.llvm.org/D122261 has the NFC patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121927

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


[PATCH] D122261: [Clang][NFC] Some `const` for `IdentifierInfo *`s feeding `DeclarationName`

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast created this revision.
hubert.reinterpretcast added a reviewer: aaron.ballman.
Herald added a project: All.
hubert.reinterpretcast requested review of this revision.
Herald added a project: clang.

`DeclarationName` already takes `const IdentifierInfo *`. Propagate the `const` 
outward to various APIs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122261

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -9016,8 +9016,8 @@
 
 /// DeclClonePragmaWeak - clone existing decl (maybe definition),
 /// \#pragma weak needs a non-definition decl and source may not have one.
-NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
-  SourceLocation Loc) {
+NamedDecl *Sema::DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II,
+ SourceLocation Loc) {
   assert(isa(ND) || isa(ND));
   NamedDecl *NewD = nullptr;
   if (auto *FD = dyn_cast(ND)) {
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -2020,7 +2020,7 @@
 
 VarDecl::VarDecl(Kind DK, ASTContext &C, DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
- IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
+ const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
  StorageClass SC)
 : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc),
   redeclarable_base(C) {
@@ -2035,10 +2035,9 @@
   // Everything else is implicitly initialized to false.
 }
 
-VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC,
- SourceLocation StartL, SourceLocation IdL,
- IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
- StorageClass S) {
+VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation StartL,
+ SourceLocation IdL, const IdentifierInfo *Id,
+ QualType T, TypeSourceInfo *TInfo, StorageClass S) {
   return new (C, DC) VarDecl(Var, C, DC, StartL, IdL, Id, T, TInfo, S);
 }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10175,7 +10175,7 @@
   void ActOnPragmaVisibility(const IdentifierInfo* VisType,
  SourceLocation PragmaLoc);
 
-  NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
+  NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II,
  SourceLocation Loc);
   void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W);
 
Index: clang/include/clang/AST/Decl.h
===
--- clang/include/clang/AST/Decl.h
+++ clang/include/clang/AST/Decl.h
@@ -1041,7 +1041,7 @@
   };
 
   VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
-  SourceLocation IdLoc, IdentifierInfo *Id, QualType T,
+  SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
   TypeSourceInfo *TInfo, StorageClass SC);
 
   using redeclarable_base = Redeclarable;
@@ -1071,8 +1071,8 @@
 
   static VarDecl *Create(ASTContext &C, DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
- IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
- StorageClass S);
+ const IdentifierInfo *Id, QualType T,
+ TypeSourceInfo *TInfo, StorageClass S);
 
   static VarDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -9016,8 +9016,8 @@
 
 /// DeclClonePragmaWeak - clone existing decl (maybe definition),
 /// \#pragma weak needs a non-definition decl and source may not have one.
-NamedDecl * Sema::DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II,
-  SourceLocation Loc) {
+NamedDecl *Sema::DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II,
+ SourceLocation Loc) {
   assert(isa(ND) || isa(ND));
   NamedDecl *NewD = nullptr;
   if (auto *FD = dyn_cast(ND)) {
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -2020,7 +2020,7 @@
 
 VarDecl::VarDecl(Kind DK, ASTContext &C

[PATCH] D122258: [MC][RFC] Omit DWARF unwind info if compact unwind is present for all archs

2022-03-22 Thread Jez Ng via Phabricator via cfe-commits
int3 added inline comments.



Comment at: llvm/lib/MC/MCObjectFileInfo.cpp:66-67
 
-  if (T.isWatchABI())
-OmitDwarfIfHaveCompactUnwind = true;
 

@MaskRay

> I vaguely remember there is a place where DWARF unwind info is enabled for 
> all but few environments (like watchOS). Where is it?

here :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122258

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


[PATCH] D122258: [MC][RFC] Omit DWARF unwind info if compact unwind is present for all archs

2022-03-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> Previously, omitting unnecessary DWARF unwinds was only done for watchOS,

I have looked at compact unwind descriptors in 2020-11 to write 
https://maskray.me/blog/2020-11-08-stack-unwinding#compact-unwind-descriptors
I vaguely remember there is a place where DWARF unwind info is enabled for all 
but few environments (like watchOS). Where is it?
My conjecture is that it may be related to the fact that the compact unwind 
descriptor does not support async unwind tables well and there may be cases 
needing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122258

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


[clang] 2cedaee - [OpenMP] Initial parsing/sema for the 'omp parallel loop' construct

2022-03-22 Thread Mike Rice via cfe-commits

Author: Mike Rice
Date: 2022-03-22T13:55:47-07:00
New Revision: 2cedaee6f7387b39f7a534883050d66fd78e15a4

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

LOG: [OpenMP] Initial parsing/sema for the 'omp parallel loop' construct

  Adds basic parsing/sema/serialization support for the
  #pragma omp parallel loop directive.

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

Added: 
clang/test/OpenMP/parallel_generic_loop_ast_print.cpp
clang/test/OpenMP/parallel_generic_loop_messages.cpp

Modified: 
clang/include/clang-c/Index.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/AST/StmtOpenMP.h
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/StmtOpenMP.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/Analysis/cfg-openmp.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 23ecac4895bd9..4783744359eec 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2608,7 +2608,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPTargetTeamsGenericLoopDirective = 297,
 
-  CXCursor_LastStmt = CXCursor_OMPTargetTeamsGenericLoopDirective,
+  /** OpenMP parallel loop directive.
+   */
+  CXCursor_OMPParallelGenericLoopDirective = 298,
+
+  CXCursor_LastStmt = CXCursor_OMPParallelGenericLoopDirective,
 
   /**
* Cursor that represents the translation unit itself.

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index b614b6a8bebe0..ceb874598aded 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3080,6 +3080,8 @@ DEF_TRAVERSE_STMT(OMPTeamsGenericLoopDirective,
 DEF_TRAVERSE_STMT(OMPTargetTeamsGenericLoopDirective,
   { TRY_TO(TraverseOMPExecutableDirective(S)); })
 
+DEF_TRAVERSE_STMT(OMPParallelGenericLoopDirective,
+  { TRY_TO(TraverseOMPExecutableDirective(S)); })
 // OpenMP clauses.
 template 
 bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) {

diff  --git a/clang/include/clang/AST/StmtOpenMP.h 
b/clang/include/clang/AST/StmtOpenMP.h
index 82d9a69035abd..9178b47a0b5f4 100644
--- a/clang/include/clang/AST/StmtOpenMP.h
+++ b/clang/include/clang/AST/StmtOpenMP.h
@@ -1528,6 +1528,7 @@ class OMPLoopDirective : public OMPLoopBasedDirective {
T->getStmtClass() == OMPGenericLoopDirectiveClass ||
T->getStmtClass() == OMPTeamsGenericLoopDirectiveClass ||
T->getStmtClass() == OMPTargetTeamsGenericLoopDirectiveClass ||
+   T->getStmtClass() == OMPParallelGenericLoopDirectiveClass ||
T->getStmtClass() == OMPParallelMasterTaskLoopDirectiveClass ||
T->getStmtClass() == OMPParallelMasterTaskLoopSimdDirectiveClass ||
T->getStmtClass() == OMPDistributeDirectiveClass ||
@@ -5701,6 +5702,71 @@ class OMPTargetTeamsGenericLoopDirective final : public 
OMPLoopDirective {
 return T->getStmtClass() == OMPTargetTeamsGenericLoopDirectiveClass;
   }
 };
+
+/// This represents '#pragma omp parallel loop' directive.
+///
+/// \code
+/// #pragma omp parallel loop private(a,b) order(concurrent)
+/// \endcode
+/// In this example directive '#pragma omp parallel loop' has
+/// clauses 'private' with the variables 'a' and 'b', and order(concurrent).
+///
+class OMPParallelGenericLoopDirective final : public OMPLoopDirective {
+  friend class ASTStmtReader;
+  friend class OMPExecutableDirective;
+  /// Build directive with the given start and end location.
+  ///
+  /// \param StartLoc Starting location of the directive kind.
+  /// \param EndLoc Ending location of the directive.
+  /// \param CollapsedNum Number of collapsed nested loops.
+  ///
+  OMPParallelGenericLoopDirective(SourceLocation StartLoc,
+  SourceLocation EndLoc, unsigned CollapsedNum)
+  : OMPLoopDirective(OMPParallelGenericLoopDirectiveClass,
+ llvm::omp::OMPD_parallel_loop, StartLoc, EndLoc,
+ CollapsedNum) {}
+
+  /// Build an empty directive.
+  ///
+  /// \param CollapsedNum Number of collapsed nested loops.
+  /

[PATCH] D122255: Meta directive runtime support

2022-03-22 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added a comment.

Is it okay if I can put comments on the patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122255

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


[PATCH] D121525: [clang][deps] Create lit substitution for deps-to-rsp

2022-03-22 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121525

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


[PATCH] D120573: [OpenMP] Support runtime user conditions in metadirective

2022-03-22 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added a comment.

Does anyone implement/take care of the "otherwise" clause? If I am correct, 
OpenMP 5.2 supports otherwise instead of the default for meta directive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120573

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


[PATCH] D122258: [MC][RFC] Omit DWARF unwind info if compact unwind is present for all archs

2022-03-22 Thread Jez Ng via Phabricator via cfe-commits
int3 created this revision.
int3 added reviewers: davide, kledzik, lhames.
Herald added subscribers: StephenFan, cmtice, hiraditya, kristof.beyls, emaste.
Herald added a reviewer: JDevlieghere.
Herald added a reviewer: jhenderson.
Herald added a project: All.
int3 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

Diff is not yet complete, but I'm looking for some feedback...

Previously, omitting unnecessary DWARF unwinds was only done for
watchOS, but I've heard that it might be possible to do this for all
archs. @davide, @kledzik -- do you see any issues with this?

Motivation: I'm working on adding support for `__eh_frame` to LLD, but
I'm concerned that we would suffer a perf hit. Processing compact unwind
is already expensive, and that's a simpler format than EH frames. Given
that MC currently produces one EH frame entry for every compact unwind
entry, I don't think processing them will be cheap. I tried to do
something clever on LLD's end to drop the unnecessary EH frames at parse
time, but this made the code significantly more complex. So I'm looking
at fixing this at the MC level instead.

Code-wise, I'm a bit uncertain about the right approach here. A good
number of tests are failing. Some of them are tests that expected EH
frames to always be generated, and I figure we have two options here:
change the tests to have unwind info that can't be encoded with compact
unwind, or pass a flag to force EH frames to always be emitted. I've
done the former because it seems slightly easier than figuring out what
each test was supposed to do.

The other source of failure appears to stem from `lli` failing to catch
exceptions. Based on this comment 
,
I believe the root cause is that libunwind is unable to load compact
unwind dynamically. (I believe this limitation applies not just to MCJIT but to
ORC and the regular interpreter as well -- @lhames, would you be able to
confirm?)

In both cases, we need some way to tell `MCObjectFileInfo` to emit EH
frames. I'm currently doing that via
`MCContext::getGenDwarfForAssembly`. I'm not super familiar with the MC
code, though, so I'm wondering if I should use a different flag, or if I
should even be using `MCContext` here. Pointers will be appreciated!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122258

Files:
  clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
  llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
  llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
  llvm/lib/MC/MCDwarf.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/test/ExecutionEngine/MCJIT/eh-lg-pic.ll
  llvm/test/ExecutionEngine/MCJIT/eh.ll
  llvm/test/ExecutionEngine/MCJIT/multi-module-eh-a.ll
  llvm/test/ExecutionEngine/MCJIT/remote/eh.ll
  llvm/test/ExecutionEngine/OrcLazy/minimal-throw-catch.ll
  llvm/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s
  llvm/test/MC/ELF/cfi-version.ll
  llvm/test/MC/X86/i386-darwin-frame-register.ll
  llvm/test/tools/dsymutil/X86/frame-1.test
  llvm/test/tools/dsymutil/X86/frame-2.test
  llvm/test/tools/llvm-dwarfdump/X86/debug_frame_offset.test
  llvm/tools/llc/llc.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp

Index: llvm/tools/llvm-mc/llvm-mc.cpp
===
--- llvm/tools/llvm-mc/llvm-mc.cpp
+++ llvm/tools/llvm-mc/llvm-mc.cpp
@@ -429,6 +429,7 @@
   // MCObjectFileInfo needs a MCContext reference in order to initialize itself.
   MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), &SrcMgr,
 &MCOptions);
+  Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
   std::unique_ptr MOFI(
   TheTarget->createMCObjectFileInfo(Ctx, PIC, LargeCodeModel));
   Ctx.setObjectFileInfo(MOFI.get());
@@ -436,7 +437,6 @@
   if (SaveTempLabels)
 Ctx.setAllowTemporaryLabels(false);
 
-  Ctx.setGenDwarfForAssembly(GenDwarfForAssembly);
   // Default to 4 for dwarf version.
   unsigned DwarfVersion = MCOptions.DwarfVersion ? MCOptions.DwarfVersion : 4;
   if (DwarfVersion < 2 || DwarfVersion > 5) {
Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -694,9 +694,10 @@
codegen::getFileType(), NoVerify, MMIWP)) {
   reportError("target does not support generation of this file type");
 }
-
+auto &Ctx = MMIWP->getMMI().getContext();
+Ctx.setGenDwarfForAssembly(Target->Options.ForceDwarfFrameSection);
 const_cast(LLVMTM.getObjFileLowering())
-->Initialize(MMIWP->getMMI().getContext(), *Target);
+->Initialize(Ctx, *Target);
 if (MIR) {
   assert(MMIWP && "Forgot to create MMIWP?");
   if (MIR->parseMachineFunctions(*M, MMIWP->getMMI()))
Index: llvm/test/tools/llvm-dwarf

[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-22 Thread Sylvain Audi via Phabricator via cfe-commits
saudi added a comment.

Sorry, I flagged this as "accepted", but I'm not sure I am allowed to do that...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121812

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


[PATCH] D122141: [clang][extract-api] Suppprt for the module name property in SymbolGraph

2022-03-22 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added a comment.

LGTM. Need to rebase. Do you think `ProductName` should be a general property 
of `APISerializer` or something specific to the `SymbolGraphSerializer`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122141

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


[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-22 Thread Sylvain Audi via Phabricator via cfe-commits
saudi accepted this revision.
saudi added a comment.
This revision is now accepted and ready to land.

It is indeed much cleaner this way`, thanks!
The tests are not anymore the same for `clang-cl` as for `clang`, but I agree 
what needs testing is the clang-cl specific behaviors, not having the same 
tests redone as a `clang-cl` flavor.




Comment at: clang/test/ClangScanDeps/cl-resource-dir.c:3
+
+// REQUIRES: shell
+

I was wondering whether it could be a concern that this test will be skipped on 
Windows systems, where `clang-cl` specific development would most likely occur.

However I'm pretty sure it's ok, since this test is pretty simple and small, 
has little chances to break during most development iterations, and we would 
run the tests under linux at some point anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121812

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


[PATCH] D121969: Pass split-machine-functions to code generator when flto is used

2022-03-22 Thread Junfeng Dong via Phabricator via cfe-commits
junfd updated this revision to Diff 417387.
junfd added a comment.

Check the mixing -fsplit-machine-functions and -fno-split-machine-functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121969

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/fsplit-machine-functions2.c


Index: clang/test/Driver/fsplit-machine-functions2.c
===
--- /dev/null
+++ clang/test/Driver/fsplit-machine-functions2.c
@@ -0,0 +1,12 @@
+// Test -fsplit-machine-functions option pass-through with lto
+// RUN: %clang -### -target x86_64-unknown-linux -flto 
-fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+
+// Test no pass-through to ld without lto
+// RUN: %clang -### -target x86_64-unknown-linux -fsplit-machine-functions %s 
2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
+
+// Test the mix of -fsplit-machine-functions and -fno-split-machine-functions
+// RUN: %clang -### -target x86_64-unknown-linux -flto 
-fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-NOPASS
+// RUN: %clang -### -target x86_64-unknown-linux -flto 
-fno-split-machine-functions -fsplit-machine-functions %s 2>&1 | FileCheck %s 
-check-prefix=CHECK-PASS
+
+// CHECK-PASS:  "-plugin-opt=-split-machine-functions"
+// CHECK-NOPASS-NOT:"-plugin-opt=-split-machine-functions"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -574,6 +574,13 @@
 CmdArgs.push_back("-plugin-opt=-data-sections");
   }
 
+  // Pass an option to enable split machine functions.
+  if (auto *A = Args.getLastArg (options::OPT_fsplit_machine_functions,
+options::OPT_fno_split_machine_functions)) {
+if (A->getOption().matches(options::OPT_fsplit_machine_functions))
+  CmdArgs.push_back("-plugin-opt=-split-machine-functions");
+  }
+
   if (Arg *A = getLastProfileSampleUseArg(Args)) {
 StringRef FName = A->getValue();
 if (!llvm::sys::fs::exists(FName))


Index: clang/test/Driver/fsplit-machine-functions2.c
===
--- /dev/null
+++ clang/test/Driver/fsplit-machine-functions2.c
@@ -0,0 +1,12 @@
+// Test -fsplit-machine-functions option pass-through with lto
+// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+
+// Test no pass-through to ld without lto
+// RUN: %clang -### -target x86_64-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
+
+// Test the mix of -fsplit-machine-functions and -fno-split-machine-functions
+// RUN: %clang -### -target x86_64-unknown-linux -flto -fsplit-machine-functions -fno-split-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-NOPASS
+// RUN: %clang -### -target x86_64-unknown-linux -flto -fno-split-machine-functions -fsplit-machine-functions %s 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+
+// CHECK-PASS:  "-plugin-opt=-split-machine-functions"
+// CHECK-NOPASS-NOT:"-plugin-opt=-split-machine-functions"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -574,6 +574,13 @@
 CmdArgs.push_back("-plugin-opt=-data-sections");
   }
 
+  // Pass an option to enable split machine functions.
+  if (auto *A = Args.getLastArg (options::OPT_fsplit_machine_functions,
+options::OPT_fno_split_machine_functions)) {
+if (A->getOption().matches(options::OPT_fsplit_machine_functions))
+  CmdArgs.push_back("-plugin-opt=-split-machine-functions");
+  }
+
   if (Arg *A = getLastProfileSampleUseArg(Args)) {
 StringRef FName = A->getValue();
 if (!llvm::sys::fs::exists(FName))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122155: Add warning when eval-method is set in the presence of value unsafe floating-point calculations.

2022-03-22 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:50-53
+def warn_eval_method_setting_via_option_in_value_unsafe_context : Warning<
+"setting the eval method via '-ffp-eval-method' has not effect when 
numeric "
+"results of floating-point calculations aren't value-safe.">,
+InGroup;

zahiraam wrote:
> aaron.ballman wrote:
> > Unless you have a strong reason for this to be a warning, this seems like a 
> > situation we should diagnose as an error with a much clearer message.
> May  be @andrew.w.kaylor would weigh in on this?
I was going to say that for the command line option we could just issue a 
warning saying that the later option overrides the earlier, but it's a bit 
complicated to sort out what that would mean if the eval method follows a 
fast-math option and it might not always be what the user intended. So, I guess 
I'd agree that it should be an error.

For the case with pragmas, the model I'd follow is the mixing of #pragma 
float_control(except, on) with a fast-math mode or #pragma 
float_control(precise, off) with a non-ignore exception mode. In both those 
cases we issue an error.


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

https://reviews.llvm.org/D122155

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


[PATCH] D121927: [Clang] Work with multiple pragmas weak before definition

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast updated this revision to Diff 417386.
hubert.reinterpretcast marked 2 inline comments as done.
hubert.reinterpretcast added a comment.

- Address review comments: Use default member init in WeakInfo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121927

Files:
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/Weak.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CodeGen/pragma-weak.c
  clang/test/PCH/pragma-weak-functional.c
  clang/test/PCH/pragma-weak-functional.h

Index: clang/test/PCH/pragma-weak-functional.h
===
--- /dev/null
+++ clang/test/PCH/pragma-weak-functional.h
@@ -0,0 +1,6 @@
+// Header for PCH test pragma-weak-functional.c
+
+#pragma weak undecfunc_alias2 = undecfunc
+#pragma weak undecfunc_alias4 = undecfunc_alias1
+#pragma weak undecfunc_alias3 = undecfunc_alias1
+#pragma weak undecfunc_alias1 = undecfunc
Index: clang/test/PCH/pragma-weak-functional.c
===
--- /dev/null
+++ clang/test/PCH/pragma-weak-functional.c
@@ -0,0 +1,17 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/pragma-weak-functional.h %s -verify -emit-llvm -o - | FileCheck %s
+
+// Test with pch.
+// RUN: %clang_cc1 -x c-header -emit-pch -o %t %S/pragma-weak-functional.h
+// RUN: %clang_cc1 -include-pch %t %s -verify -emit-llvm -o - | FileCheck %s
+
+// CHECK-DAG: @undecfunc_alias1 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias2 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias3 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias4 = weak{{.*}} alias void (), void ()* @undecfunc
+
+/ PR28611: Try multiple aliases of same undeclared symbol or alias
+void undecfunc_alias1(void);
+void undecfunc(void) { }
+// expected-warning@pragma-weak-functional.h:4 {{alias will always resolve to undecfunc}}
+// expected-warning@pragma-weak-functional.h:5 {{alias will always resolve to undecfunc}}
Index: clang/test/CodeGen/pragma-weak.c
===
--- clang/test/CodeGen/pragma-weak.c
+++ clang/test/CodeGen/pragma-weak.c
@@ -17,6 +17,10 @@
 // CHECK-DAG: @mix2 = weak{{.*}} alias void (), void ()* @__mix2
 // CHECK-DAG: @a1 = weak{{.*}} alias void (), void ()* @__a1
 // CHECK-DAG: @xxx = weak{{.*}} alias void (), void ()* @__xxx
+// CHECK-DAG: @undecfunc_alias1 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias2 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias3 = weak{{.*}} alias void (), void ()* @undecfunc
+// CHECK-DAG: @undecfunc_alias4 = weak{{.*}} alias void (), void ()* @undecfunc
 
 
 
@@ -136,6 +140,15 @@
 __attribute((pure,noinline,const)) void __xxx(void) { }
 // CHECK: void @__xxx() [[RN:#[0-9]+]]
 
+/ PR28611: Try multiple aliases of same undeclared symbol or alias
+#pragma weak undecfunc_alias1 = undecfunc
+#pragma weak undecfunc_alias1 = undecfunc // Try specifying same alias/target pair a second time.
+#pragma weak undecfunc_alias3 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}
+#pragma weak undecfunc_alias4 = undecfunc_alias2 // expected-warning {{alias will always resolve to undecfunc}}
+#pragma weak undecfunc_alias2 = undecfunc
+void undecfunc_alias2(void);
+void undecfunc(void) { }
+
 / PR10878: Make sure we can call a weak alias
 void SHA512Pad(void *context) {}
 #pragma weak SHA384Pad = SHA512Pad
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -4559,13 +4559,14 @@
   // entire table, since later PCH files in a PCH chain are only interested in
   // the results at the end of the chain.
   RecordData WeakUndeclaredIdentifiers;
-  for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) {
-IdentifierInfo *II = WeakUndeclaredIdentifier.first;
-WeakInfo &WI = WeakUndeclaredIdentifier.second;
-AddIdentifierRef(II, WeakUndeclaredIdentifiers);
-AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers);
-AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers);
-WeakUndeclaredIdentifiers.push_back(WI.getUsed());
+  for (const auto &WeakUndeclaredIdentifierList :
+   SemaRef.WeakUndeclaredIdentifiers) {
+const IdentifierInfo *const II = WeakUndeclaredIdentifierList.first;
+for (const auto &WI : WeakUndeclaredIdentifierList.second) {
+  AddIdentifierRef(II, WeakUndeclaredIdentifiers);
+  AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers);
+  Ad

[PATCH] D121812: [clang][deps] NFC: De-duplicate clang-cl tests

2022-03-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121812

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


[PATCH] D121525: [clang][deps] Create lit substitution for deps-to-rsp

2022-03-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121525

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


[PATCH] D122255: Meta directive runtime support

2022-03-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added subscribers: ggeorgakoudis, mikerice, cchen.
jdoerfert added a comment.

This contains a lot of unrelated changes, leftover comments, etc. As you clean 
up the code, please also include tests. Clang format the patch, go over the new 
code and make sure you follow the coding style. Remove unneeded parts (e.g., a 
map into which you simply push objects then take them out to push them into a 
vector).

Also, have you seen D120573 ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122255

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


[PATCH] D122160: [clang][extract-api] Refactor ExtractAPI and improve docs

2022-03-22 Thread Zixu Wang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG89f6b26f1beb: [clang][extract-api] Refactor ExtractAPI and 
improve docs (authored by zixuw).

Changed prior to commit:
  https://reviews.llvm.org/D122160?vs=417365&id=417383#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122160

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/AvailabilityInfo.h
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/include/clang/SymbolGraph/API.h
  clang/include/clang/SymbolGraph/AvailabilityInfo.h
  clang/include/clang/SymbolGraph/DeclarationFragments.h
  clang/include/clang/SymbolGraph/FrontendActions.h
  clang/include/clang/SymbolGraph/Serialization.h
  clang/lib/CMakeLists.txt
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/lib/FrontendTool/CMakeLists.txt
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/lib/SymbolGraph/API.cpp
  clang/lib/SymbolGraph/CMakeLists.txt
  clang/lib/SymbolGraph/DeclarationFragments.cpp
  clang/lib/SymbolGraph/ExtractAPIConsumer.cpp
  clang/lib/SymbolGraph/Serialization.cpp
  clang/test/ExtractAPI/global_record.c
  clang/test/SymbolGraph/global_record.c

Index: clang/lib/SymbolGraph/Serialization.cpp
===
--- clang/lib/SymbolGraph/Serialization.cpp
+++ /dev/null
@@ -1,332 +0,0 @@
-//===- SymbolGraph/Serialization.cpp *- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-///
-/// \file
-/// \brief Defines the SymbolGraph serializer and parser.
-///
-//===--===//
-
-#include "clang/SymbolGraph/Serialization.h"
-#include "clang/Basic/Version.h"
-#include "clang/SymbolGraph/API.h"
-#include "llvm/Support/JSON.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/VersionTuple.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace clang;
-using namespace clang::symbolgraph;
-using namespace llvm;
-using namespace llvm::json;
-
-namespace {
-
-static void serializeObject(Object &Paren, StringRef Key,
-Optional Obj) {
-  if (Obj)
-Paren[Key] = std::move(Obj.getValue());
-}
-
-static void serializeArray(Object &Paren, StringRef Key,
-   Optional Array) {
-  if (Array)
-Paren[Key] = std::move(Array.getValue());
-}
-
-// SymbolGraph: SemanticVersion
-static Optional serializeSemanticVersion(const VersionTuple &V) {
-  if (V.empty())
-return None;
-
-  Object Version;
-  Version["major"] = V.getMajor();
-  Version["minor"] = V.getMinor().getValueOr(0);
-  Version["patch"] = V.getSubminor().getValueOr(0);
-  return Version;
-}
-
-static Object serializeOperatingSystem(const Triple &T) {
-  Object OS;
-  OS["name"] = T.getOSTypeName(T.getOS());
-  serializeObject(OS, "minimumVersion",
-  serializeSemanticVersion(T.getMinimumSupportedOSVersion()));
-  return OS;
-}
-
-// SymbolGraph: Platform
-static Object serializePlatform(const Triple &T) {
-  Object Platform;
-  Platform["architecture"] = T.getArchName();
-  Platform["vendor"] = T.getVendorName();
-  Platform["operatingSystem"] = serializeOperatingSystem(T);
-  return Platform;
-}
-
-// SymbolGraph: SourcePosition
-static Object serializeSourcePosition(const PresumedLoc &Loc,
-  bool IncludeFileURI = false) {
-  assert(Loc.isValid() && "invalid source position");
-
-  Object SourcePosition;
-  SourcePosition["line"] = Loc.getLine();
-  SourcePosition["character"] = Loc.getColumn();
-
-  if (IncludeFileURI) {
-std::string FileURI = "file://";
-FileURI += sys::path::convert_to_slash(Loc.getFilename());
-SourcePosition["uri"] = FileURI;
-  }
-
-  return SourcePosition;
-}
-
-// SymbolGraph: SourceRange
-static Object serializeSourceRange(const PresumedLoc &BeginLoc,
-   const PresumedLoc &EndLoc) {
-  Object SourceRange;
-  serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc));
-  serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc));
-  return SourceRange;
-}
-
-// SymbolGraph: AvailabilityItem
-static Optional serializeAvailability(const Avai

[clang] 89f6b26 - [clang][extract-api] Refactor ExtractAPI and improve docs

2022-03-22 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-03-22T13:21:57-07:00
New Revision: 89f6b26f1beb2c1344f5cfeb34e405128544c76b

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

LOG: [clang][extract-api] Refactor ExtractAPI and improve docs

- The name SymbolGraph is inappropriate and confusing for the new library
  for clang-extract-api. Refactor and rename things to make it clear that
  ExtractAPI is the core functionality and SymbolGraph is one serializer
  for the API information.
- Add documentation comments to ExtractAPI classes and methods to improve
  readability and clearness of the ExtractAPI work.

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

Added: 
clang/include/clang/ExtractAPI/API.h
clang/include/clang/ExtractAPI/AvailabilityInfo.h
clang/include/clang/ExtractAPI/DeclarationFragments.h
clang/include/clang/ExtractAPI/FrontendActions.h
clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/lib/ExtractAPI/API.cpp
clang/lib/ExtractAPI/CMakeLists.txt
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SerializerBase.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/test/ExtractAPI/global_record.c

Modified: 
clang/lib/CMakeLists.txt
clang/lib/FrontendTool/CMakeLists.txt
clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Removed: 
clang/include/clang/SymbolGraph/API.h
clang/include/clang/SymbolGraph/AvailabilityInfo.h
clang/include/clang/SymbolGraph/DeclarationFragments.h
clang/include/clang/SymbolGraph/FrontendActions.h
clang/include/clang/SymbolGraph/Serialization.h
clang/lib/SymbolGraph/API.cpp
clang/lib/SymbolGraph/CMakeLists.txt
clang/lib/SymbolGraph/DeclarationFragments.cpp
clang/lib/SymbolGraph/ExtractAPIConsumer.cpp
clang/lib/SymbolGraph/Serialization.cpp
clang/test/SymbolGraph/global_record.c



diff  --git a/clang/include/clang/SymbolGraph/API.h 
b/clang/include/clang/ExtractAPI/API.h
similarity index 57%
rename from clang/include/clang/SymbolGraph/API.h
rename to clang/include/clang/ExtractAPI/API.h
index ffcc03758f4d2..5ba3cf7268d88 100644
--- a/clang/include/clang/SymbolGraph/API.h
+++ b/clang/include/clang/ExtractAPI/API.h
@@ -1,4 +1,4 @@
-//===- SymbolGraph/API.h *- C++ 
-*-===//
+//===- ExtractAPI/API.h -*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,18 +7,22 @@
 
//===--===//
 ///
 /// \file
-/// \brief Defines SymbolGraph API records.
+/// This file defines the APIRecord-based structs and the APISet class.
+///
+/// Clang ExtractAPI is a tool to collect API information from a given set of
+/// header files. The structures in this file describe data representations of
+/// the API information collected for various kinds of symbols.
 ///
 
//===--===//
 
-#ifndef LLVM_CLANG_SYMBOLGRAPH_API_H
-#define LLVM_CLANG_SYMBOLGRAPH_API_H
+#ifndef LLVM_CLANG_EXTRACTAPI_API_H
+#define LLVM_CLANG_EXTRACTAPI_API_H
 
 #include "clang/AST/Decl.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/SymbolGraph/AvailabilityInfo.h"
-#include "clang/SymbolGraph/DeclarationFragments.h"
+#include "clang/ExtractAPI/AvailabilityInfo.h"
+#include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
@@ -27,18 +31,43 @@
 #include 
 
 namespace clang {
-namespace symbolgraph {
+namespace extractapi {
 
+/// DocComment is a vector of RawComment::CommentLine.
+///
+/// Each line represents one line of striped documentation comment,
+/// with source range information. This simplifies calculating the source
+/// location of a character in the doc comment for pointing back to the source
+/// file.
+/// e.g.
+/// \code
+///   /// This is a documentation comment
+///   ^~'  First line.
+///   /// with multiple lines.
+///   ^~~' Second line.
+/// \endcode
 using DocComment = std::vector;
 
+/// The base representation of an API record. Holds common symbol information.
 struct APIRecord {
   StringRef Name;
   StringRef USR;
   PresumedLoc Location;
   AvailabilityInfo Availability;
   LinkageInfo Linkage;
+
+  /// Documentation comment lines attached to this symbol declaration.
   DocComment Comment;

[PATCH] D122160: [clang][extract-api] Refactor ExtractAPI and improve docs

2022-03-22 Thread Daniel Grumberg via Phabricator via cfe-commits
dang accepted this revision.
dang added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122160

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


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 2 inline comments as done.
kwk added a comment.

@HazardyKnusperkeks I've addressed your comments and did an early return 
together with `llvm_unreachable()` which is used in the `clang/lib/Format` in 
other places as well. I hope this is to your liking. There's no longer an 
`assert`. Do you want that as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 417379.
kwk added a comment.

- Address review comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,22 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl &Matches) {
+  for (int i = Matches.s

[PATCH] D121927: [Clang] Work with multiple pragmas weak before definition

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast marked an inline comment as done.
hubert.reinterpretcast added inline comments.



Comment at: clang/include/clang/Sema/Weak.h:33
+  : alias(Alias), loc(Loc) {}
+  inline IdentifierInfo *getAlias() const { return alias; }
   inline SourceLocation getLocation() const { return loc; }

aaron.ballman wrote:
> Would it be onerous to make the return type be `const IdentifierInfo *` given 
> that the function is `const`? (If it is, just ignore the suggestion -- I love 
> adding const correctness where we can get it basically for free.)
It's not free but I can post an NFC patch to add the `const` through. On the 
chain of calls that `const` needs to be added to, the pointer eventually feeds 
a `DeclarationName` (which already takes `const IdentifierInfo *`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121927

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


[PATCH] D121754: [clang-format] Refactor determineStarAmpUsage

2022-03-22 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Just a side note, I often get this on your changes:
Unhandled Exception ("Exception")
Found unknown intradiff source line, expected a line beginning with "+", "-", 
or " " (space): \ No newline at end of file
.




Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:85
+  auto Tokens = annotate("x - 0");
+  EXPECT_EQ(Tokens.size(), 4u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::minus, TT_BinaryOperator);

sstwcw wrote:
> HazardyKnusperkeks wrote:
> > I know the other cases also use EXPECT, but the size should be an ASSERT, 
> > so there would be no seg fault if the number would change (it shouldn't).
> I tried a wrong number and `EXPECT_EQ` didn't give a segfault.
The potential segfault is not in `EXPECT_EQ`, but in accessing a non existent 
token.
The number of tokens will most likely never change, but than again we don't 
need the `EXPECT_EQ` either.
But if it changes (gets smaller) we want to abort the test after the failed 
check and not accessing `Tokens` with an invalid index, that's why I'm pleading 
(and using) `ASSERT_EQ`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121754

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


[PATCH] D122249: [Clang] Add a compatibiliy warning for non-literals in constexpr.

2022-03-22 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 417376.
cor3ntin added a comment.

- fix formatting

- use cxx2b in the test as per aaron request. This doesn't really matter as 
this part

of the test file is only executed in c++2b mode though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122249

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
  clang/test/SemaCXX/constant-expression-cxx2b.cpp

Index: clang/test/SemaCXX/constant-expression-cxx2b.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2b.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2b.cpp
@@ -96,7 +96,7 @@
 constexpr int non_literal(bool b) {
   if (!b)
 return 0;
-  NonLiteral n;
+  NonLiteral n; // cxx2b-warning {{definition of a variable of non-literal type in a constexpr function is incompatible with C++ standards before C++2b}}
 }
 
 constexpr int non_literal_1 = non_literal(false);
@@ -164,7 +164,8 @@
   auto non_literal = [](bool b) constexpr {
 if (!b)
   NonLiteral n; // cxx2b-note {{non-literal type 'NonLiteral' cannot be used in a constant expression}} \
-// cxx2a-error {{variable of non-literal type 'NonLiteral' cannot be defined in a constexpr function before C++2b}}
+// cxx2a-error {{variable of non-literal type 'NonLiteral' cannot be defined in a constexpr function before C++2b}} \
+// cxx2b-warning {{definition of a variable of non-literal type in a constexpr function is incompatible with C++ standards before C++2b}}
 return 0;
   };
 
@@ -214,7 +215,8 @@
 
   auto non_literal = [](bool b) { // cxx2a-note 2{{declared here}}
 if (b)
-  NonLiteral n; // cxx2b-note {{non-literal type 'NonLiteral' cannot be used in a constant expression}}
+  NonLiteral n; // cxx2b-note {{non-literal type 'NonLiteral' cannot be used in a constant expression}} \
+// cxx2b-warning {{definition of a variable of non-literal type in a constexpr function is incompatible with C++ standards before C++2b}}
 return 0;
   };
 
@@ -230,11 +232,12 @@
 constexpr auto dependent_var_def_lambda(void) {
   return [](bool b) { // cxx2a-note {{declared here}}
 if (!b)
-  T t;
+  T t; // cxx2b-warning {{definition of a variable of non-literal type in a constexpr function is incompatible with C++ standards before C++2b}}
 return 0;
   };
 }
 
 constexpr auto non_literal_valid_in_cxx2b = dependent_var_def_lambda()(true); // \
 // cxx2a-error {{constexpr variable 'non_literal_valid_in_cxx2b' must be initialized by a constant expression}} \
-// cxx2a-note  {{non-constexpr function}}
+// cxx2a-note {{non-constexpr function}} \
+// cxx2b-note {{in instantiation}}
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
@@ -30,12 +30,13 @@
 };
 
 constexpr void non_literal() { // expected-error {{constexpr function never produces a constant expression}}
-  NonLiteral n;// expected-note {{non-literal type 'NonLiteral' cannot be used in a constant expression}}
+  NonLiteral n;// expected-note {{non-literal type 'NonLiteral' cannot be used in a constant expression}} \
+   // expected-warning {{definition of a variable of non-literal type in a constexpr function is incompatible with C++ standards before C++2b}}
 }
 
 constexpr void non_literal2(bool b) {
   if (!b)
-NonLiteral n;
+NonLiteral n; // expected-warning {{definition of a variable of non-literal type in a constexpr function is incompatible with C++ standards before C++2b}}
 }
 
 constexpr int c_thread_local(int n) {
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -1893,7 +1893,7 @@
   if (Kind == Sema::CheckConstexprKind::Diagnose) {
 SemaRef.Diag(VD->getLocation(),
  SemaRef.getLangOpts().CPlusPlus2b
- ? diag::warn_cxx20_compat_constexpr_static_var
+ ? diag::warn_cxx20_compat_constexpr_var
  : diag::ext_constexpr_static_var)
 << isa(Dcl)
 << (VD->getTLSKind() == VarDecl::TLS_Dynamic);
@@ -1901,10 +1901,15 @@
 return false;
   }
 }
-if (!SemaRef.LangOpts.CPlusPlus2b &&
-CheckLiteralType(SemaRef, Kind, VD->getLocation(), VD->getType(),
- diag::err_constexpr_local_var_non_literal_type,
- isa

[PATCH] D121756: [clang-format] Clean up code looking for if statements

2022-03-22 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks requested changes to this revision.
HazardyKnusperkeks added a comment.

Just a formality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121756

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


[PATCH] D122255: Meta directive runtime support

2022-03-22 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo created this revision.
Herald added subscribers: mgrang, hiraditya.
Herald added a project: All.
abidmalikwaterloo requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

The patch extends the current implementation 
for runtime support. The current patch build AST 
of the when clauses in sorted order using the
context selector score


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122255

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/OpenMPClause.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPContext.h
  llvm/lib/Frontend/OpenMP/OMPContext.cpp

Index: llvm/lib/Frontend/OpenMP/OMPContext.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPContext.cpp
+++ llvm/lib/Frontend/OpenMP/OMPContext.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 
+#include 
 #define DEBUG_TYPE "openmp-ir-builder"
 
 using namespace llvm;
@@ -339,6 +340,53 @@
   return Score;
 }
 
+/// 
+/// Takes \p VMI and \p Ctx and sort the 
+/// scores using \p A
+void llvm::omp::getArrayVariantMatchForContext(const SmallVectorImpl &VMIs,
+const OMPContext &Ctx, SmallVector> &A){
+	
+	//APInt BestScore(64, 0);
+	APInt Score (64, 0);
+	llvm::DenseMap m;
+	
+	/*for (unsigned u = 0, e = VMIs.size(); u < e; ++u) {
+		const VariantMatchInfo &VMI = VMIs[u];
+		SmallVector ConstructMatches;
+  		APInt Score = getVariantMatchScore(VMI, Ctx, ConstructMatches);
+  		m.insert({u, Score});	
+	}
+
+	*/
+	
+	for (unsigned u = 0, e = VMIs.size(); u < e; ++u) {
+		const VariantMatchInfo &VMI = VMIs[u];
+
+		SmallVector ConstructMatches;
+		// If the variant is not applicable its not the best.
+		if (!isVariantApplicableInContextHelper(VMI, Ctx, &ConstructMatches,
+/* DeviceSetOnly */ false)){
+   Score = 0;
+   m.insert({u, Score});
+  			continue;
+  		}
+  		
+   		// Check if its clearly not the best.
+		Score = getVariantMatchScore(VMI, Ctx, ConstructMatches);
+		m.insert({u, Score});	
+	}
+			
+	for (auto& it : m) 
+		A.push_back(it);
+	
+	std::sort(A.begin(), A.end(), [] (std::pair&a,
+	 	  std::pair&b){	
+			return a.second.ugt(b.second);
+		});	
+}
+ 
+
+
 int llvm::omp::getBestVariantMatchForContext(
 const SmallVectorImpl &VMIs, const OMPContext &Ctx) {
 
Index: llvm/include/llvm/Frontend/OpenMP/OMPContext.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPContext.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPContext.h
@@ -189,6 +189,15 @@
 int getBestVariantMatchForContext(const SmallVectorImpl &VMIs,
   const OMPContext &Ctx);
 
+/// Sort array \p A of clause index  with score
+/// This will be used to produce AST clauses
+/// in a sorted order with the clause with the highiest order
+/// on the top and default clause at the bottom
+void getArrayVariantMatchForContext(
+const SmallVectorImpl &VMIs, const OMPContext &Ctx,
+SmallVector> &A);
+
+// new--
 } // namespace omp
 
 template <> struct DenseMapInfo {
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -4791,8 +4791,9 @@
   CapturedStmt *Res = CapturedStmt::Create(
   getASTContext(), S, static_cast(RSI->CapRegionKind),
   Captures, CaptureInits, CD, RD);
-
+  		
   CD->setBody(Res->getCapturedStmt());
+
   RD->completeDefinition();
 
   return Res;
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -37,6 +37,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include "llvm/Frontend/OpenMP/OMPContext.h"
 #include 
 
 using namespace clang;
@@ -3930,6 +3931,7 @@
 
 void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
   switch (DKind) {
+  case OMPD_metadirective: // added
   case OMPD_parallel:
   case OMPD_parallel_for:
   case OMPD_parallel_for_simd:
@@ -4339,8 +4341,8 @@
   case OMPD_declare_variant:
   case OMPD_begin_declare_variant:
   case OMPD_end_declare_variant:
-  case OMPD_metadirective:
-llvm_unreachable("OpenMP Directive is not allowed");
+  //case OMPD_metad

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/Format.cpp:2694-2697
+if (!Matches[i].empty()) {
+  res = Matches[i];
+  break;
+}





Comment at: clang/lib/Format/Format.cpp:2699
+  }
+  assert(!res.empty());
+  return res;

Is there something like LLVM_UNREACHABLE?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121370

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


[PATCH] D122248: [clang][CodeGen]Fix clang crash and add bitfield support in __builtin_dump_struct

2022-03-22 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> the remaining changes are code formatting

Please remove code formatting changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122248

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


[PATCH] D121927: [Clang] Work with multiple pragmas weak before definition

2022-03-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast marked an inline comment as done.
hubert.reinterpretcast added inline comments.



Comment at: clang/include/clang/Sema/Weak.h:62
+return false;
+  return LHS.getAlias()->getName() == RHS.getAlias()->getName();
+}

aaron.ballman wrote:
> Previously we cared about the source locations being the same. But... is 
> there a situation where the aliases are the same but the source locations are 
> different? I can't think of any, so perhaps that's worth an assert that the 
> locations match?
We didn't really case about the source locations being the same. The removed 
operators were just dead code (featuring such things as 
compare-by-pointer-value). I have verified that splitting the deletion of them 
to a separate patch does not cause any build or LIT `check-all` failures. I can 
commit that part as an NFC patch first if you prefer.

Also, the aliases //can// be the same with different source locations. The 
location comes from where the `#pragma weak` is (from the parser by way of 
`ActOnPragmaWeakAlias`). That duplicates are ignored (meaning we only diagnose 
one instance) is mentioned in the patch description.

It is already the status quo that having the same alias specified with 
different targets (at least those not yet declared) neither produces a 
diagnostic nor operates by "last one wins". Instead, Clang prefers the first 
declared target and GCC just emits both and leaves it to the assembler to 
figure out (https://godbolt.org/z/EasK375j3).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121927

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


[PATCH] D122029: Change __auto_type behavior with qualifiers to match GCC behavior

2022-03-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

FWIW, I plan to land this sometime tomorrow (Mar 23) unless there are 
additional review comments before then.


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

https://reviews.llvm.org/D122029

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


[PATCH] D117391: [AST] Ignore implicit nodes in CastExpr::getConversionFunction

2022-03-22 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr closed this revision.
kimgr added a comment.
Herald added a project: All.

Now that D119477  has landed, this suggested 
change is obsolete. Closing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117391

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


[PATCH] D122249: [Clang] Add a compatibiliy warning for non-literals in constexpr.

2022-03-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2725
+def warn_cxx20_compat_constexpr_var : Warning<
+  "definition of a %select{static variable|thread_local variable|variable of 
non-literal type}1 "
   "in a constexpr %select{function|constructor}0 "

You should re-flow the whole diagnostic to the usual 80-col limit.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:1904-1912
+if(SemaRef.LangOpts.CPlusPlus2b) {
+if(!VD->getType()->isLiteralType(SemaRef.Context))
+
SemaRef.Diag(VD->getLocation(),diag::warn_cxx20_compat_constexpr_var)
+<< isa(Dcl)
+<< 2;
+}
+else if (CheckLiteralType(SemaRef, Kind, VD->getLocation(), 
VD->getType(),

Formatting looks off here (I was expecting the `else if` on the same line as 
the curly brace, but maybe clang-format is being weird?)



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:1908
+<< isa(Dcl)
+<< 2;
+}





Comment at: clang/test/SemaCXX/constant-expression-cxx2b.cpp:99
 return 0;
-  NonLiteral n;
+  NonLiteral n; // expected-warning {{definition of a variable of non-literal 
type in a constexpr function is incompatible with C++ standards before C++2b}}
 }

Shouldn't this be a `cxx2b-warning` instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122249

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


[PATCH] D122155: Add warning when eval-method is set in the presence of value unsafe floating-point calculations.

2022-03-22 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticFrontendKinds.td:50-53
+def warn_eval_method_setting_via_option_in_value_unsafe_context : Warning<
+"setting the eval method via '-ffp-eval-method' has not effect when 
numeric "
+"results of floating-point calculations aren't value-safe.">,
+InGroup;

aaron.ballman wrote:
> Unless you have a strong reason for this to be a warning, this seems like a 
> situation we should diagnose as an error with a much clearer message.
May  be @andrew.w.kaylor would weigh in on this?


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

https://reviews.llvm.org/D122155

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


  1   2   3   >