This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Do not generate error about unsupported target specific options when there is no compiler jobs
ClosedPublic

Authored by mgabka on Sep 1 2023, 8:42 AM.

Details

Summary

The upstream commit: https://reviews.llvm.org/D151590
added a new flag to mark target specific compiler options.

The side effect of it was that in cases when -### or -v is used without any
input file, clang started emitting an error.
It happened like that becasue there is no compilation actions created
which could consume/verify these target specific options.

This patch changes that error to a warning about unused option, in situations
when there is no actions and still generates error when there are actions.

Fix for https://github.com/llvm/llvm-project/issues/64958

Diff Detail

Event Timeline

mgabka created this revision.Sep 1 2023, 8:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2023, 8:42 AM
mgabka requested review of this revision.Sep 1 2023, 8:42 AM
mgabka updated this revision to Diff 555706.Sep 4 2023, 4:41 AM

Thanks for working on this! I see 2 cases here:

  1. In the case of -###, it makes sense that no errors are emitted as no actions are run (nor, AFAIK, created).
  1. In the case of -v, clang -v file.c should behave like clang file.c (why wouldn't it?). So, this should give an error: %clang --target=x86_64-unknown-linux-gnu --verbose -march=.

IIUC, this patch will only affect the 1st case and that particular change makes sense to me. Not sure about 2, but if that's not affected by this patch then I'd just refocus on -### by updating the summary and the test.

Does this make sense?

clang/test/Driver/suppress-err-on-target-specific-options.c
4 ↗(On Diff #555706)

You can use this new syntax. This way some will RUN lines will be executed even if only one of the require targets is available. Documentation: https://llvm.org/docs/TestingGuide.html#substitutions

9 ↗(On Diff #555706)

IMO this should be an error:

clang: error: no input files

That's not the case ATM (ToT). That's not something "introduced" here, so I would just not test it here.

mgabka added a comment.Sep 5 2023, 3:21 AM

Thanks for working on this! I see 2 cases here:

  1. In the case of -###, it makes sense that no errors are emitted as no actions are run (nor, AFAIK, created).
  1. In the case of -v, clang -v file.c should behave like clang file.c (why wouldn't it?). So, this should give an error: %clang --target=x86_64-unknown-linux-gnu --verbose -march=.

IIUC, this patch will only affect the 1st case and that particular change makes sense to me. Not sure about 2, but if that's not affected by this patch then I'd just refocus on -### by updating the summary and the test.

Does this make sense?

I wanted to show that my patch does not break existing behaviour for X86, as there is no tests for it at all.
The existing behaviour is is that for X86 -mcpu always generates error, my change is changing the behaviour so the error is generated when the compilation job is created, i.e when the file name is passed, this is why I think the tests I added are valuable (as I did't find any, unfortunately the https://reviews.llvm.org/D151590 didn't introduce any tests.

mgabka updated this revision to Diff 556033.Sep 6 2023, 7:37 AM
mgabka marked an inline comment as done.
mgabka added inline comments.
clang/test/Driver/suppress-err-on-target-specific-options.c
9 ↗(On Diff #555706)

so I am not sure, gcc behaves same way, so I doubt that both are wrong.

OK, so previously I made a wrong assumption. I assumed that both of these should return identical error (missing input in both cases):

$ clang
clang: error: no input files
$ clang --verbose
# Some info vebose info here, but no error

But looking at how SuppressMissingInputWarning is set explains the behavior above. So yes, in both cases (-v and -###) no action is created and hence this patch does apply to both -v and -###. Unlike I claimed before, apologies.

This change makes a lot of sense to me now. However, I'd appreciate a few more comments explaining that this affects the behavior _when no job/action is created_, e.g. for clang -### and clang -v <no-input-file>. That's already noted in the commit message, but a comment in the source and the test file would be appreciated.

clang/test/Driver/suppress-err-on-target-specific-options.c
9 ↗(On Diff #555706)

Aha, see my latest reply, I was wrong.

MaskRay requested changes to this revision.Sep 6 2023, 10:02 AM
MaskRay added inline comments.
clang/test/Driver/suppress-err-on-target-specific-options.c
1 ↗(On Diff #556033)

There are too many RUN lines. We can combine some.

-mcpu= -march= can be tested in one command.

I think you can drop --verbose (-v) tests. The -v behavior is tested a lot in other files.

Perhaps just name this file: no-input-file.c. We don't have dedicated tests yet

Clang :: Driver/android-ndk-standalone.cpp
Clang :: Driver/baremetal.cpp
Clang :: Driver/cl-options.c
Clang :: Driver/config-file.c
Clang :: Driver/config-file3.c
Clang :: Driver/cuda-detect-path.cu
Clang :: Driver/cuda-detect.cu
Clang :: Driver/cuda-macosx.cu
Clang :: Driver/default-toolchain.c
Clang :: Driver/hip-version.hip
Clang :: Driver/lanai-toolchain.c
Clang :: Driver/print-supported-cpus.c
Clang :: Driver/solaris-sparc-gcc-search.test
Clang :: Driver/stack-size-section.c
This revision now requires changes to proceed.Sep 6 2023, 10:02 AM
MaskRay added inline comments.Sep 6 2023, 10:05 AM
clang/test/Driver/suppress-err-on-target-specific-options.c
12 ↗(On Diff #556033)

%if x86-registered-target is not needed. You can build llvm without X86 in LLVM_TARGETS_TO_BUILD: to verify.

awarzynski added inline comments.Sep 7 2023, 12:31 AM
clang/test/Driver/suppress-err-on-target-specific-options.c
1 ↗(On Diff #556033)

Perhaps just name this file: no-input-file.c.

That or "no-action.c" as this is testing the behavior when:

  • no action is created.

From what I can see, only -v and -### fall into this category (potentially more), so I would test _both_. This way it would be a dedicated test for "what happens when no actions are created". We could add more flags that fall into this category over time.

mgabka updated this revision to Diff 556243.Sep 8 2023, 3:18 AM
mgabka retitled this revision from Do not generate error about unsupported target specific options when using -### or -v to Do not generate error about unsupported target specific options when there is no compiler jobs.
mgabka edited the summary of this revision. (Show Details)
mgabka added a comment.Sep 8 2023, 3:20 AM

I renamed the file as requested and added extra comment in the source code, and removed the RUN lines where the file was present, AFAIK there is no tests for such cases at the moment but this is not what may patch is changing, so I hope these tests are not needed for this patch to land.

awarzynski accepted this revision.Sep 8 2023, 3:28 AM

LGTM, thanks a ton for the fix! Please wait for @MaskRay to approve too.

clang/lib/Driver/Driver.cpp
4957–4959

[nit] "target specific options are not consumed/validated" -> it's worth adding that that's because no action is created.

MaskRay accepted this revision.Sep 8 2023, 3:48 PM

It is fixing https://github.com/llvm/llvm-project/issues/64958

Nit: just say

"Fix https://github.com/llvm/llvm-project/issues/64958"

This means that we lose the ability to detect target-specific options for other targets, but I think it's better than erroring on supported options.

clang/test/Driver/no-action.c
8

Optional/super nit: it's not a pattern everybody uses, but I personally use /// for comments that are neither RUN nor CHECK. The /// comment stands out in some editors and helps certain automated analysis (e.g. auto detecting typo in possibly CHECK prefixes). This is super nit, so no need to do it.

This revision is now accepted and ready to land.Sep 8 2023, 3:48 PM
MaskRay retitled this revision from Do not generate error about unsupported target specific options when there is no compiler jobs to [Driver] Do not generate error about unsupported target specific options when there is no compiler jobs.Sep 8 2023, 9:41 PM
mgabka updated this revision to Diff 556431.Sep 11 2023, 7:39 AM
mgabka edited the summary of this revision. (Show Details)
This revision was landed with ongoing or failed builds.Sep 11 2023, 8:04 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 11 2023, 8:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript