Skip to content

Commit

Permalink
[clang][Interp] Finish initializing structs from CompoundLiteralExprs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Apr 18, 2024
1 parent c674dbc commit fd98f80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundLiteralExpr(
const Expr *Init = E->getInitializer();
if (Initializing) {
// We already have a value, just initialize that.
return this->visitInitializer(Init);
return this->visitInitializer(Init) && this->emitFinishInit(E);
}

std::optional<PrimType> T = classify(E->getType());
Expand All @@ -1862,7 +1862,7 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundLiteralExpr(
return this->emitInitGlobal(*T, *GlobalIndex, E);
}

return this->visitInitializer(Init);
return this->visitInitializer(Init) && this->emitFinishInit(E);
}

return false;
Expand Down Expand Up @@ -1891,7 +1891,7 @@ bool ByteCodeExprGen<Emitter>::VisitCompoundLiteralExpr(
}
return this->emitInit(*T, E);
} else {
if (!this->visitInitializer(Init))
if (!this->visitInitializer(Init) || !this->emitFinishInit(E))
return false;
}

Expand Down
12 changes: 12 additions & 0 deletions clang/test/AST/Interp/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,15 @@ void unaryops(void) {
(void)((struct zz {float x;}){3}.x++);
(void)((struct ww {float x;}){3}.x--);
}

/// This used to fail because we didn't properly mark the struct
/// initialized through a CompoundLiteralExpr as initialized.
struct TestStruct {
int a;
int b;
};
int Y __attribute__((annotate(
"GlobalValAnnotationWithArgs",
42,
(struct TestStruct) { .a = 1, .b = 2 }
)));

0 comments on commit fd98f80

Please sign in to comment.