[clang] 3f71d29 - [clang][Interp] Handle __unaligned in alignof expressions

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 9 07:06:55 PDT 2024


Author: Timm Bäder
Date: 2024-04-09T16:06:36+02:00
New Revision: 3f71d29e2370912ccc0384adce640c554561edd2

URL: https://github.com/llvm/llvm-project/commit/3f71d29e2370912ccc0384adce640c554561edd2
DIFF: https://github.com/llvm/llvm-project/commit/3f71d29e2370912ccc0384adce640c554561edd2.diff

LOG: [clang][Interp] Handle __unaligned in alignof expressions

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/AST/Interp/ms.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 50e86d94736476..a1ce6575148325 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -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.

diff  --git a/clang/test/AST/Interp/ms.cpp b/clang/test/AST/Interp/ms.cpp
index 99716e90c7a1db..fe5ed219946e76 100644
--- a/clang/test/AST/Interp/ms.cpp
+++ b/clang/test/AST/Interp/ms.cpp
@@ -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, "");


        


More information about the cfe-commits mailing list