[all-commits] [llvm/llvm-project] 681c50: Improve the strict prototype diagnostic behavior

Aaron Ballman via All-commits all-commits at lists.llvm.org
Thu May 26 05:36:16 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 681c50c62e9338afdf58ebfd663f8e3ff43439fb
      https://github.com/llvm/llvm-project/commit/681c50c62e9338afdf58ebfd663f8e3ff43439fb
  Author: Aaron Ballman <aaron at aaronballman.com>
  Date:   2022-05-26 (Thu, 26 May 2022)

  Changed paths:
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Sema/SemaDecl.cpp
    M clang/test/C/drs/dr0xx.c
    M clang/test/CodeGen/2009-06-01-addrofknr.c
    M clang/test/Parser/declarators.c
    M clang/test/Sema/arg-duplicate.c
    M clang/test/Sema/knr-def-call.c
    M clang/test/Sema/knr-variadic-def.c
    M clang/test/Sema/warn-deprecated-non-prototype.c
    M clang/test/Sema/warn-strict-prototypes.c

  Log Message:
  -----------
  Improve the strict prototype diagnostic behavior

Post-commit feedback on https://reviews.llvm.org/D122895 pointed out
that the diagnostic wording for some code was using "declaration" in a
confusing way, such as:

int foo(); // warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x

int foo(int arg) { // warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x
  return 5;
}

And that we had other minor issues with the diagnostics being somewhat
confusing.

This patch addresses the confusion by reworking the implementation to
be a bit more simple and a bit less chatty. Specifically, it changes
the warning and note diagnostics to be able to specify "declaration" or
"definition" as appropriate, and it changes the function merging logic
so that the function without a prototype is always what gets warned on,
and the function with a prototype is sometimes what gets noted.
Additionally, when diagnosing a K&R C definition that is preceded by a
function without a prototype, we don't note the prior declaration, we
warn on it because it will also be changing behavior in C2x.

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




More information about the All-commits mailing list