Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -4473,24 +4473,30 @@ if (ICE.isInvalid()) return; - uint64_t AlignVal = Alignment.getZExtValue(); - // C++11 [dcl.align]p2: - // -- if the constant expression evaluates to zero, the alignment - // specifier shall have no effect - // C11 6.7.5p6: - // An alignment specification of zero has no effect. - if (!(TmpAttr.isAlignas() && !Alignment)) { - if (!llvm::isPowerOf2_64(AlignVal)) { - Diag(AttrLoc, diag::err_alignment_not_power_of_two) - << E->getSourceRange(); - return; - } - } uint64_t MaximumAlignment = Sema::MaximumAlignment; if (Context.getTargetInfo().getTriple().isOSBinFormatCOFF()) MaximumAlignment = std::min(MaximumAlignment, uint64_t(8192)); - if (AlignVal > MaximumAlignment) { + bool TooManyActiveBits = Alignment.getActiveBits() > llvm::APInt(64, MaximumAlignment).getActiveBits(); + + uint64_t AlignVal = 0; + if (!TooManyActiveBits) { + AlignVal = Alignment.getZExtValue(); + // C++11 [dcl.align]p2: + // -- if the constant expression evaluates to zero, the alignment + // specifier shall have no effect + // C11 6.7.5p6: + // An alignment specification of zero has no effect. + if (!(TmpAttr.isAlignas() && !Alignment)) { + if (!llvm::isPowerOf2_64(AlignVal)) { + Diag(AttrLoc, diag::err_alignment_not_power_of_two) + << E->getSourceRange(); + return; + } + } + } + + if (TooManyActiveBits || AlignVal > MaximumAlignment) { Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaximumAlignment << E->getSourceRange(); return; Index: clang/test/Sema/attr-aligned.c =================================================================== --- clang/test/Sema/attr-aligned.c +++ clang/test/Sema/attr-aligned.c @@ -1,8 +1,10 @@ -// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s int x __attribute__((aligned(3))); // expected-error {{requested alignment is not a power of 2}} int y __attribute__((aligned(1ull << 33))); // expected-error {{requested alignment must be 4294967296 bytes or smaller}} int y __attribute__((aligned(1ull << 32))); +// GH50534 +int z __attribute__((aligned((__int128_t)0x1234567890abcde0ULL << 64))); // expected-error {{requested alignment must be 4294967296 bytes or smaller}} // PR26444 int y __attribute__((aligned(1 << 29)));