Skip to content

Commit 2ba1cc8

Browse files
authored
[Clang][CodeGen] Fix bad codegen when building Clang with latest MSVC (#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](#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
1 parent fe31363 commit 2ba1cc8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,10 +2092,15 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
20922092
auto *classStart =
20932093
llvm::StructType::get(PtrTy, PtrTy, PtrTy, LongTy, LongTy);
20942094
auto &astContext = CGM.getContext();
2095-
auto flags = Builder.CreateLoad(
2096-
Address{Builder.CreateStructGEP(classStart, selfValue, 4), LongTy,
2097-
CharUnits::fromQuantity(
2098-
astContext.getTypeAlign(astContext.UnsignedLongTy))});
2095+
// FIXME: The following few lines up to and including the call to
2096+
// `CreateLoad` were known to miscompile when MSVC 19.40.33813 is used
2097+
// to build Clang. When the bug is fixed in future MSVC releases, we
2098+
// should revert these lines to their previous state. See discussion in
2099+
// https://github.com/llvm/llvm-project/pull/102681
2100+
llvm::Value *Val = Builder.CreateStructGEP(classStart, selfValue, 4);
2101+
auto Align = CharUnits::fromQuantity(
2102+
astContext.getTypeAlign(astContext.UnsignedLongTy));
2103+
auto flags = Builder.CreateLoad(Address{Val, LongTy, Align});
20992104
auto isInitialized =
21002105
Builder.CreateAnd(flags, ClassFlags::ClassFlagInitialized);
21012106
llvm::BasicBlock *notInitializedBlock =

0 commit comments

Comments
 (0)