Skip to content

Commit 2cd19df

Browse files
committed
[clang][Interp] Allow visiting extern variables
If the variable is additionally const(expr), visit them like normal but omit the initializer.
1 parent 486332a commit 2cd19df

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,18 +2665,12 @@ bool ByteCodeExprGen<Emitter>::visitVarDecl(const VarDecl *VD) {
26652665
if (P.getGlobal(VD))
26662666
return true;
26672667

2668-
// Ignore external declarations. We will instead emit a dummy
2669-
// pointer when we see a DeclRefExpr for them.
2670-
if (VD->hasExternalStorage())
2671-
return true;
2672-
26732668
std::optional<unsigned> GlobalIndex = P.createGlobal(VD, Init);
26742669

26752670
if (!GlobalIndex)
26762671
return false;
26772672

2678-
assert(Init);
2679-
{
2673+
if (Init) {
26802674
DeclScope<Emitter> LocalScope(this, VD);
26812675

26822676
if (VarT) {
@@ -2686,6 +2680,7 @@ bool ByteCodeExprGen<Emitter>::visitVarDecl(const VarDecl *VD) {
26862680
}
26872681
return this->visitGlobalInitializer(Init, *GlobalIndex);
26882682
}
2683+
return true;
26892684
} else {
26902685
VariableScope<Emitter> LocalScope(this);
26912686
if (VarT) {

clang/test/AST/Interp/literals.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,11 @@ namespace incdecbool {
11901190
constexpr int externvar1() { // both-error {{never produces a constant expression}}
11911191
extern char arr[]; // ref-note {{declared here}}
11921192
return arr[0]; // ref-note {{read of non-constexpr variable 'arr'}} \
1193-
// expected-note {{indexing of array without known bound}}
1193+
// expected-note {{array-to-pointer decay of array member without known bound is not supported}}
11941194
}
11951195
#endif
1196+
1197+
namespace Extern {
1198+
constexpr extern char Oops = 1;
1199+
static_assert(Oops == 1, "");
1200+
}

0 commit comments

Comments
 (0)