This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Emit warning for -x option without effects
AbandonedPublic

Authored by qiucf on Dec 29 2021, 11:10 PM.

Details

Summary

Things might be confusing for people not familiar with how this option works. Add this warning like GCC.

Diff Detail

Unit TestsFailed

Event Timeline

qiucf requested review of this revision.Dec 29 2021, 11:10 PM
qiucf created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 29 2021, 11:10 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

gentle ping

hans added inline comments.Jan 27 2022, 7:52 AM
clang/lib/Driver/Driver.cpp
2416

Could we end up here in clang-cl mode with InputTypeArg pointing to a '/TC' or '/TP' option? (Set near the top of the function.) In that case, emitting a diagnostic that talks about -x would be misleading.

What if you initialized InputsBeforeOptX to a sentinel value instead (e.g. SIZE_MAX)? Could the if statement then be simplified to just

if (Inputs.size() == InputsBeforeX)

?

clang/test/Driver/redundant-args.c
2

These two lines seem to test pretty different things (and I find the first test a bit confusing). Maybe there's a better test to add the new warning to, or it could go in its own file?

awarzynski added inline comments.Jan 27 2022, 8:17 AM
clang/test/Driver/redundant-args.c
2

I second @hans here - this is confusing. I suggest the following:

// RUN: %clang  -Werror -x c -fsyntax-only %s
// RUN: not %clang  -Werror %s -x c -fsyntax-only  2>&1 | FileCheck %s

Basically:

  • IIUC, -target is not relevant here
  • -x -c and -x -c -x -c are identical (so -x -c should be sufficient)
  • both lines should be almost identical and the difference triggering the warning should be made clear
Herald added a project: Restricted Project. · View Herald TranscriptJun 27 2022, 11:42 PM
Herald added a subscriber: MaskRay. · View Herald Transcript
qiucf abandoned this revision.Jun 27 2022, 11:43 PM