Skip to content

Commit f9b4429

Browse files
committed
[clang][TableGen] Fix Duplicate Entries in TableGen
Fixed TableGen duplicate issues that causes the wrong interrupt attribute from being selected. resolves #140701
1 parent 3f196e0 commit f9b4429

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -triple riscv64 -ast-dump -ast-dump-filter c23 -std=c23 -x c %s | FileCheck --strict-whitespace %s
2+
3+
// CHECK: FunctionDecl{{.*}}pre_c23
4+
// CHECK-NEXT: |-CompoundStmt
5+
// CHECK-NEXT: `-RISCVInterruptAttr{{.*}}supervisor
6+
__attribute__((interrupt("supervisor"))) void pre_c23(){}
7+
8+
// CHECK: FunctionDecl{{.*}}in_c23
9+
// CHECK-NEXT: |-CompoundStmt
10+
// CHECK-NEXT: `-RISCVInterruptAttr{{.*}}supervisor
11+
// CHECK-NOT: `-RISCVInterruptAttr{{.*}}machine
12+
[[gnu::interrupt("supervisor")]] void in_c23(){}

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/STLExtras.h"
2121
#include "llvm/ADT/SmallString.h"
2222
#include "llvm/ADT/StringExtras.h"
23+
#include "llvm/ADT/StringMap.h"
2324
#include "llvm/ADT/StringRef.h"
2425
#include "llvm/ADT/StringSwitch.h"
2526
#include "llvm/Support/ErrorHandling.h"
@@ -3667,6 +3668,9 @@ static bool GenerateTargetSpecificAttrChecks(const Record *R,
36673668
static void GenerateHasAttrSpellingStringSwitch(
36683669
ArrayRef<std::pair<const Record *, FlattenedSpelling>> Attrs,
36693670
raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
3671+
3672+
llvm::StringMap<std::string> TestStringMap;
3673+
36703674
for (const auto &[Attr, Spelling] : Attrs) {
36713675
// C++11-style attributes have specific version information associated with
36723676
// them. If the attribute has no scope, the version information must not
@@ -3727,12 +3731,24 @@ static void GenerateHasAttrSpellingStringSwitch(
37273731
}
37283732
}
37293733

3730-
std::string TestStr = !Test.empty()
3731-
? Test + " ? " + itostr(Version) + " : 0"
3732-
: itostr(Version);
3733-
if (Scope.empty() || Scope == Spelling.nameSpace())
3734-
OS << " .Case(\"" << Spelling.name() << "\", " << TestStr << ")\n";
3734+
std::string TestStr =
3735+
!Test.empty() ? '(' + Test + " ? " + itostr(Version) + " : 0" + ')'
3736+
: '(' + itostr(Version) + ')';
3737+
3738+
if (Scope.empty() || Scope == Spelling.nameSpace()) {
3739+
if (TestStringMap.contains(Spelling.name())) {
3740+
TestStringMap[Spelling.name()] += " || " + TestStr;
3741+
} else {
3742+
TestStringMap[Spelling.name()] = TestStr;
3743+
}
3744+
}
3745+
}
3746+
3747+
for (auto &entry : TestStringMap) {
3748+
OS << " .Case(\"" << entry.getKey() << "\", " << entry.getValue()
3749+
<< ")\n";
37353750
}
3751+
37363752
OS << " .Default(0);\n";
37373753
}
37383754

0 commit comments

Comments
 (0)