[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
This commit is contained in:
Alex Lorenz 2021-10-29 12:59:01 -07:00
parent 3b039c68f2
commit a43d1aa852
3 changed files with 6 additions and 2 deletions

View File

@ -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">, "taking address of packed member %0 of class or structure %q1 may result in an unaligned pointer value">,
InGroup<DiagGroup<"address-of-packed-member">>; InGroup<DiagGroup<"address-of-packed-member">>;
def warn_param_mismatched_alignment : Warning< 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">>; InGroup<DiagGroup<"align-mismatch">>;
def err_objc_object_assignment : Error< def err_objc_object_assignment : Error<

View File

@ -4887,7 +4887,7 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
if (ArgAlign < ParamAlign) if (ArgAlign < ParamAlign)
Diag(Loc, diag::warn_param_mismatched_alignment) Diag(Loc, diag::warn_param_mismatched_alignment)
<< (int)ArgAlign.getQuantity() << (int)ParamAlign.getQuantity() << (int)ArgAlign.getQuantity() << (int)ParamAlign.getQuantity()
<< ParamName << FDecl; << ParamName << (FDecl != nullptr) << FDecl;
} }
/// Handles the checks for format strings, non-POD arguments to vararg /// Handles the checks for format strings, non-POD arguments to vararg

View File

@ -282,3 +282,7 @@ void test10() {
auto *UA4ptr = new UsingAligned4(11); auto *UA4ptr = new UsingAligned4(11);
new (UA4ptr) UsingAligned4(12); 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}}
}