aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
diff options
context:
space:
mode:
authorAndy Kaylor <akaylor@nvidia.com>2025-03-25 16:13:57 -0700
committerGitHub <noreply@github.com>2025-03-25 16:13:57 -0700
commitbff94d774cda03e43aff1cdf6e4945136bbab3d7 (patch)
tree4cf45a234f69f47577523f60af4f27c97dfa03ae /clang/lib/CIR/CodeGen/CIRGenFunction.cpp
parente04d739522f9df450c88bb1ec17cbd39c0babf8f (diff)
downloadllvm-bff94d774cda03e43aff1cdf6e4945136bbab3d7.zip
llvm-bff94d774cda03e43aff1cdf6e4945136bbab3d7.tar.gz
llvm-bff94d774cda03e43aff1cdf6e4945136bbab3d7.tar.bz2
[CIR] Emit allocas into the proper lexical scope (#132468)
Alloca operations were being emitted into the entry block of the current function unconditionally, even if the variable they represented was declared in a different scope. This change upstreams the code for handling insertion of the alloca into the proper lexcial scope. It also adds a CIR-to-CIR transformation to hoist allocas to the function entry block, which is necessary to produce the expected LLVM IR during lowering.
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenFunction.cpp')
-rw-r--r--clang/lib/CIR/CodeGen/CIRGenFunction.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
index 4ba3d41..47fc908 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
@@ -138,7 +138,8 @@ mlir::Location CIRGenFunction::getLoc(mlir::Location lhs, mlir::Location rhs) {
void CIRGenFunction::emitAndUpdateRetAlloca(QualType type, mlir::Location loc,
CharUnits alignment) {
if (!type->isVoidType()) {
- fnRetAlloca = emitAlloca("__retval", convertType(type), loc, alignment);
+ fnRetAlloca = emitAlloca("__retval", convertType(type), loc, alignment,
+ /*insertIntoFnEntryBlock=*/false);
}
}
@@ -293,7 +294,8 @@ void CIRGenFunction::startFunction(GlobalDecl gd, QualType returnType,
mlir::Value addrVal =
emitAlloca(cast<NamedDecl>(paramVar)->getName(),
- convertType(paramVar->getType()), paramLoc, alignment);
+ convertType(paramVar->getType()), paramLoc, alignment,
+ /*insertIntoFnEntryBlock=*/true);
declare(addrVal, paramVar, paramVar->getType(), paramLoc, alignment,
/*isParam=*/true);