Index: clang/include/clang/AST/ASTContext.h =================================================================== --- clang/include/clang/AST/ASTContext.h +++ clang/include/clang/AST/ASTContext.h @@ -2103,6 +2103,11 @@ unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; } unsigned getTypeAlign(const Type *T) const { return getTypeInfo(T).Align; } + /// Return the alignment of the character type, in bits. + uint64_t getCharAlign() const { + return getTypeAlign(CharTy); + } + /// Return the ABI-specified natural alignment of a (complete) type \p T, /// before alignment adjustments, in bits. /// Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -1540,7 +1540,7 @@ } CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const { - unsigned Align = Target->getCharWidth(); + unsigned Align = Target->getCharAlign(); bool UseAlignAttrOnly = false; if (unsigned AlignFromAttr = D->getMaxAlignment()) { @@ -1594,7 +1594,7 @@ } Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); if (BaseT.getQualifiers().hasUnaligned()) - Align = Target->getCharWidth(); + Align = Target->getCharAlign(); if (const auto *VD = dyn_cast(D)) { if (VD->hasGlobalStorage() && !ForAlignof) Align = std::max(Align, getTargetInfo().getMinGlobalAlign()); Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -5831,9 +5831,9 @@ return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two) << Arg->getSourceRange(); - if (Result < Context.getCharWidth()) + if (Result < Context.getCharAlign()) return Diag(TheCall->getBeginLoc(), diag::err_alignment_too_small) - << (unsigned)Context.getCharWidth() << Arg->getSourceRange(); + << (unsigned)Context.getCharAlign() << Arg->getSourceRange(); if (Result > std::numeric_limits::max()) return Diag(TheCall->getBeginLoc(), diag::err_alignment_too_big)