Skip to content

Commit eddf9cf

Browse files
committed
[clang][Interp] Fix failure to allocate local variables
We were incorrectly returning true when the allocateLocal() call failed.
1 parent 6b32ba6 commit eddf9cf

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,10 +2749,9 @@ bool ByteCodeExprGen<Emitter>::visitVarDecl(const VarDecl *VD) {
27492749
return this->emitSetLocal(*VarT, Offset, VD);
27502750
}
27512751
} else {
2752-
if (std::optional<unsigned> Offset = this->allocateLocal(VD)) {
2753-
if (Init)
2754-
return this->visitLocalInitializer(Init, *Offset);
2755-
}
2752+
if (std::optional<unsigned> Offset = this->allocateLocal(VD))
2753+
return !Init || this->visitLocalInitializer(Init, *Offset);
2754+
return false;
27562755
}
27572756
return true;
27582757
}

clang/test/AST/Interp/arrays.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,22 @@ namespace LocalIndex {
545545
array[const_subscript] = 0; // both-warning {{array index 3 is past the end of the array (that has type 'int[2]')}}
546546
}
547547
}
548+
549+
namespace LocalVLA {
550+
struct Foo {
551+
int x;
552+
Foo(int x) : x(x) {}
553+
};
554+
struct Elidable {
555+
Elidable();
556+
};
557+
558+
void foo(int size) {
559+
Elidable elidableDynArray[size];
560+
#if __cplusplus >= 202002L
561+
// both-note@-3 {{declared here}}
562+
// both-warning@-3 {{variable length array}}
563+
// both-note@-4 {{function parameter 'size' with unknown value}}
564+
#endif
565+
}
566+
}

0 commit comments

Comments
 (0)