Skip to content

Commit

Permalink
[clang][Interp] Handle __datasizeof.
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Mar 17, 2024
1 parent c5818c3 commit 0211389
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,9 @@ template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitUnaryExprOrTypeTraitExpr(
const UnaryExprOrTypeTraitExpr *E) {
UnaryExprOrTypeTrait Kind = E->getKind();
ASTContext &ASTCtx = Ctx.getASTContext();
const ASTContext &ASTCtx = Ctx.getASTContext();

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

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

Size = ASTCtx.getTypeSizeInChars(ArgType);
if (Kind == UETT_SizeOf)
Size = ASTCtx.getTypeSizeInChars(ArgType);
else
Size = ASTCtx.getTypeInfoDataSizeInChars(ArgType).Width;
}

if (DiscardResult)
Expand Down
1 change: 1 addition & 0 deletions clang/test/SemaCXX/datasizeof.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -verify %s
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -verify %s -fexperimental-new-constant-interpreter

#if !__has_extension(datasizeof)
# error "Expected datasizeof extension"
Expand Down

0 comments on commit 0211389

Please sign in to comment.