Skip to content

Commit

Permalink
[Clang][CodeGen] Fix bad codegen when building Clang with latest MSVC (
Browse files Browse the repository at this point in the history
…llvm#102681)

Before this PR, when using the latest MSVC `Microsoft (R) C/C++
Optimizing Compiler Version 19.40.33813 for x64` one of the Clang unit
test used to fail: `CodeGenObjC/gnustep2-direct-method.m`, see full
failure log:
[here](llvm#100517 (comment)).

This PR temporarily shuffles around the code to make the MSVC inliner/
optimizer happy and avoid the bug.

MSVC bug report:
https://developercommunity.visualstudio.com/t/Bad-code-generation-when-building-LLVM-w/10719589?port=1025&fsid=e572244a-cde7-4d75-a73d-9b8cd94204dd
  • Loading branch information
aganea authored and bwendling committed Aug 15, 2024
1 parent dfafa42 commit 003af69
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions clang/lib/CodeGen/CGObjCGNU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2092,10 +2092,15 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
auto *classStart =
llvm::StructType::get(PtrTy, PtrTy, PtrTy, LongTy, LongTy);
auto &astContext = CGM.getContext();
auto flags = Builder.CreateLoad(
Address{Builder.CreateStructGEP(classStart, selfValue, 4), LongTy,
CharUnits::fromQuantity(
astContext.getTypeAlign(astContext.UnsignedLongTy))});
// FIXME: The following few lines up to and including the call to
// `CreateLoad` were known to miscompile when MSVC 19.40.33813 is used
// to build Clang. When the bug is fixed in future MSVC releases, we
// should revert these lines to their previous state. See discussion in
// https://github.com/llvm/llvm-project/pull/102681
llvm::Value *Val = Builder.CreateStructGEP(classStart, selfValue, 4);
auto Align = CharUnits::fromQuantity(
astContext.getTypeAlign(astContext.UnsignedLongTy));
auto flags = Builder.CreateLoad(Address{Val, LongTy, Align});
auto isInitialized =
Builder.CreateAnd(flags, ClassFlags::ClassFlagInitialized);
llvm::BasicBlock *notInitializedBlock =
Expand Down

0 comments on commit 003af69

Please sign in to comment.