Skip to content

Commit 35638f6

Browse files
tbaederrDanielCChen
authored andcommitted
[clang][bytecode] Use PredefinedExpr as base for its variable (llvm#111956)
This fixes the error message generated.
1 parent 0e7f299 commit 35638f6

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,11 @@ bool Compiler<Emitter>::VisitPredefinedExpr(const PredefinedExpr *E) {
28692869
if (DiscardResult)
28702870
return true;
28712871

2872+
if (!Initializing) {
2873+
unsigned StringIndex = P.createGlobalString(E->getFunctionName(), E);
2874+
return this->emitGetPtrGlobal(StringIndex, E);
2875+
}
2876+
28722877
return this->delegate(E->getFunctionName());
28732878
}
28742879

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const void *Program::getNativePointer(unsigned Idx) {
3333
return NativePointers[Idx];
3434
}
3535

36-
unsigned Program::createGlobalString(const StringLiteral *S) {
36+
unsigned Program::createGlobalString(const StringLiteral *S, const Expr *Base) {
3737
const size_t CharWidth = S->getCharByteWidth();
3838
const size_t BitWidth = CharWidth * Ctx.getCharBit();
3939

@@ -52,12 +52,15 @@ unsigned Program::createGlobalString(const StringLiteral *S) {
5252
llvm_unreachable("unsupported character width");
5353
}
5454

55+
if (!Base)
56+
Base = S;
57+
5558
// Create a descriptor for the string.
56-
Descriptor *Desc =
57-
allocateDescriptor(S, CharType, Descriptor::GlobalMD, S->getLength() + 1,
58-
/*isConst=*/true,
59-
/*isTemporary=*/false,
60-
/*isMutable=*/false);
59+
Descriptor *Desc = allocateDescriptor(Base, CharType, Descriptor::GlobalMD,
60+
S->getLength() + 1,
61+
/*isConst=*/true,
62+
/*isTemporary=*/false,
63+
/*isMutable=*/false);
6164

6265
// Allocate storage for the string.
6366
// The byte length does not include the null terminator.

clang/lib/AST/ByteCode/Program.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class Program final {
6464
const void *getNativePointer(unsigned Idx);
6565

6666
/// Emits a string literal among global data.
67-
unsigned createGlobalString(const StringLiteral *S);
67+
unsigned createGlobalString(const StringLiteral *S,
68+
const Expr *Base = nullptr);
6869

6970
/// Returns a pointer to a global.
7071
Pointer getPtrGlobal(unsigned Idx) const;

clang/test/AST/ByteCode/cxx1z.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ namespace Temp {
1313

1414
char arr[3];
1515
A<const char*, &arr[1]> d; // both-error {{refers to subobject '&arr[1]'}}
16+
17+
void Func() {
18+
A<const char*, __func__> a; // both-error {{pointer to subobject of predefined '__func__' variable}}
19+
}

0 commit comments

Comments
 (0)