[PATCH] D58811: [clang] Fix misuses of char width to char align

Aleksandr Malykh via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 1 00:52:12 PST 2019


amalykh created this revision.
amalykh added reviewers: rsmith, momchil.velikov, stephenkelly.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch replaces getCharWidth with getCharAlign where it is used incorrectly


Repository:
  rC Clang

https://reviews.llvm.org/D58811

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaChecking.cpp


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<int32_t>::max())
       return Diag(TheCall->getBeginLoc(), diag::err_alignment_too_big)
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<VarDecl>(D)) {
         if (VD->hasGlobalStorage() && !ForAlignof)
           Align = std::max(Align, getTargetInfo().getMinGlobalAlign());
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.
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58811.188853.patch
Type: text/x-patch
Size: 2266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190301/b223bba2/attachment-0001.bin>


More information about the cfe-commits mailing list