diff options
author | Morris Hafner <mmha@users.noreply.github.com> | 2025-08-20 13:30:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-20 13:30:21 +0200 |
commit | b01f05977ce65dc71fed07cd64684a182e983533 (patch) | |
tree | 787e49476790ac175ac63c727fb608fed1aa8ec8 /clang/lib/CIR/CodeGen/CIRGenModule.cpp | |
parent | 8b128388b527ac196e06115dd2496e2e9d59e565 (diff) | |
download | llvm-b01f05977ce65dc71fed07cd64684a182e983533.zip llvm-b01f05977ce65dc71fed07cd64684a182e983533.tar.gz llvm-b01f05977ce65dc71fed07cd64684a182e983533.tar.bz2 |
[CIR] Add support for string literal lvalues in ConstantLValueEmitter (#154514)
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.cpp')
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenModule.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 7c52adc..cb8cc30 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -1318,6 +1318,19 @@ cir::GlobalOp CIRGenModule::getGlobalForStringLiteral(const StringLiteral *s, return gv; } +/// Return a pointer to a constant array for the given string literal. +cir::GlobalViewAttr +CIRGenModule::getAddrOfConstantStringFromLiteral(const StringLiteral *s, + StringRef name) { + cir::GlobalOp gv = getGlobalForStringLiteral(s, name); + auto arrayTy = mlir::dyn_cast<cir::ArrayType>(gv.getSymType()); + assert(arrayTy && "String literal must be array"); + assert(!cir::MissingFeatures::addressSpace()); + cir::PointerType ptrTy = getBuilder().getPointerTo(arrayTy.getElementType()); + + return builder.getGlobalViewAttr(ptrTy, gv); +} + void CIRGenModule::emitExplicitCastExprType(const ExplicitCastExpr *e, CIRGenFunction *cgf) { if (cgf && e->getType()->isVariablyModifiedType()) |