Author: Michael Kruse
Date: 2026-10-08T13:26:53+02:00
New Revision: 531bd6fcaa0715c8deb5028ba2a11a5457b8a404

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

LOG: [Clang][Driver] Fix inverted diagnostic condition (#225640)

The diagnostic string for warn_drv_preprocessed_input_file_unused and
warn_drv_input_file_unused require %1/%2 to be true iff the causing
option is *un*available. Swap the option. Also use `getSpelling()` to
include the dash in the printed input.

warn_drv_input_file_unused was already part of #218802 which was
reverted.

preprocessed-input-file-unused.c test case generated by AI

Added: 
    clang/test/Driver/Inputs/preprocessed-input-file-unused.i
    clang/test/Driver/preprocessed-input-file-unused.c

Modified: 
    clang/lib/Driver/Driver.cpp
    clang/test/Driver/aix-ld.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 57beab92011a9..006c3d2f0044d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3526,13 +3526,13 @@ void Driver::handleArguments(Compilation &C, 
DerivedArgList &Args,
                 Args.getLastArg(options::OPT_M, options::OPT_MM)) &&
                getPreprocessedType(InputType) == types::TY_INVALID)
         Diag(clang::diag::warn_drv_preprocessed_input_file_unused)
-            << InputArg->getAsString(Args) << !!FinalPhaseArg
-            << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() : "");
+            << InputArg->getAsString(Args) << !FinalPhaseArg
+            << (FinalPhaseArg ? FinalPhaseArg->getSpelling() : "");
       else
         Diag(clang::diag::warn_drv_input_file_unused)
             << InputArg->getAsString(Args) << getPhaseName(InitialPhase)
-            << !!FinalPhaseArg
-            << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() : "");
+            << !FinalPhaseArg
+            << (FinalPhaseArg ? FinalPhaseArg->getSpelling() : "");
       continue;
     }
 

diff  --git a/clang/test/Driver/Inputs/preprocessed-input-file-unused.i 
b/clang/test/Driver/Inputs/preprocessed-input-file-unused.i
new file mode 100644
index 0000000000000..c2102144fb141
--- /dev/null
+++ b/clang/test/Driver/Inputs/preprocessed-input-file-unused.i
@@ -0,0 +1 @@
+int unused;

diff  --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index bedd224eeca9c..641908afc8d98 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -1171,4 +1171,4 @@
 // RUN:        -K \
 // RUN:        -c \
 // RUN:   | FileCheck --check-prefixes=CHECK-K-UNUSED %s
-// CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused 
[-Wunused-command-line-argument]
+// CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused when '-c' is 
present [-Wunused-command-line-argument]

diff  --git a/clang/test/Driver/preprocessed-input-file-unused.c 
b/clang/test/Driver/preprocessed-input-file-unused.c
new file mode 100644
index 0000000000000..78fd92f1502ae
--- /dev/null
+++ b/clang/test/Driver/preprocessed-input-file-unused.c
@@ -0,0 +1,15 @@
+// Regression test for a condition inversion bug that caused
+// warn_drv_preprocessed_input_file_unused to never mention which option
+// determined the final compilation phase.
+
+// RUN: %clang -E %S/Inputs/preprocessed-input-file-unused.i -o /dev/null 2>&1 
\
+// RUN:   | FileCheck --check-prefix=CHECK-E %s
+// CHECK-E: warning: {{.*}}preprocessed-input-file-unused.i: previously 
preprocessed input unused when '-E' is present [-Wunused-command-line-argument]
+
+// RUN: %clang -M %S/Inputs/preprocessed-input-file-unused.i -o /dev/null 2>&1 
\
+// RUN:   | FileCheck --check-prefix=CHECK-M %s
+// CHECK-M: warning: {{.*}}preprocessed-input-file-unused.i: previously 
preprocessed input unused when '-M' is present [-Wunused-command-line-argument]
+
+// RUN: %clang -MM %S/Inputs/preprocessed-input-file-unused.i -o /dev/null 
2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MM %s
+// CHECK-MM: warning: {{.*}}preprocessed-input-file-unused.i: previously 
preprocessed input unused when '-MM' is present [-Wunused-command-line-argument]


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to