[clang] ff04bb8 - [clang][bytecode] Use PredefinedExpr as base for its variable (#111956)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 11 00:31:53 PDT 2024
Author: Timm Baeder
Date: 2024-10-11T09:31:49+02:00
New Revision: ff04bb8f4064274aedcb6e916079132ab6042a10
URL: https://github.com/llvm/llvm-project/commit/ff04bb8f4064274aedcb6e916079132ab6042a10
DIFF: https://github.com/llvm/llvm-project/commit/ff04bb8f4064274aedcb6e916079132ab6042a10.diff
LOG: [clang][bytecode] Use PredefinedExpr as base for its variable (#111956)
This fixes the error message generated.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Program.cpp
clang/lib/AST/ByteCode/Program.h
clang/test/AST/ByteCode/cxx1z.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 0a3b38b0dc6e57..b2663714340b93 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2869,6 +2869,11 @@ bool Compiler<Emitter>::VisitPredefinedExpr(const PredefinedExpr *E) {
if (DiscardResult)
return true;
+ if (!Initializing) {
+ unsigned StringIndex = P.createGlobalString(E->getFunctionName(), E);
+ return this->emitGetPtrGlobal(StringIndex, E);
+ }
+
return this->delegate(E->getFunctionName());
}
diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp
index 23245a66b578ae..cd2665f755d7cb 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -33,7 +33,7 @@ const void *Program::getNativePointer(unsigned Idx) {
return NativePointers[Idx];
}
-unsigned Program::createGlobalString(const StringLiteral *S) {
+unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) {
const size_t CharWidth = S->getCharByteWidth();
const size_t BitWidth = CharWidth * Ctx.getCharBit();
@@ -52,12 +52,15 @@ unsigned Program::createGlobalString(const StringLiteral *S) {
llvm_unreachable("unsupported character width");
}
+ if (!Base)
+ Base = S;
+
// Create a descriptor for the string.
- Descriptor *Desc =
- allocateDescriptor(S, CharType, Descriptor::GlobalMD, S->getLength() + 1,
- /*isConst=*/true,
- /*isTemporary=*/false,
- /*isMutable=*/false);
+ Descriptor *Desc = allocateDescriptor(Base, CharType, Descriptor::GlobalMD,
+ S->getLength() + 1,
+ /*isConst=*/true,
+ /*isTemporary=*/false,
+ /*isMutable=*/false);
// Allocate storage for the string.
// The byte length does not include the null terminator.
diff --git a/clang/lib/AST/ByteCode/Program.h b/clang/lib/AST/ByteCode/Program.h
index be84c40714a60b..f676672fb7ced5 100644
--- a/clang/lib/AST/ByteCode/Program.h
+++ b/clang/lib/AST/ByteCode/Program.h
@@ -64,7 +64,8 @@ class Program final {
const void *getNativePointer(unsigned Idx);
/// Emits a string literal among global data.
- unsigned createGlobalString(const StringLiteral *S);
+ unsigned createGlobalString(const StringLiteral *S,
+ const Expr *Base = nullptr);
/// Returns a pointer to a global.
Pointer getPtrGlobal(unsigned Idx) const;
diff --git a/clang/test/AST/ByteCode/cxx1z.cpp b/clang/test/AST/ByteCode/cxx1z.cpp
index 1a06597fa348fe..57f99235a2b201 100644
--- a/clang/test/AST/ByteCode/cxx1z.cpp
+++ b/clang/test/AST/ByteCode/cxx1z.cpp
@@ -13,3 +13,7 @@ namespace Temp {
char arr[3];
A<const char*, &arr[1]> d; // both-error {{refers to subobject '&arr[1]'}}
+
+void Func() {
+ A<const char*, __func__> a; // both-error {{pointer to subobject of predefined '__func__' variable}}
+}
More information about the cfe-commits
mailing list