This is an archive of the discontinued LLVM Phabricator instance.

[clang][driver] Emit an error for `/clang:-x`
ClosedPublic

Authored by Fznamznon on Jan 27 2023, 9:35 AM.

Details

Summary

/clang:-x emits an error instead of a warning. And if the error is suppressed,
/clang:-x takes no effect.
Considering that /clang: is a recent addition in 2018-11 and there are MSVC
style alternatives, therefore /clang:-x doesn't seem useful and we just reject
it since properly supporting it would add lots of complexity.

Fixes #59307

Diff Detail

Event Timeline

Fznamznon created this revision.Jan 27 2023, 9:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2023, 9:35 AM
Fznamznon requested review of this revision.Jan 27 2023, 9:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2023, 9:35 AM

See https://github.com/llvm/llvm-project/issues/59307#issuecomment-1407529807 I think we should just report an error for /clang:-xc

clang/lib/Driver/Driver.cpp
2571
-    assert(!Args.hasArg(options::OPT_x) && "-x and /TC or /TP is not allowed");
+    if (auto *A = Args.getLastArg(options::OPT_x))
+      Diag(diag::err_drv_unsupported_opt_with_suggestion)
+          << A->getAsString(Args) << "/TC' or '/TP";
clang/test/Driver/x-args.c
8

Delete //

Fznamznon updated this revision to Diff 493256.Jan 30 2023, 2:40 AM

Emit an error if /clang:-x passed.

Fznamznon retitled this revision from [clang][driver] Do not warn about position of `/clang:-xc` in cl mode to [clang][driver] Emit an error for `/clang:-x`.Jan 30 2023, 2:41 AM
Fznamznon edited the summary of this revision. (Show Details)
Fznamznon marked an inline comment as done.Jan 30 2023, 2:51 AM
Fznamznon added inline comments.
clang/lib/Driver/Driver.cpp
2571

Thank you, the suggestion seems reasonable to me. Although, the concrete place doesn't.
The suggested line to change is under if (we have /TC or /TP argument), so if I put error emission there it won't be emitted if no /TC or /TP was passed and the original problem reported in https://github.com/llvm/llvm-project/issues/59307 won't be resolved. People will still be confused by the warning saying -x c passed after last input when in fact they passed /clang:-x before the input.

Also, the whole function doesn't return even if diagnostic is emitted, so I put error emission in a way to not emit a warning saying that -x is passed after last input together with it, because both errors emitted like this:

error: '-x c' after last input file has no effect
error: unsupported option '-x c'; did you mean '/TC' or '/TP'?

look confusing.

clang/test/Driver/x-args.c
8

Done, thanks.

This seems reasonable to me. I was a bit worried about the behavior being rather strange, but given that these are "escape hatch" command line options to skip the clang-cl driver, and there are existing clang-cl options that cover this functionality, it makes more sense to me now. LGTM, but please add a release note about the fix (to clang/docs/ReleaseNotes.rst). I'll leave the final sign-off to @MaskRay.

Fznamznon updated this revision to Diff 493326.Jan 30 2023, 8:47 AM

Add a release note.

MaskRay accepted this revision.Jan 30 2023, 3:03 PM

LGTM.

clang/docs/ReleaseNotes.rst
60 ↗(On Diff #493326)

Double backtick

LLVM_ENABLE_SPHINX=on and run ninja docs-clang-html to check whether the docs build is good.

This revision is now accepted and ready to land.Jan 30 2023, 3:03 PM
MaskRay added a comment.EditedJan 30 2023, 3:05 PM

In CL mode values of /clang: arguments end up at the end of arguments list so passing /clang:-x doesn't make sense and produces confusing warning.

The description needs updating. clang:-x emits an error instead of a warning. And if the error is suppressed, /clang:-x takes no effect.
Considering that /clang: is a recent addition in 2018-11 and there are MSVC style alternatives, therefore /clang:-x doesn't seem useful and we just reject it since properly supporting it would add lots of complexity.

MaskRay added inline comments.Jan 30 2023, 3:12 PM
clang/lib/Driver/Driver.cpp
2571

You need to remove assert(!Args.hasArg(options::OPT_x) && "-x and /TC or /TP is not allowed"); as otherwise /clang:-x /TC leads to a crash in an assert build of clang (LLVM_ENABLE_ASSERTIONS=on).

Fznamznon updated this revision to Diff 493576.Jan 31 2023, 5:37 AM

Apply suggestions

Fznamznon edited the summary of this revision. (Show Details)Jan 31 2023, 5:39 AM
Fznamznon added inline comments.
clang/lib/Driver/Driver.cpp
2571

Ok, removed the assert. Verified there is no crash in the test.

Fznamznon added inline comments.Jan 31 2023, 7:22 AM
clang/docs/ReleaseNotes.rst
60 ↗(On Diff #493326)

Ok fixed and verified.

@MaskRay , thanks for the suggestions. Applied. Please let me know that it is ok now.

MaskRay accepted this revision.Jan 31 2023, 9:39 AM
MaskRay added inline comments.
clang/test/Driver/x-args.c
12

You can remove this CL-NOT negative pattern. Instead, use --check-prefix=CL --implicit-check-not=error: to check that there is no other error.

Fznamznon added inline comments.Jan 31 2023, 10:22 AM
clang/test/Driver/x-args.c
12

I probably don't fully understand the suggestion, but there is a error: that is being checked in this test. The one that this revision adds. It is checked on the next line.

Fznamznon added inline comments.Feb 1 2023, 2:06 AM
clang/test/Driver/x-args.c
12

Is that ok if I submit the patch "as is"?

MaskRay added inline comments.Feb 1 2023, 2:51 PM
clang/test/Driver/x-args.c
12

CL-NOT: checks one specific error message does not appear before error: unsupported option .... You need another pattern to check that it does not appear after error: unsupported option .... If you use --implicit-check-not, you additionally check that there is no other error diagnostic whatever their message is.

Fznamznon updated this revision to Diff 494221.Feb 2 2023, 2:33 AM

Apply suggestion and rebase

Fznamznon updated this revision to Diff 494222.Feb 2 2023, 2:37 AM

Fix incorrect conflict resolution

Fznamznon added inline comments.Feb 2 2023, 2:39 AM
clang/test/Driver/x-args.c
12

Okay, this sounds reasonable, thank you. Applied.

MaskRay accepted this revision.Feb 2 2023, 8:31 AM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Feb 2 2023, 9:18 AM

This breaks tests on Mac: http://45.33.8.238/macm1/54097/step_7.txt

Please take a look and revert for now if it takes a while to fix.

This breaks tests on Mac: http://45.33.8.238/macm1/54097/step_7.txt

Please take a look and revert for now if it takes a while to fix.

Thanks for reporting. It seems I should have added -- before the input. I will push the fix asap.