[clang] 5099dc3 - [Clang][CodeGen] Fix use of CXXThisValue with StrictVTablePointers (#68169)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 4 14:41:54 PDT 2023
Author: Matheus Izvekov
Date: 2023-10-04T23:41:49+02:00
New Revision: 5099dc341f7fa9baec160c2991072eb445469d46
URL: https://github.com/llvm/llvm-project/commit/5099dc341f7fa9baec160c2991072eb445469d46
DIFF: https://github.com/llvm/llvm-project/commit/5099dc341f7fa9baec160c2991072eb445469d46.diff
LOG: [Clang][CodeGen] Fix use of CXXThisValue with StrictVTablePointers (#68169)
Added:
Modified:
clang/lib/CodeGen/CGClass.cpp
clang/test/CodeGenCXX/strict-vtable-pointers-GH67937.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 57a424c6f176c47..d18f186ce5b4157 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -28,6 +28,7 @@
#include "clang/CodeGen/CGFunctionInfo.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Metadata.h"
+#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Transforms/Utils/SanitizerStats.h"
#include <optional>
@@ -1291,10 +1292,10 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
assert(BaseCtorContinueBB);
}
- llvm::Value *const OldThis = CXXThisValue;
for (; B != E && (*B)->isBaseInitializer() && (*B)->isBaseVirtual(); B++) {
if (!ConstructVBases)
continue;
+ SaveAndRestore ThisRAII(CXXThisValue);
if (CGM.getCodeGenOpts().StrictVTablePointers &&
CGM.getCodeGenOpts().OptimizationLevel > 0 &&
isInitializerOfDynamicClass(*B))
@@ -1311,7 +1312,7 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
// Then, non-virtual base initializers.
for (; B != E && (*B)->isBaseInitializer(); B++) {
assert(!(*B)->isBaseVirtual());
-
+ SaveAndRestore ThisRAII(CXXThisValue);
if (CGM.getCodeGenOpts().StrictVTablePointers &&
CGM.getCodeGenOpts().OptimizationLevel > 0 &&
isInitializerOfDynamicClass(*B))
@@ -1319,8 +1320,6 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD,
EmitBaseInitializer(*this, ClassDecl, *B);
}
- CXXThisValue = OldThis;
-
InitializeVTablePointers(ClassDecl);
// And finally, initialize class members.
diff --git a/clang/test/CodeGenCXX/strict-vtable-pointers-GH67937.cpp b/clang/test/CodeGenCXX/strict-vtable-pointers-GH67937.cpp
index 6fb1e68c288b181..692ca23a69abe6a 100644
--- a/clang/test/CodeGenCXX/strict-vtable-pointers-GH67937.cpp
+++ b/clang/test/CodeGenCXX/strict-vtable-pointers-GH67937.cpp
@@ -1,6 +1,5 @@
-// RUN: %clang_cc1 %s -I%S -triple=x86_64-pc-windows-msvc -fstrict-vtable-pointers -disable-llvm-passes -disable-llvm-verifier -O1 -emit-llvm -o %t.ll
+// RUN: %clang_cc1 %s -I%S -triple=x86_64-pc-windows-msvc -fstrict-vtable-pointers -disable-llvm-passes -O1 -emit-llvm -o %t.ll
// RUN: FileCheck %s < %t.ll
-// RUN: not llvm-as < %t.ll -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-VERIFIER
struct A {
virtual ~A();
@@ -9,11 +8,6 @@ struct B : virtual A {};
class C : B {};
C foo;
-// FIXME: This is not supposed to generate invalid IR!
-// CHECK-VERIFIER: Instruction does not dominate all uses!
-// CHECK-VERIFIER-NEXT: %1 = call ptr @llvm.launder.invariant.group.p0(ptr %this1)
-// CHECK-VERIFIER-NEXT: %3 = call ptr @llvm.launder.invariant.group.p0(ptr %1)
-
// CHECK-LABEL: define {{.*}} @"??0C@@QEAA at XZ"(ptr {{.*}} %this, i32 {{.*}} %is_most_derived)
// CHECK: ctor.init_vbases:
// CHECK-NEXT: %0 = getelementptr inbounds i8, ptr %this1, i64 0
@@ -24,6 +18,5 @@ C foo;
// CHECK-NEXT: br label %ctor.skip_vbases
// CHECK-EMPTY:
// CHECK-NEXT: ctor.skip_vbases:
-// FIXME: Should be using '%this1' instead of %1 below.
-// CHECK-NEXT: %3 = call ptr @llvm.launder.invariant.group.p0(ptr %1)
+// CHECK-NEXT: %3 = call ptr @llvm.launder.invariant.group.p0(ptr %this1)
// CHECK-NEXT: %call3 = call noundef ptr @"??0B@@QEAA at XZ"(ptr {{.*}} %3, i32 noundef 0) #2
More information about the cfe-commits
mailing list