llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-risc-v

Author: Vincent (Mr-Anyone)

<details>
<summary>Changes</summary>

Fixed TableGen duplicate issues that causes the wrong interrupt attribute from 
being selected.

resolves #<!-- -->140701

---
Full diff: https://github.com/llvm/llvm-project/pull/140828.diff


2 Files Affected:

- (added) clang/test/AST/ast-dump-riscv-attributes.cpp (+12) 
- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (+21-5) 


``````````diff
diff --git a/clang/test/AST/ast-dump-riscv-attributes.cpp 
b/clang/test/AST/ast-dump-riscv-attributes.cpp
new file mode 100644
index 0000000000000..7efe626072311
--- /dev/null
+++ b/clang/test/AST/ast-dump-riscv-attributes.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple riscv64 -ast-dump -ast-dump-filter c23 -std=c23 -x 
c %s | FileCheck --strict-whitespace %s
+
+// CHECK:       FunctionDecl{{.*}}pre_c23
+// CHECK-NEXT:    |-CompoundStmt
+// CHECK-NEXT:    `-RISCVInterruptAttr{{.*}}supervisor
+__attribute__((interrupt("supervisor"))) void pre_c23(){}
+
+// CHECK:       FunctionDecl{{.*}}in_c23
+// CHECK-NEXT:    |-CompoundStmt
+// CHECK-NEXT:    `-RISCVInterruptAttr{{.*}}supervisor
+// CHECK-NOT:     `-RISCVInterruptAttr{{.*}}machine
+[[gnu::interrupt("supervisor")]] void in_c23(){}
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 9684ec9520e5a..effef13c8d276 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -3667,6 +3668,9 @@ static bool GenerateTargetSpecificAttrChecks(const Record 
*R,
 static void GenerateHasAttrSpellingStringSwitch(
     ArrayRef<std::pair<const Record *, FlattenedSpelling>> Attrs,
     raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  llvm::StringMap<std::string> TargetSpecificMap;
+
   for (const auto &[Attr, Spelling] : Attrs) {
     // C++11-style attributes have specific version information associated with
     // them. If the attribute has no scope, the version information must not
@@ -3727,12 +3731,24 @@ static void GenerateHasAttrSpellingStringSwitch(
       }
     }
 
-    std::string TestStr = !Test.empty()
-                              ? Test + " ? " + itostr(Version) + " : 0"
-                              : itostr(Version);
-    if (Scope.empty() || Scope == Spelling.nameSpace())
-      OS << "    .Case(\"" << Spelling.name() << "\", " << TestStr << ")\n";
+    std::string TestStr =
+        !Test.empty() ? '(' + Test + " ? " + itostr(Version) + " : 0" + ')'
+                      : '(' + itostr(Version) + ')';
+
+    if (Scope.empty() || Scope == Spelling.nameSpace()) {
+      if (TargetSpecificMap.contains(Spelling.name())) {
+        TargetSpecificMap[Spelling.name()] += " || " + TestStr;
+      } else {
+        TargetSpecificMap[Spelling.name()] = TestStr;
+      }
+    }
+  }
+
+  for (auto &entry : TargetSpecificMap) {
+    OS << "    .Case(\"" << entry.getKey() << "\", " << entry.getValue()
+       << ")\n";
   }
+
   OS << "    .Default(0);\n";
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/140828
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to