Skip to content

Commit

Permalink
[clang][Interp] Fix failure to allocate local variables
Browse files Browse the repository at this point in the history
We were incorrectly returning true when the allocateLocal() call
failed.
  • Loading branch information
tbaederr committed Feb 19, 2024
1 parent 6b32ba6 commit eddf9cf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 3 additions & 4 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2749,10 +2749,9 @@ bool ByteCodeExprGen<Emitter>::visitVarDecl(const VarDecl *VD) {
return this->emitSetLocal(*VarT, Offset, VD);
}
} else {
if (std::optional<unsigned> Offset = this->allocateLocal(VD)) {
if (Init)
return this->visitLocalInitializer(Init, *Offset);
}
if (std::optional<unsigned> Offset = this->allocateLocal(VD))
return !Init || this->visitLocalInitializer(Init, *Offset);
return false;
}
return true;
}
Expand Down
19 changes: 19 additions & 0 deletions clang/test/AST/Interp/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,22 @@ namespace LocalIndex {
array[const_subscript] = 0; // both-warning {{array index 3 is past the end of the array (that has type 'int[2]')}}
}
}

namespace LocalVLA {
struct Foo {
int x;
Foo(int x) : x(x) {}
};
struct Elidable {
Elidable();
};

void foo(int size) {
Elidable elidableDynArray[size];
#if __cplusplus >= 202002L
// both-note@-3 {{declared here}}
// both-warning@-3 {{variable length array}}
// both-note@-4 {{function parameter 'size' with unknown value}}
#endif
}
}

0 comments on commit eddf9cf

Please sign in to comment.