Skip to content

Commit fea05b5

Browse files
committed
[clang][bytecode] Allow forming pointers to fields of extern globals
This should be fine as long as we're not reading from it. Note that this regresses CXX/special/class.init/class.inhctor.init/p1.cpp, which used to work fine with the bytecode interpreter. That's because this code now fails: struct Param; struct A { constexpr A(Param); int a; }; struct B : A { B(); using A::A; int b = 2; }; struct Wrap1 : B { constexpr Wrap1(); }; struct Wrap2 : Wrap1 {}; extern const Wrap2 b; struct Param { constexpr Param(int c) : n(4 * b.a + b.b + c) {} int n; }; and reports that the Param() constructor is never a valid constant expression. But that's true and the current interpeter should report that as well. It also fails when calling at compile time.
1 parent 82c25d2 commit fea05b5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,8 +1323,6 @@ static bool getField(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
13231323
!CheckNull(S, OpPC, Ptr, CSK_Field))
13241324
return false;
13251325

1326-
if (!CheckExtern(S, OpPC, Ptr))
1327-
return false;
13281326
if (!CheckRange(S, OpPC, Ptr, CSK_Field))
13291327
return false;
13301328
if (!CheckArray(S, OpPC, Ptr))

clang/test/AST/ByteCode/cxx11.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,9 @@ namespace DynamicCast {
194194
int g : (S*)(void*)(sptr) == sptr;
195195
};
196196
}
197+
198+
namespace ExternPointer {
199+
struct S { int a; };
200+
extern const S pu;
201+
constexpr const int *pua = &pu.a; // Ok.
202+
}

0 commit comments

Comments
 (0)