Skip to content

Commit 87377cd

Browse files
committed
[clang][bytecode] Emit diagnostics from GetGlobalUnchecked
If the global is uninitialized.
1 parent 82c25d2 commit 87377cd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ bool GetGlobal(InterpState &S, CodePtr OpPC, uint32_t I) {
14331433
template <PrimType Name, class T = typename PrimConv<Name>::T>
14341434
bool GetGlobalUnchecked(InterpState &S, CodePtr OpPC, uint32_t I) {
14351435
const Pointer &Ptr = S.P.getPtrGlobal(I);
1436-
if (!Ptr.isInitialized())
1436+
if (!CheckInitialized(S, OpPC, Ptr, AK_Read))
14371437
return false;
14381438
S.Stk.push<T>(Ptr.deref<T>());
14391439
return true;

clang/test/AST/ByteCode/cxx11.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,11 @@ namespace DynamicCast {
194194
int g : (S*)(void*)(sptr) == sptr;
195195
};
196196
}
197+
198+
namespace GlobalInitializer {
199+
extern int &g; // both-note {{here}}
200+
struct S {
201+
int G : g; // both-error {{constant expression}} \
202+
// both-note {{initializer of 'g' is unknown}}
203+
};
204+
}

0 commit comments

Comments
 (0)