[clang] 2ba1cc8 - [Clang][CodeGen] Fix bad codegen when building Clang with latest MSVC (#102681)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 10 13:26:14 PDT 2024
Author: Alexandre Ganea
Date: 2024-08-10T16:26:10-04:00
New Revision: 2ba1cc8ea53cd76fbeac79dad837dcae32cc7e59
URL: https://github.com/llvm/llvm-project/commit/2ba1cc8ea53cd76fbeac79dad837dcae32cc7e59
DIFF: https://github.com/llvm/llvm-project/commit/2ba1cc8ea53cd76fbeac79dad837dcae32cc7e59.diff
LOG: [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](https://github.com/llvm/llvm-project/pull/100517#issuecomment-2266269490).
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
Added:
Modified:
clang/lib/CodeGen/CGObjCGNU.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 948b10954ebbe..ca5804018227e 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -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 =
More information about the cfe-commits
mailing list