Skip to content

Commit e7b3b94

Browse files
MasterAwesometru
authored andcommitted
[clang] Correct behavior of LLVM_UNREACHABLE_OPTIMIZE=OFF for Release builds (#68284)
```c++ AArch64SVEPcsAttr *AArch64SVEPcsAttr::CreateImplicit(ASTContext &Ctx, SourceRange Range, Spelling S) { AttributeCommonInfo I(Range, NoSemaHandlerAttribute, ( S == GNU_aarch64_sve_pcs ? AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, GNU_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/} : S == CXX11_clang_aarch64_sve_pcs ? AttributeCommonInfo::Form{AttributeCommonInfo::AS_CXX11, CXX11_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/} : S == C23_clang_aarch64_sve_pcs ? AttributeCommonInfo::Form{AttributeCommonInfo::AS_C23, C23_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/} : (llvm_unreachable("Unknown attribute spelling!"), AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, 0, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}))); return CreateImplicit(Ctx, I); } ``` ```c++ AArch64SVEPcsAttr *AArch64SVEPcsAttr::CreateImplicit(ASTContext &Ctx, SourceRange Range, Spelling S) { AttributeCommonInfo I(Range, NoSemaHandlerAttribute, [&]() { switch (S) { case GNU_aarch64_sve_pcs: return AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, GNU_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}; case CXX11_clang_aarch64_sve_pcs: return AttributeCommonInfo::Form{AttributeCommonInfo::AS_CXX11, CXX11_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}; case C23_clang_aarch64_sve_pcs: return AttributeCommonInfo::Form{AttributeCommonInfo::AS_C23, C23_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}; default: llvm_unreachable("Unknown attribute spelling!"); return AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, 0, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/}; } }()); return CreateImplicit(Ctx, I); } ``` Fixes #68237 Conflicts: clang/docs/ReleaseNotes.rst
1 parent f0a687d commit e7b3b94

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

clang/docs/ReleaseNotes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ Bug Fixes in This Version
717717
virtual member functions even if the target required a greater function
718718
alignment and/or did not have function pointers which point to function entry
719719
points (i.e., uses function descriptor objects instead).
720+
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
721+
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).
720722

721723
Bug Fixes to Compiler Builtins
722724
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/utils/TableGen/ClangAttrEmitter.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -2639,23 +2639,28 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
26392639
OS << ", ";
26402640
emitFormInitializer(OS, Spellings[0], "0");
26412641
} else {
2642-
OS << ", (\n";
2642+
OS << ", [&]() {\n";
2643+
OS << " switch (S) {\n";
26432644
std::set<std::string> Uniques;
26442645
unsigned Idx = 0;
26452646
for (auto I = Spellings.begin(), E = Spellings.end(); I != E;
26462647
++I, ++Idx) {
26472648
const FlattenedSpelling &S = *I;
26482649
const auto &Name = SemanticToSyntacticMap[Idx];
26492650
if (Uniques.insert(Name).second) {
2650-
OS << " S == " << Name << " ? AttributeCommonInfo::Form";
2651+
OS << " case " << Name << ":\n";
2652+
OS << " return AttributeCommonInfo::Form";
26512653
emitFormInitializer(OS, S, Name);
2652-
OS << " :\n";
2654+
OS << ";\n";
26532655
}
26542656
}
2655-
OS << " (llvm_unreachable(\"Unknown attribute spelling!\"), "
2656-
<< " AttributeCommonInfo::Form";
2657+
OS << " default:\n";
2658+
OS << " llvm_unreachable(\"Unknown attribute spelling!\");\n"
2659+
<< " return AttributeCommonInfo::Form";
26572660
emitFormInitializer(OS, Spellings[0], "0");
2658-
OS << "))";
2661+
OS << ";\n"
2662+
<< " }\n"
2663+
<< " }()";
26592664
}
26602665

26612666
OS << ");\n";

0 commit comments

Comments
 (0)