Skip to content

Commit

Permalink
[clang] Correct behavior of LLVM_UNREACHABLE_OPTIMIZE=OFF for `Rele…
Browse files Browse the repository at this point in the history
…ase` builds (#68284)

# Codegen
### Before
```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);
}
```

### After
```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
  • Loading branch information
MasterAwesome committed Oct 5, 2023
1 parent a50e63b commit bffbe9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ Bug Fixes in This Version
- Fix a crash when evaluating value-dependent structured binding
variables at compile time.
Fixes (`#67690 <https://github.com/llvm/llvm-project/issues/67690>`_)
- Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_).

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
17 changes: 11 additions & 6 deletions clang/utils/TableGen/ClangAttrEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2690,23 +2690,28 @@ static void emitAttributes(RecordKeeper &Records, raw_ostream &OS,
OS << ", ";
emitFormInitializer(OS, Spellings[0], "0");
} else {
OS << ", (\n";
OS << ", [&]() {\n";
OS << " switch (S) {\n";
std::set<std::string> Uniques;
unsigned Idx = 0;
for (auto I = Spellings.begin(), E = Spellings.end(); I != E;
++I, ++Idx) {
const FlattenedSpelling &S = *I;
const auto &Name = SemanticToSyntacticMap[Idx];
if (Uniques.insert(Name).second) {
OS << " S == " << Name << " ? AttributeCommonInfo::Form";
OS << " case " << Name << ":\n";
OS << " return AttributeCommonInfo::Form";
emitFormInitializer(OS, S, Name);
OS << " :\n";
OS << ";\n";
}
}
OS << " (llvm_unreachable(\"Unknown attribute spelling!\"), "
<< " AttributeCommonInfo::Form";
OS << " default:\n";
OS << " llvm_unreachable(\"Unknown attribute spelling!\");\n"
<< " return AttributeCommonInfo::Form";
emitFormInitializer(OS, Spellings[0], "0");
OS << "))";
OS << ";\n"
<< " }\n"
<< " }()";
}

OS << ");\n";
Expand Down

0 comments on commit bffbe9a

Please sign in to comment.