[clang] [clang][CodeGen] Make `UnqualPtrTy` truly unqualified (PR #94388)
Alex Voicu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 6 08:41:02 PDT 2024
https://github.com/AlexVlx updated https://github.com/llvm/llvm-project/pull/94388
>From cdf95a804614950167d2d4df227d06a86a70d4bb Mon Sep 17 00:00:00 2001
From: Alex Voicu <alexandru.voicu at amd.com>
Date: Tue, 4 Jun 2024 19:52:28 +0100
Subject: [PATCH 1/2] Unqualified `ptr`s should be truly unqualified, and not
AS0 ptrs.
---
clang/lib/CodeGen/CodeGenModule.cpp | 1 +
clang/lib/CodeGen/CodeGenTypeCache.h | 4 +++-
clang/lib/CodeGen/ItaniumCXXABI.cpp | 6 +++---
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index be7bf0b72dc0c..b58ca03ce69da 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -368,6 +368,7 @@ CodeGenModule::CodeGenModule(ASTContext &C,
IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
IntPtrTy = llvm::IntegerType::get(LLVMContext,
C.getTargetInfo().getMaxPointerWidth());
+ UnqualPtrTy = llvm::PointerType::getUnqual(LLVMContext);
Int8PtrTy = llvm::PointerType::get(LLVMContext,
C.getTargetAddressSpace(LangAS::Default));
const llvm::DataLayout &DL = M.getDataLayout();
diff --git a/clang/lib/CodeGen/CodeGenTypeCache.h b/clang/lib/CodeGen/CodeGenTypeCache.h
index e273ebe3b060f..3b659bc182aa4 100644
--- a/clang/lib/CodeGen/CodeGenTypeCache.h
+++ b/clang/lib/CodeGen/CodeGenTypeCache.h
@@ -51,9 +51,11 @@ struct CodeGenTypeCache {
llvm::IntegerType *PtrDiffTy;
};
+ /// unqualified void*
+ llvm::PointerType *UnqualPtrTy;
+
/// void*, void** in the target's default address space (often 0)
union {
- llvm::PointerType *UnqualPtrTy;
llvm::PointerType *VoidPtrTy;
llvm::PointerType *Int8PtrTy;
llvm::PointerType *VoidPtrPtrTy;
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 8427286dee887..8952e7ca072da 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -4656,14 +4656,14 @@ static void InitCatchParam(CodeGenFunction &CGF,
auto catchRD = CatchType->getAsCXXRecordDecl();
CharUnits caughtExnAlignment = CGF.CGM.getClassPointerAlignment(catchRD);
- llvm::Type *PtrTy = CGF.UnqualPtrTy; // addrspace 0 ok
+ llvm::Type *PtrTy = CGF.UnqualPtrTy; // unqualified is ok
// Check for a copy expression. If we don't have a copy expression,
// that means a trivial copy is okay.
const Expr *copyExpr = CatchParam.getInit();
if (!copyExpr) {
llvm::Value *rawAdjustedExn = CallBeginCatch(CGF, Exn, true);
- Address adjustedExn(CGF.Builder.CreateBitCast(rawAdjustedExn, PtrTy),
+ Address adjustedExn(CGF.Builder.CreatePointerCast(rawAdjustedExn, PtrTy),
LLVMCatchTy, caughtExnAlignment);
LValue Dest = CGF.MakeAddrLValue(ParamAddr, CatchType);
LValue Src = CGF.MakeAddrLValue(adjustedExn, CatchType);
@@ -4677,7 +4677,7 @@ static void InitCatchParam(CodeGenFunction &CGF,
CGF.EmitNounwindRuntimeCall(getGetExceptionPtrFn(CGF.CGM), Exn);
// Cast that to the appropriate type.
- Address adjustedExn(CGF.Builder.CreateBitCast(rawAdjustedExn, PtrTy),
+ Address adjustedExn(CGF.Builder.CreatePointerCast(rawAdjustedExn, PtrTy),
LLVMCatchTy, caughtExnAlignment);
// The copy expression is defined in terms of an OpaqueValueExpr.
>From 5eef3a90a2dcfa08aa84bef3f40db17845911039 Mon Sep 17 00:00:00 2001
From: Alex Voicu <alexandru.voicu at amd.com>
Date: Thu, 6 Jun 2024 16:40:24 +0100
Subject: [PATCH 2/2] Pointer to default should work.
---
clang/lib/CodeGen/ItaniumCXXABI.cpp | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 8952e7ca072da..0c4f0c71a41e5 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -4656,15 +4656,12 @@ static void InitCatchParam(CodeGenFunction &CGF,
auto catchRD = CatchType->getAsCXXRecordDecl();
CharUnits caughtExnAlignment = CGF.CGM.getClassPointerAlignment(catchRD);
- llvm::Type *PtrTy = CGF.UnqualPtrTy; // unqualified is ok
-
// Check for a copy expression. If we don't have a copy expression,
// that means a trivial copy is okay.
const Expr *copyExpr = CatchParam.getInit();
if (!copyExpr) {
llvm::Value *rawAdjustedExn = CallBeginCatch(CGF, Exn, true);
- Address adjustedExn(CGF.Builder.CreatePointerCast(rawAdjustedExn, PtrTy),
- LLVMCatchTy, caughtExnAlignment);
+ Address adjustedExn(rawAdjustedExn, LLVMCatchTy, caughtExnAlignment);
LValue Dest = CGF.MakeAddrLValue(ParamAddr, CatchType);
LValue Src = CGF.MakeAddrLValue(adjustedExn, CatchType);
CGF.EmitAggregateCopy(Dest, Src, CatchType, AggValueSlot::DoesNotOverlap);
@@ -4676,9 +4673,7 @@ static void InitCatchParam(CodeGenFunction &CGF,
llvm::CallInst *rawAdjustedExn =
CGF.EmitNounwindRuntimeCall(getGetExceptionPtrFn(CGF.CGM), Exn);
- // Cast that to the appropriate type.
- Address adjustedExn(CGF.Builder.CreatePointerCast(rawAdjustedExn, PtrTy),
- LLVMCatchTy, caughtExnAlignment);
+ Address adjustedExn(rawAdjustedExn, LLVMCatchTy, caughtExnAlignment);
// The copy expression is defined in terms of an OpaqueValueExpr.
// Find it and map it to the adjusted expression.
More information about the cfe-commits
mailing list