Skip to content

Commit 3f71d29

Browse files
committed
[clang][Interp] Handle __unaligned in alignof expressions
1 parent 2875e24 commit 3f71d29

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,9 @@ static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx,
10841084
if (const auto *Ref = T->getAs<ReferenceType>())
10851085
T = Ref->getPointeeType();
10861086

1087+
if (T.getQualifiers().hasUnaligned())
1088+
return CharUnits::One();
1089+
10871090
// __alignof is defined to return the preferred alignment.
10881091
// Before 8, clang returned the preferred alignment for alignof and
10891092
// _Alignof as well.

clang/test/AST/Interp/ms.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66

77
/// Used to assert because the two parameters to _rotl do not have the same type.
88
static_assert(_rotl(0x01, 5) == 32);
9+
10+
static_assert(alignof(__unaligned int) == 1, "");

0 commit comments

Comments
 (0)