[clang] a43d1aa - [clang] Make 'align-mismatch' warning work without an associated function declaration

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 29 13:39:28 PDT 2021


Author: Alex Lorenz
Date: 2021-10-29T13:39:16-07:00
New Revision: a43d1aa8525649a64b1f0ed5a5c25718c28920c1

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

LOG: [clang] Make 'align-mismatch' warning work without an associated function declaration

This change fixes a crash where a NULL fd was used to emit a diagnostic.
Instead of crashing, just avoid printing the declaration name when there's no
associated function declaration.

Differential Revision: https://reviews.llvm.org/D109402

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/lib/Sema/SemaChecking.cpp
    clang/test/CodeGen/typedef_alignment_mismatch_warning.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 7f7410a20084b..d37c8e9266e9b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6792,7 +6792,7 @@ def warn_taking_address_of_packed_member : Warning<
   "taking address of packed member %0 of class or structure %q1 may result in an unaligned pointer value">,
   InGroup<DiagGroup<"address-of-packed-member">>;
 def warn_param_mismatched_alignment : Warning<
-  "passing %0-byte aligned argument to %1-byte aligned parameter %2 of %3 may result in an unaligned pointer access">,
+  "passing %0-byte aligned argument to %1-byte aligned parameter %2%select{| of %4}3 may result in an unaligned pointer access">,
   InGroup<DiagGroup<"align-mismatch">>;
 
 def err_objc_object_assignment : Error<

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 147f50aeed97f..bf458f914c111 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4887,7 +4887,7 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
   if (ArgAlign < ParamAlign)
     Diag(Loc, diag::warn_param_mismatched_alignment)
         << (int)ArgAlign.getQuantity() << (int)ParamAlign.getQuantity()
-        << ParamName << FDecl;
+        << ParamName << (FDecl != nullptr) << FDecl;
 }
 
 /// Handles the checks for format strings, non-POD arguments to vararg

diff  --git a/clang/test/CodeGen/typedef_alignment_mismatch_warning.cpp b/clang/test/CodeGen/typedef_alignment_mismatch_warning.cpp
index 9bc1d19843f34..1e6888de60e6b 100644
--- a/clang/test/CodeGen/typedef_alignment_mismatch_warning.cpp
+++ b/clang/test/CodeGen/typedef_alignment_mismatch_warning.cpp
@@ -282,3 +282,7 @@ void test10() {
   auto *UA4ptr = new UsingAligned4(11);
   new (UA4ptr) UsingAligned4(12);
 }
+
+void testFunctionPointerArray(void (*fptr[10])(Aligned8Int *), Aligned2Int* src) {
+  fptr[0](src); // expected-warning {{passing 2-byte aligned argument to 8-byte aligned parameter 1 may result in an unaligned pointer access}}
+}


        


More information about the cfe-commits mailing list