From: Nico Weber Date: Tue, 9 Jul 2019 00:34:08 +0000 (+0000) Subject: Let unaliased Args track which Alias they were created from, and use that in Arg... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b032fe4ee8c24e095d7dadfbb2aee6b41bda6680;p=clang Let unaliased Args track which Alias they were created from, and use that in Arg::getAsString() for diagnostics With this, `clang-cl /source-charset:utf-16 test.cc` now prints `invalid value 'utf-16' in '/source-charset:utf-16'` instead of `invalid value 'utf-16' in '-finput-charset=utf-16'` before, and several other clang-cl flags produce much less confusing output as well. Fixes PR29106. Since an arg and its alias can have different arg types (joined vs not) and different values (because of AliasArgs<>), I chose to give the Alias its own Arg object. For convenience, I just store the alias directly in the unaliased arg – there aren't many arg objects at runtime, so that seems ok. Finally, I changed Arg::getAsString() to use the alias's representation if it's present – that function was already documented as being the suitable function for diagnostics, and most callers already used it for diagnostics. Implementation-wise, Arg::accept() previously used to parse things as the unaliased option. The core of that switch is now extracted into a new function acceptInternal() which parses as the _aliased_ option, and the previously-intermingled unaliasing is now done as an explicit step afterwards. (This also changes one place in lld that didn't use getAsString() for diagnostics, so that that one place now also prints the flag as the user wrote it, not as it looks after it went through unaliasing.) Differential Revision: https://reviews.llvm.org/D64253 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365413 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Driver/arm-execute-only.c b/test/Driver/arm-execute-only.c index 866d7271d1..c73785d385 100644 --- a/test/Driver/arm-execute-only.c +++ b/test/Driver/arm-execute-only.c @@ -1,27 +1,27 @@ // RUN: not %clang -c -target thumbv6m-eabi -mexecute-only %s 2>&1 | \ // RUN: FileCheck --check-prefix CHECK-EXECUTE-ONLY-NOT-SUPPORTED %s +// CHECK-EXECUTE-ONLY-NOT-SUPPORTED: error: execute only is not supported for the thumbv6m sub-architecture // RUN: not %clang -target armv8m.main-eabi -mexecute-only -mno-movt %s 2>&1 \ // RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY-NO-MOVT +// CHECK-EXECUTE-ONLY-NO-MOVT: error: option '-mexecute-only' cannot be specified with '-mno-movt' // RUN: not %clang -target armv8m.main-eabi -mexecute-only -mlong-calls %s 2>&1 \ // RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY-LONG-CALLS +// CHECK-EXECUTE-ONLY-LONG-CALLS: error: option '-mexecute-only' cannot be specified with '-mlong-calls' +// RUN: %clang -target armv7m-eabi -x assembler -mexecute-only %s -c -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY -check-prefix CHECK-NO-EXECUTE-ONLY-ASM +// CHECK-NO-EXECUTE-ONLY-ASM: warning: argument unused during compilation: '-mexecute-only' // -mpure-code flag for GCC compatibility // RUN: not %clang -c -target thumbv6m-eabi -mpure-code %s 2>&1 | \ // RUN: FileCheck --check-prefix CHECK-EXECUTE-ONLY-NOT-SUPPORTED %s // RUN: not %clang -target armv8m.main-eabi -mpure-code -mno-movt %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY-NO-MOVT +// RUN: | FileCheck %s -check-prefix CHECK-PURE-CODE-NO-MOVT +// CHECK-PURE-CODE-NO-MOVT: error: option '-mpure-code' cannot be specified with '-mno-movt' // RUN: not %clang -target armv8m.main-eabi -mpure-code -mlong-calls %s 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-EXECUTE-ONLY-LONG-CALLS - -// RUN: %clang -target armv7m-eabi -x assembler -mexecute-only %s -c -### 2>&1 \ -// RUN: | FileCheck %s -check-prefix CHECK-NO-EXECUTE-ONLY -check-prefix CHECK-NO-EXECUTE-ONLY-ASM - -// CHECK-EXECUTE-ONLY-NOT-SUPPORTED: error: execute only is not supported for the thumbv6m sub-architecture -// CHECK-EXECUTE-ONLY-NO-MOVT: error: option '-mexecute-only' cannot be specified with '-mno-movt' -// CHECK-EXECUTE-ONLY-LONG-CALLS: error: option '-mexecute-only' cannot be specified with '-mlong-calls' -// CHECK-NO-EXECUTE-ONLY-ASM: warning: argument unused during compilation: '-mexecute-only' +// RUN: | FileCheck %s -check-prefix CHECK-PURE-CODE-LONG-CALLS +// CHECK-PURE-CODE-LONG-CALLS: error: option '-mpure-code' cannot be specified with '-mlong-calls' diff --git a/test/Driver/cl-options.c b/test/Driver/cl-options.c index 3b377b3f63..04aa08a557 100644 --- a/test/Driver/cl-options.c +++ b/test/Driver/cl-options.c @@ -8,7 +8,7 @@ // c: -c // RUN: %clang_cl /C -### -- %s 2>&1 | FileCheck -check-prefix=C %s -// C: error: invalid argument '-C' only allowed with '/E, /P or /EP' +// C: error: invalid argument '/C' only allowed with '/E, /P or /EP' // RUN: %clang_cl /C /P -### -- %s 2>&1 | FileCheck -check-prefix=C_P %s // C_P: "-E" @@ -214,11 +214,11 @@ // /source-charset: should warn on everything except UTF-8. // RUN: %clang_cl /source-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=source-charset-utf-16 %s -// source-charset-utf-16: invalid value 'utf-16' +// source-charset-utf-16: invalid value 'utf-16' in '/source-charset:utf-16' // /execution-charset: should warn on everything except UTF-8. // RUN: %clang_cl /execution-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=execution-charset-utf-16 %s -// execution-charset-utf-16: invalid value 'utf-16' +// execution-charset-utf-16: invalid value 'utf-16' in '/execution-charset:utf-16' // // RUN: %clang_cl /Umymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s // RUN: %clang_cl /U mymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s diff --git a/test/Driver/darwin-version.c b/test/Driver/darwin-version.c index 75279b9e0c..7885b59646 100644 --- a/test/Driver/darwin-version.c +++ b/test/Driver/darwin-version.c @@ -18,7 +18,7 @@ // RUN: %clang -target armv7-apple-ios11.0 -c -### %s 2> %t.err // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS41 %s -// CHECK-VERSION-IOS41: invalid iOS deployment version '--target=armv7-apple-ios11.0' +// CHECK-VERSION-IOS41: invalid iOS deployment version '-target armv7-apple-ios11.0' // RUN: %clang -target armv7-apple-darwin -miphoneos-version-min=11.0 -c -### %s 2> %t.err // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-VERSION-IOS5 %s @@ -197,11 +197,11 @@ // RUN: %clang -target x86_64-apple-macos10.11.2 -mmacos-version-min=10.6 -c %s -### 2>&1 | \ // RUN: FileCheck --check-prefix=CHECK-VERSION-TNO-OSV1 %s -// CHECK-VERSION-TNO-OSV1: overriding '-mmacosx-version-min=10.6' option with '--target=x86_64-apple-macos10.11.2' +// CHECK-VERSION-TNO-OSV1: overriding '-mmacos-version-min=10.6' option with '-target x86_64-apple-macos10.11.2' // RUN: %clang -target x86_64-apple-macos -miphoneos-version-min=9.1 -c %s -### 2>&1 | \ // RUN: FileCheck --check-prefix=CHECK-VERSION-TNO-OSV2 %s -// CHECK-VERSION-TNO-OSV2: overriding '-miphoneos-version-min=9.1' option with '--target=x86_64-apple-macos' +// CHECK-VERSION-TNO-OSV2: overriding '-miphoneos-version-min=9.1' option with '-target x86_64-apple-macos' // RUN: %clang -target x86_64-apple-ios -miphonesimulator-version-min=10.0 -c %s -### 2>&1 | \ // RUN: FileCheck --check-prefix=CHECK-VERSION-TNO-OSV3 %s @@ -211,7 +211,7 @@ // RUN: %clang -target arm64-apple-ios10.1.0 -miphoneos-version-min=10.1.0.1 -c %s -### 2>&1 | \ // RUN: FileCheck --check-prefix=CHECK-VERSION-TNO-OSV4 %s -// CHECK-VERSION-TNO-OSV4: overriding '-miphoneos-version-min=10.1.0.1' option with '--target=arm64-apple-ios10.1.0' +// CHECK-VERSION-TNO-OSV4: overriding '-miphoneos-version-min=10.1.0.1' option with '-target arm64-apple-ios10.1.0' // RUN: %clang -target x86_64-apple-macos10.6 -mmacos-version-min=10.6 -c %s -### 2>&1 | \ // RUN: FileCheck --check-prefix=CHECK-VERSION-TNO-SAME %s