[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread via cfe-commits


@@ -3727,12 +3734,26 @@ 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 =

Mr-Anyone wrote:

Take the `interrupt` attribute as an example:

This is the original string: `true && (T.getArch() == llvm::Triple::riscv32 || 
T.getArch() == llvm::Triple::riscv64) ? 1 : 0`. 

The problem is that there are multiple of them for a single attribute, such as 
`true && (T.getArch() == llvm::Triple::arm || T.getArch() == 
llvm::Triple::thumb || T.getArch() == llvm::Triple::armeb || T.getArch() == 
llvm::Triple::thumbeb) ? 1 : 0
` for arm.

Meaning that, we used to get: 
```
.Case("interrupt",true && (T.getArch() == llvm::Triple::riscv32 || T.getArch() 
== llvm::Triple::riscv64) ? 1 : 0 )
.Case("interrupt",true && (T.getArch() == llvm::Triple::arm || T.getArch() == 
llvm::Triple::thumb || T.getArch() == llvm::Triple::armeb || T.getArch() == 
llvm::Triple::thumbeb) ? 1 : 0
...
```


This is the new one `TestStr`: `(true && (T.getArch() == llvm::Triple::avr) ? 1 
: 0)`, with the only difference being the added parentheses. We can join test 
strings together with `||`, meaning we generate something like this: 


```
(true && (T.getArch() == llvm::Triple::riscv32 || T.getArch() == 
llvm::Triple::riscv64) ? 1 : 0) ||
(true && (T.getArch() == llvm::Triple::arm || 
T.getArch() == llvm::Triple::thumb || T.getArch() == llvm::Triple::armeb || 
T.getArch() == llvm::Triple::thumbeb) ? 1 : 0) ... 
```

So now we have a single case statement instead, 

```
.Case("interrupt",(true && (T.getArch() == llvm::Triple::riscv32 || T.getArch() 
== llvm::Triple::riscv64) ? 1 : 0) ||
(true && (T.getArch() == llvm::Triple::arm || 
T.getArch() == llvm::Triple::thumb || T.getArch() == llvm::Triple::armeb || 
T.getArch() == llvm::Triple::thumbeb) ? 1 : 0) ... )
...
```


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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman closed 
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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM!

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Erich Keane via cfe-commits


@@ -3727,12 +3734,26 @@ 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 =

erichkeane wrote:

Got it, thank you for that!

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread via cfe-commits

https://github.com/Mr-Anyone edited 
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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.


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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread via cfe-commits

https://github.com/Mr-Anyone updated 
https://github.com/llvm/llvm-project/pull/140828

>From 393ccc154e2f1d68ef25d660c8063ab9674ab09b Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 21:25:32 -0400
Subject: [PATCH 1/5] [clang][TableGen] Fix Duplicate Entries in TableGen

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

resolves #140701
---
 clang/test/AST/ast-dump-riscv-attributes.cpp | 12 
 clang/utils/TableGen/ClangAttrEmitter.cpp| 31 
 2 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-riscv-attributes.cpp

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 0..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..094ea0564f2d7 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,12 @@ static bool GenerateTargetSpecificAttrChecks(const 
Record *R,
 static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  // It turns out that duplicate records for a given spelling. This map 
combines
+  // matching test strings using '||'. For example, if there are three
+  // conditions A, B, and C, the final result will be: A || B || C.
+  llvm::StringMap TestStringMap;
+
   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 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";
   }
+
   OS << ".Default(0);\n";
 }
 

>From 475f240822f34a00e26740a4ad3576fab14accf1 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:18:36 -0400
Subject: [PATCH 2/5] update comments

---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 094ea0564f2d7..d2b873adfdbdb 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3669,8 +3669,8 @@ static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
 
-  // It turns out that duplicate records for a given spelling. This map 
combines
-  // matching test strings using '||'. For example, if there are three
+  // It turns out that there are duplicate records for a given spelling. This 
map
+  // combines matching test strings using '||'. For example, if there are three
   // conditions A, B, and C, the final result will be: A || B || C.
   llvm::StringMap TestStringMap;
 

>From 7a5e56c13d2fe25fca26e6d31473e35b4bb18f03 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:24:14 -0400
Subject: [PATCH 3/5] Fixed Clang Format

---
 clang/

[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread via cfe-commits

https://github.com/Mr-Anyone updated 
https://github.com/llvm/llvm-project/pull/140828

>From 393ccc154e2f1d68ef25d660c8063ab9674ab09b Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 21:25:32 -0400
Subject: [PATCH 1/5] [clang][TableGen] Fix Duplicate Entries in TableGen

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

resolves #140701
---
 clang/test/AST/ast-dump-riscv-attributes.cpp | 12 
 clang/utils/TableGen/ClangAttrEmitter.cpp| 31 
 2 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-riscv-attributes.cpp

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 0..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..094ea0564f2d7 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,12 @@ static bool GenerateTargetSpecificAttrChecks(const 
Record *R,
 static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  // It turns out that duplicate records for a given spelling. This map 
combines
+  // matching test strings using '||'. For example, if there are three
+  // conditions A, B, and C, the final result will be: A || B || C.
+  llvm::StringMap TestStringMap;
+
   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 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";
   }
+
   OS << ".Default(0);\n";
 }
 

>From 475f240822f34a00e26740a4ad3576fab14accf1 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:18:36 -0400
Subject: [PATCH 2/5] update comments

---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 094ea0564f2d7..d2b873adfdbdb 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3669,8 +3669,8 @@ static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
 
-  // It turns out that duplicate records for a given spelling. This map 
combines
-  // matching test strings using '||'. For example, if there are three
+  // It turns out that there are duplicate records for a given spelling. This 
map
+  // combines matching test strings using '||'. For example, if there are three
   // conditions A, B, and C, the final result will be: A || B || C.
   llvm::StringMap TestStringMap;
 

>From 7a5e56c13d2fe25fca26e6d31473e35b4bb18f03 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:24:14 -0400
Subject: [PATCH 3/5] Fixed Clang Format

---
 clang/

[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread via cfe-commits


@@ -3727,12 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";

Mr-Anyone wrote:

done.

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread via cfe-commits


@@ -3727,12 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }

Mr-Anyone wrote:

done, thanks. 

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread via cfe-commits


@@ -3727,12 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed

Mr-Anyone wrote:

done.

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread via cfe-commits

https://github.com/Mr-Anyone updated 
https://github.com/llvm/llvm-project/pull/140828

>From 393ccc154e2f1d68ef25d660c8063ab9674ab09b Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 21:25:32 -0400
Subject: [PATCH 1/5] [clang][TableGen] Fix Duplicate Entries in TableGen

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

resolves #140701
---
 clang/test/AST/ast-dump-riscv-attributes.cpp | 12 
 clang/utils/TableGen/ClangAttrEmitter.cpp| 31 
 2 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-riscv-attributes.cpp

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 0..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..094ea0564f2d7 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,12 @@ static bool GenerateTargetSpecificAttrChecks(const 
Record *R,
 static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  // It turns out that duplicate records for a given spelling. This map 
combines
+  // matching test strings using '||'. For example, if there are three
+  // conditions A, B, and C, the final result will be: A || B || C.
+  llvm::StringMap TestStringMap;
+
   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 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";
   }
+
   OS << ".Default(0);\n";
 }
 

>From 475f240822f34a00e26740a4ad3576fab14accf1 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:18:36 -0400
Subject: [PATCH 2/5] update comments

---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 094ea0564f2d7..d2b873adfdbdb 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3669,8 +3669,8 @@ static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
 
-  // It turns out that duplicate records for a given spelling. This map 
combines
-  // matching test strings using '||'. For example, if there are three
+  // It turns out that there are duplicate records for a given spelling. This 
map
+  // combines matching test strings using '||'. For example, if there are three
   // conditions A, B, and C, the final result will be: A || B || C.
   llvm::StringMap TestStringMap;
 

>From 7a5e56c13d2fe25fca26e6d31473e35b4bb18f03 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:24:14 -0400
Subject: [PATCH 3/5] Fixed Clang Format

---
 clang/

[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread via cfe-commits


@@ -3727,12 +3734,26 @@ 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 =

Mr-Anyone wrote:

before: https://pastebin.com/iwkWd3Bf
after: https://pastebin.com/eikjMpQt

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Aaron Ballman via cfe-commits


@@ -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

AaronBallman wrote:

Before this patch, our "has attribute" check was looking through a 
`StringSwitch` that had multiple cases with the same string argument but 
different resulting values (that would check for target triples and arches). So 
we'd hit the first case, say "this matches", and the test for the attribute 
would only pass if the target triple matched. Because the first triple was 
never the RISCV attribute, we'd always say "we don't have this attribute". In 
turn, this would mean parsing would say "well, we don't know about this 
attribute, so eat all the arguments". But because Sema could figure out which 
`handleInterruptAttr` function to call, we'd actually go ahead and make the 
correct attribute, just with the incorrect argument. The default if no argument 
is specified for RISCV is `machine`. So we'd ignore `supervisor` and just 
substitute in `machine` quietly for the user.

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for working on this! In general, this looks good to me, just nits 
about our coding style.

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Aaron Ballman via cfe-commits


@@ -3727,12 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }

AaronBallman wrote:

```suggestion
  if (TestStringMap.contains(Spelling.name()))
TestStringMap[Spelling.name()] += " || " + TestStr;
  else
TestStringMap[Spelling.name()] = TestStr;
```

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Aaron Ballman via cfe-commits


@@ -3727,12 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";

AaronBallman wrote:

```suggestion
  for (auto &Entry : TestStringMap) {
OS << ".Case(\"" << Entry.getKey() << "\", " << Entry.getValue()
   << ")\n";
```

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Aaron Ballman via cfe-commits


@@ -3727,12 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed

AaronBallman wrote:

```suggestion
  // been parsed.
```

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-21 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-20 Thread via cfe-commits

https://github.com/Mr-Anyone updated 
https://github.com/llvm/llvm-project/pull/140828

>From 393ccc154e2f1d68ef25d660c8063ab9674ab09b Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 21:25:32 -0400
Subject: [PATCH 1/4] [clang][TableGen] Fix Duplicate Entries in TableGen

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

resolves #140701
---
 clang/test/AST/ast-dump-riscv-attributes.cpp | 12 
 clang/utils/TableGen/ClangAttrEmitter.cpp| 31 
 2 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-riscv-attributes.cpp

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 0..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..094ea0564f2d7 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,12 @@ static bool GenerateTargetSpecificAttrChecks(const 
Record *R,
 static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  // It turns out that duplicate records for a given spelling. This map 
combines
+  // matching test strings using '||'. For example, if there are three
+  // conditions A, B, and C, the final result will be: A || B || C.
+  llvm::StringMap TestStringMap;
+
   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 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";
   }
+
   OS << ".Default(0);\n";
 }
 

>From 475f240822f34a00e26740a4ad3576fab14accf1 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:18:36 -0400
Subject: [PATCH 2/4] update comments

---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 094ea0564f2d7..d2b873adfdbdb 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3669,8 +3669,8 @@ static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
 
-  // It turns out that duplicate records for a given spelling. This map 
combines
-  // matching test strings using '||'. For example, if there are three
+  // It turns out that there are duplicate records for a given spelling. This 
map
+  // combines matching test strings using '||'. For example, if there are three
   // conditions A, B, and C, the final result will be: A || B || C.
   llvm::StringMap TestStringMap;
 

>From 7a5e56c13d2fe25fca26e6d31473e35b4bb18f03 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:24:14 -0400
Subject: [PATCH 3/4] Fixed Clang Format

---
 clang/

[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-20 Thread via cfe-commits

https://github.com/Mr-Anyone updated 
https://github.com/llvm/llvm-project/pull/140828

>From 393ccc154e2f1d68ef25d660c8063ab9674ab09b Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 21:25:32 -0400
Subject: [PATCH 1/3] [clang][TableGen] Fix Duplicate Entries in TableGen

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

resolves #140701
---
 clang/test/AST/ast-dump-riscv-attributes.cpp | 12 
 clang/utils/TableGen/ClangAttrEmitter.cpp| 31 
 2 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-riscv-attributes.cpp

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 0..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..094ea0564f2d7 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,12 @@ static bool GenerateTargetSpecificAttrChecks(const 
Record *R,
 static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  // It turns out that duplicate records for a given spelling. This map 
combines
+  // matching test strings using '||'. For example, if there are three
+  // conditions A, B, and C, the final result will be: A || B || C.
+  llvm::StringMap TestStringMap;
+
   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 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";
   }
+
   OS << ".Default(0);\n";
 }
 

>From 475f240822f34a00e26740a4ad3576fab14accf1 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:18:36 -0400
Subject: [PATCH 2/3] update comments

---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 094ea0564f2d7..d2b873adfdbdb 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3669,8 +3669,8 @@ static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
 
-  // It turns out that duplicate records for a given spelling. This map 
combines
-  // matching test strings using '||'. For example, if there are three
+  // It turns out that there are duplicate records for a given spelling. This 
map
+  // combines matching test strings using '||'. For example, if there are three
   // conditions A, B, and C, the final result will be: A || B || C.
   llvm::StringMap TestStringMap;
 

>From 7a5e56c13d2fe25fca26e6d31473e35b4bb18f03 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:24:14 -0400
Subject: [PATCH 3/3] Fixed Clang Format

---
 clang/

[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-20 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp -- 
clang/test/AST/ast-dump-riscv-attributes.cpp 
clang/utils/TableGen/ClangAttrEmitter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index d2b873adf..05580716d 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3669,9 +3669,9 @@ static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
 
-  // It turns out that there are duplicate records for a given spelling. This 
map
-  // combines matching test strings using '||'. For example, if there are three
-  // conditions A, B, and C, the final result will be: A || B || C.
+  // It turns out that there are duplicate records for a given spelling. This
+  // map combines matching test strings using '||'. For example, if there are
+  // three conditions A, B, and C, the final result will be: A || B || C.
   llvm::StringMap TestStringMap;
 
   for (const auto &[Attr, Spelling] : Attrs) {

``




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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-20 Thread via cfe-commits

https://github.com/Mr-Anyone updated 
https://github.com/llvm/llvm-project/pull/140828

>From 393ccc154e2f1d68ef25d660c8063ab9674ab09b Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 21:25:32 -0400
Subject: [PATCH 1/2] [clang][TableGen] Fix Duplicate Entries in TableGen

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

resolves #140701
---
 clang/test/AST/ast-dump-riscv-attributes.cpp | 12 
 clang/utils/TableGen/ClangAttrEmitter.cpp| 31 
 2 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-riscv-attributes.cpp

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 0..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..094ea0564f2d7 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,12 @@ static bool GenerateTargetSpecificAttrChecks(const 
Record *R,
 static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  // It turns out that duplicate records for a given spelling. This map 
combines
+  // matching test strings using '||'. For example, if there are three
+  // conditions A, B, and C, the final result will be: A || B || C.
+  llvm::StringMap TestStringMap;
+
   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 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";
   }
+
   OS << ".Default(0);\n";
 }
 

>From 475f240822f34a00e26740a4ad3576fab14accf1 Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 22:18:36 -0400
Subject: [PATCH 2/2] update comments

---
 clang/utils/TableGen/ClangAttrEmitter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 094ea0564f2d7..d2b873adfdbdb 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3669,8 +3669,8 @@ static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
 
-  // It turns out that duplicate records for a given spelling. This map 
combines
-  // matching test strings using '||'. For example, if there are three
+  // It turns out that there are duplicate records for a given spelling. This 
map
+  // combines matching test strings using '||'. For example, if there are three
   // conditions A, B, and C, the final result will be: A || B || C.
   llvm::StringMap TestStringMap;
 

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-20 Thread via cfe-commits

https://github.com/Mr-Anyone updated 
https://github.com/llvm/llvm-project/pull/140828

>From 393ccc154e2f1d68ef25d660c8063ab9674ab09b Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 21:25:32 -0400
Subject: [PATCH] [clang][TableGen] Fix Duplicate Entries in TableGen

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

resolves #140701
---
 clang/test/AST/ast-dump-riscv-attributes.cpp | 12 
 clang/utils/TableGen/ClangAttrEmitter.cpp| 31 
 2 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-riscv-attributes.cpp

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 0..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..094ea0564f2d7 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,12 @@ static bool GenerateTargetSpecificAttrChecks(const 
Record *R,
 static void GenerateHasAttrSpellingStringSwitch(
 ArrayRef> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  // It turns out that duplicate records for a given spelling. This map 
combines
+  // matching test strings using '||'. For example, if there are three
+  // conditions A, B, and C, the final result will be: A || B || C.
+  llvm::StringMap TestStringMap;
+
   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 +3734,26 @@ 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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  // Create the actual string switch statement after all the attributes have
+  // been parsed
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";
   }
+
   OS << ".Default(0);\n";
 }
 

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-20 Thread via cfe-commits

https://github.com/Mr-Anyone updated 
https://github.com/llvm/llvm-project/pull/140828

>From f9b4429de43493a95dc107e383e71ffaebecf2ba Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 21:25:32 -0400
Subject: [PATCH] [clang][TableGen] Fix Duplicate Entries in TableGen

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

resolves #140701
---
 clang/test/AST/ast-dump-riscv-attributes.cpp | 12 +
 clang/utils/TableGen/ClangAttrEmitter.cpp| 26 
 2 files changed, 33 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-riscv-attributes.cpp

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 0..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..145abdd8828e5 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> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  llvm::StringMap TestStringMap;
+
   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 (TestStringMap.contains(Spelling.name())) {
+TestStringMap[Spelling.name()] += " || " + TestStr;
+  } else {
+TestStringMap[Spelling.name()] = TestStr;
+  }
+}
+  }
+
+  for (auto &entry : TestStringMap) {
+OS << ".Case(\"" << entry.getKey() << "\", " << entry.getValue()
+   << ")\n";
   }
+
   OS << ".Default(0);\n";
 }
 

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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-20 Thread via cfe-commits

llvmbot wrote:




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

Author: Vincent (Mr-Anyone)


Changes

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 0..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> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  llvm::StringMap 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";
 }
 

``




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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vincent (Mr-Anyone)


Changes

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 0..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> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  llvm::StringMap 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";
 }
 

``




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


[clang] [clang][TableGen] Fix Duplicate Entries in TableGen (PR #140828)

2025-05-20 Thread via cfe-commits

https://github.com/Mr-Anyone created 
https://github.com/llvm/llvm-project/pull/140828

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

resolves #140701

>From 640bc8ba7a0bf9c7bffd1a2911c1ddac3b4e6fcd Mon Sep 17 00:00:00 2001
From: Vincent 
Date: Tue, 20 May 2025 21:25:32 -0400
Subject: [PATCH] [clang][TableGen] Fix Duplicate Entries in TableGen

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

resolves #140701
---
 clang/test/AST/ast-dump-riscv-attributes.cpp | 12 +
 clang/utils/TableGen/ClangAttrEmitter.cpp| 26 
 2 files changed, 33 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-riscv-attributes.cpp

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 0..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> Attrs,
 raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
+
+  llvm::StringMap 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";
 }
 

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