Skip to content

Commit 4d700ff

Browse files
committed
[clang][Interp] Implement ImplicitValueInitExprs
Take the existing Zero opcode and emit it. Differential Revision: https://reviews.llvm.org/D132829
1 parent 95e6a40 commit 4d700ff

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ bool ByteCodeExprGen<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
223223
return this->bail(BO);
224224
}
225225

226+
template <class Emitter>
227+
bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E) {
228+
if (Optional<PrimType> T = classify(E))
229+
return this->emitZero(*T, E);
230+
231+
return false;
232+
}
233+
226234
template <class Emitter>
227235
bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
228236
OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/true);

clang/lib/AST/Interp/ByteCodeExprGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
7575
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
7676
bool VisitUnaryOperator(const UnaryOperator *E);
7777
bool VisitDeclRefExpr(const DeclRefExpr *E);
78+
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E);
7879

7980
protected:
8081
bool visitExpr(const Expr *E) override;

clang/lib/AST/Interp/Opcodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def ConstBool : ConstOpcode<Bool, ArgBool>;
203203
// [] -> [Integer]
204204
def Zero : Opcode {
205205
let Types = [AluTypeClass];
206+
let HasGroup = 1;
206207
}
207208

208209
// [] -> [Pointer]

clang/test/AST/Interp/arrays.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
2+
// RUN: %clang_cc1 -verify=ref %s
3+
4+
5+
/// expected-no-diagnostics
6+
/// ref-no-diagnostics
7+
8+
#pragma clang diagnostic push
9+
#pragma clang diagnostic ignored "-Wc99-extensions"
10+
#pragma clang diagnostic ignored "-Winitializer-overrides"
11+
/// FIXME: The example below tests ImplicitValueInitExprs, but we can't
12+
/// currently evaluate other parts of it.
13+
#if 0
14+
struct fred {
15+
char s [6];
16+
int n;
17+
};
18+
19+
struct fred y [] = { [0] = { .s[0] = 'q' } };
20+
#endif
21+
#pragma clang diagnostic pop

0 commit comments

Comments
 (0)