Skip to content

Commit e32bbae

Browse files
author
git apple-llvm automerger
committed
Merge commit '385752c9b5f2' from llvm.org/main into next
2 parents 5523267 + 385752c commit e32bbae

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ Bug Fixes in This Version
628628
- Fix crash due to unknown references and pointer implementation and handling of
629629
base classes. (GH139452)
630630
- Fixed an assertion failure in serialization of constexpr structs containing unions. (#GH140130)
631+
- Fixed duplicate entries in TableGen that caused the wrong attribute to be selected. (GH#140701)
631632

632633
Bug Fixes to Compiler Builtins
633634
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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: 25 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"
@@ -3675,6 +3676,12 @@ static bool GenerateTargetSpecificAttrChecks(const Record *R,
36753676
static void GenerateHasAttrSpellingStringSwitch(
36763677
ArrayRef<std::pair<const Record *, FlattenedSpelling>> Attrs,
36773678
raw_ostream &OS, StringRef Variety, StringRef Scope = "") {
3679+
3680+
// It turns out that there are duplicate records for a given spelling. This
3681+
// map combines matching test strings using '||'. For example, if there are
3682+
// three conditions A, B, and C, the final result will be: A || B || C.
3683+
llvm::StringMap<std::string> TestStringMap;
3684+
36783685
for (const auto &[Attr, Spelling] : Attrs) {
36793686
// C++11-style attributes have specific version information associated with
36803687
// them. If the attribute has no scope, the version information must not
@@ -3735,12 +3742,25 @@ static void GenerateHasAttrSpellingStringSwitch(
37353742
}
37363743
}
37373744

3738-
std::string TestStr = !Test.empty()
3739-
? Test + " ? " + itostr(Version) + " : 0"
3740-
: itostr(Version);
3741-
if (Scope.empty() || Scope == Spelling.nameSpace())
3742-
OS << " .Case(\"" << Spelling.name() << "\", " << TestStr << ")\n";
3745+
std::string TestStr =
3746+
!Test.empty() ? '(' + Test + " ? " + itostr(Version) + " : 0" + ')'
3747+
: '(' + itostr(Version) + ')';
3748+
3749+
if (Scope.empty() || Scope == Spelling.nameSpace()) {
3750+
if (TestStringMap.contains(Spelling.name()))
3751+
TestStringMap[Spelling.name()] += " || " + TestStr;
3752+
else
3753+
TestStringMap[Spelling.name()] = TestStr;
3754+
}
3755+
}
3756+
3757+
// Create the actual string switch statement after all the attributes have
3758+
// been parsed.
3759+
for (auto &Entry : TestStringMap) {
3760+
OS << " .Case(\"" << Entry.getKey() << "\", " << Entry.getValue()
3761+
<< ")\n";
37433762
}
3763+
37443764
OS << " .Default(0);\n";
37453765
}
37463766

0 commit comments

Comments
 (0)