Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build obj.clangAST when LLVM_UNREACHABLE_OPTIMIZATIONS are turned off #68237

Closed
MasterAwesome opened this issue Oct 4, 2023 · 5 comments · Fixed by #68284 or llvm/llvm-project-release-prs#726

Comments

@MasterAwesome
Copy link
Contributor

MasterAwesome commented Oct 4, 2023

I'm trying to build clang in Release mode with LLVM_UNREACHABLE_OPTIMIZATIONS turned off; however, the file AttrImpl.cpp fails to compile. This happens in release/17.x branch and main.

cmake llvm \
    -DLLVM_ENABLE_PROJECTS=clang \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_C_COMPILER=clang \
    -DCMAKE_CXX_COMPILER=clang++ \
    -DCMAKE_ASM_COMPILER=clang \
    -DLLVM_UNREACHABLE_OPTIMIZE=OFF \
    -B build
cd build/
make obj.clangAST

This seems due to the fact that on CMAKE_BUILD_TYPE=Release + LLVM_UNREACHABLE_OPTIMIZE=OFF leads to

do { \
LLVM_BUILTIN_TRAP; \
LLVM_BUILTIN_UNREACHABLE; \
} while (false)
branch which causes the tblgen'd output (AttrImpl.inc) to not compile. All other variants work [(Release + LLVM_UNREACHABLE_OPTIMIZE=ON), (Debug + LLVM_UNREACHABLE_OPTIMIZE=[ON|OFF])]

This is bisected to clang-tblgen change b6d4d51#diff-58111c7c545672c3a67b1b31a37d4103b35d9c584a46c74b0be14cc37741491bR2642-R2646

Tested with both host toolchains clang 17.0.2 and gcc 13.2.0

For Rust specific issue: Rust defaults to LLVM_UNREACHABLE_OPTIMIZE=OFF for all LLVM builds and this causes a regression when LLVM is compiled in release mode. See rust-lang/rust#109373

@MasterAwesome
Copy link
Contributor Author

MasterAwesome commented Oct 5, 2023

I can contribute to this change, where can I read about the procedure abut these types of changes, do I contribute to main using a PR and request for backport onto release/17.x. Also how do I claim the issue?

AaronBallman pushed a commit that referenced this issue Oct 5, 2023
…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
@AaronBallman AaronBallman added this to the LLVM 17.0.X Release milestone Oct 5, 2023
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Oct 5, 2023
@AaronBallman
Copy link
Collaborator

/cherry-pick bffbe9a

@llvmbot
Copy link
Member

llvmbot commented Oct 5, 2023

Failed to cherry-pick: bffbe9a

https://github.com/llvm/llvm-project/actions/runs/6423348224

Please manually backport the fix and push it to your github fork. Once this is done, please add a comment like this:

/branch <user>/<repo>/<branch>

@MasterAwesome
Copy link
Contributor Author

/branch MasterAwesome/rust-llvm-project/llvm/release/17.x

@llvmbot
Copy link
Member

llvmbot commented Oct 5, 2023

/pull-request llvm/llvm-project-release-prs#726

@tru tru moved this from Needs Triage to Needs Review in LLVM Release Status Oct 6, 2023
tru pushed a commit to llvm/llvm-project-release-prs that referenced this issue Oct 10, 2023
…ase` 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 llvm/llvm-project#68237
Conflicts:
	clang/docs/ReleaseNotes.rst
@tru tru moved this from Needs Review to Done in LLVM Release Status Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment