Skip to content

Commit 0211389

Browse files
committed
[clang][Interp] Handle __datasizeof.
1 parent c5818c3 commit 0211389

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,9 +1096,9 @@ template <class Emitter>
10961096
bool ByteCodeExprGen<Emitter>::VisitUnaryExprOrTypeTraitExpr(
10971097
const UnaryExprOrTypeTraitExpr *E) {
10981098
UnaryExprOrTypeTrait Kind = E->getKind();
1099-
ASTContext &ASTCtx = Ctx.getASTContext();
1099+
const ASTContext &ASTCtx = Ctx.getASTContext();
11001100

1101-
if (Kind == UETT_SizeOf) {
1101+
if (Kind == UETT_SizeOf || Kind == UETT_DataSizeOf) {
11021102
QualType ArgType = E->getTypeOfArgument();
11031103

11041104
// C++ [expr.sizeof]p2: "When applied to a reference or a reference type,
@@ -1113,7 +1113,10 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryExprOrTypeTraitExpr(
11131113
if (ArgType->isDependentType() || !ArgType->isConstantSizeType())
11141114
return false;
11151115

1116-
Size = ASTCtx.getTypeSizeInChars(ArgType);
1116+
if (Kind == UETT_SizeOf)
1117+
Size = ASTCtx.getTypeSizeInChars(ArgType);
1118+
else
1119+
Size = ASTCtx.getTypeInfoDataSizeInChars(ArgType).Width;
11171120
}
11181121

11191122
if (DiscardResult)

clang/test/SemaCXX/datasizeof.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -verify %s -fexperimental-new-constant-interpreter
23

34
#if !__has_extension(datasizeof)
45
# error "Expected datasizeof extension"

0 commit comments

Comments
 (0)