Skip to content

Commit

Permalink
[clang][Interp] Handle __unaligned in alignof expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Apr 9, 2024
1 parent 2875e24 commit 3f71d29
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,9 @@ static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx,
if (const auto *Ref = T->getAs<ReferenceType>())
T = Ref->getPointeeType();

if (T.getQualifiers().hasUnaligned())
return CharUnits::One();

// __alignof is defined to return the preferred alignment.
// Before 8, clang returned the preferred alignment for alignof and
// _Alignof as well.
Expand Down
2 changes: 2 additions & 0 deletions clang/test/AST/Interp/ms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@

/// Used to assert because the two parameters to _rotl do not have the same type.
static_assert(_rotl(0x01, 5) == 32);

static_assert(alignof(__unaligned int) == 1, "");

0 comments on commit 3f71d29

Please sign in to comment.