[clang] b2936ca - [clang] inheritance fix for nomerge attribute

Dávid Bolvanský via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 11 06:51:15 PST 2022


Author: Dávid Bolvanský
Date: 2022-02-11T15:51:08+01:00
New Revision: b2936caf77e00fdb97814960eb1355c2a36c1e70

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

LOG: [clang] inheritance fix for nomerge attribute

Discussed here: https://reviews.llvm.org/D119061#3310822

Reviewed By: aaron.ballman

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

Added: 
    clang/test/Sema/attr-nomerge-ast.cpp

Modified: 
    clang/include/clang/Basic/Attr.td
    clang/lib/Sema/SemaStmtAttr.cpp
    clang/test/Parser/stmt-attributes.c
    clang/test/Parser/stmt-attributes.m
    clang/test/Sema/attr-nomerge.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 5156b6b5615b..8e8b7bc16e3b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1390,7 +1390,6 @@ def : MutualExclusions<[Likely, Unlikely]>;
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
-  let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
                              "functions and statements">;
   let SimpleHandler = 1;

diff  --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 4f2977f89ce1..63c6fa391459 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -202,7 +202,7 @@ static Attr *handleNoMergeAttr(Sema &S, Stmt *St, const ParsedAttr &A,
 
   if (!CEF.foundCallExpr()) {
     S.Diag(St->getBeginLoc(), diag::warn_nomerge_attribute_ignored_in_stmt)
-        << NMA.getSpelling();
+        << A;
     return nullptr;
   }
 

diff  --git a/clang/test/Parser/stmt-attributes.c b/clang/test/Parser/stmt-attributes.c
index 52061afd7bc1..86c9255fd47e 100644
--- a/clang/test/Parser/stmt-attributes.c
+++ b/clang/test/Parser/stmt-attributes.c
@@ -80,7 +80,7 @@ void foobar(void) {
   __attribute__((nomerge, unused)) bar(); // expected-error {{expected identifier or '('}}
   __attribute__((nomerge(1, 2))) bar();   // expected-error {{'nomerge' attribute takes no arguments}}
   int x;
-  __attribute__((nomerge)) x = 10; // expected-warning {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  __attribute__((nomerge)) x = 10; // expected-warning {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
 
   __attribute__((nomerge)) label : bar(); // expected-error {{'nomerge' attribute only applies to functions and statements}}
 }

diff  --git a/clang/test/Parser/stmt-attributes.m b/clang/test/Parser/stmt-attributes.m
index a138580d6717..227ea9dc2fac 100644
--- a/clang/test/Parser/stmt-attributes.m
+++ b/clang/test/Parser/stmt-attributes.m
@@ -29,13 +29,13 @@ - (void)bar {
   // expected-error at -3 {{expected identifier or '('}}
   // expected-note at -4 {{to match this '['}}
   __attribute__((nomerge)) [self foo];
-  // expected-warning at -1 {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  // expected-warning at -1 {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
   __attribute__((nomerge)) [getTest() foo];
 
   __attribute__(()) ^{};
   // expected-error at -1 {{expected identifier or '('}}
   __attribute__((nomerge)) ^{};
-  // expected-warning at -1 {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  // expected-warning at -1 {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
   __attribute__((nomerge)) ^{ [self foo]; }();
 
   __attribute__(()) @try {
@@ -49,9 +49,9 @@ - (void)bar {
   }
 
   __attribute__((nomerge)) (__bridge void *)self;
-  // expected-warning at -1 {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  // expected-warning at -1 {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
 
   __attribute__((nomerge)) self.hasFoobar;
-  // expected-warning at -1 {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  // expected-warning at -1 {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
 }
 @end

diff  --git a/clang/test/Sema/attr-nomerge-ast.cpp b/clang/test/Sema/attr-nomerge-ast.cpp
new file mode 100644
index 000000000000..c440cf760b16
--- /dev/null
+++ b/clang/test/Sema/attr-nomerge-ast.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -ast-dump %s 2>&1 | FileCheck %s
+
+[[clang::nomerge]] void func();
+[[clang::nomerge]] void func();
+void func();
+[[clang::nomerge]] void func() {}
+
+// CHECK: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: NoMergeAttr
+// CHECK-NEXT: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: NoMergeAttr
+// CHECK-NEXT: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: NoMergeAttr {{.*}} Inherited
+// CHECK-NEXT: FunctionDecl {{.*}} func 'void ()'
+// CHECK-NEXT: CompoundStmt
+// CHECK-NEXT: NoMergeAttr

diff  --git a/clang/test/Sema/attr-nomerge.cpp b/clang/test/Sema/attr-nomerge.cpp
index eafea2dfe810..294abfafcd2a 100644
--- a/clang/test/Sema/attr-nomerge.cpp
+++ b/clang/test/Sema/attr-nomerge.cpp
@@ -6,7 +6,7 @@ void foo() {
   [[clang::nomerge]] bar();
   [[clang::nomerge(1, 2)]] bar(); // expected-error {{'nomerge' attribute takes no arguments}}
   int x;
-  [[clang::nomerge]] x = 10; // expected-warning {{nomerge attribute is ignored because there exists no call expression inside the statement}}
+  [[clang::nomerge]] x = 10; // expected-warning {{'nomerge' attribute is ignored because there exists no call expression inside the statement}}
 
   [[clang::nomerge]] label: bar(); // expected-error {{'nomerge' attribute only applies to functions and statements}}
 


        


More information about the cfe-commits mailing list