llvm-project/clang/test/Driver/unknown-arg.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
4.0 KiB
C
Raw Normal View History

// RUN: not %clang %s -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -ifoo -imultilib dir -### 2>&1 | \
// RUN: FileCheck %s
// RUN: %clang %s -imultilib dir -### 2>&1 | \
// RUN: FileCheck %s --check-prefix=MULTILIB
// RUN: not %clang %s -stdlibs=foo -hell -version -### 2>&1 | \
// RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
// RUN: %clang_cl -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -### -c -- %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=CL
// RUN: %clang_cl -Brepo -### -- %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=CL-DID-YOU-MEAN
// RUN: %clang_cl /Brepo -### -- %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=CL-DID-YOU-MEAN-SLASH
[clang] Make the driver not diagnose errors on nonexistent linker inputs When nonexistent linker inputs are passed to the driver, the linker now errors out, instead of the compiler. If the linker does not run, clang now emits a "warning: linker input unused" instead of an error for nonexistent files. The motivation for this change is that I noticed that `clang-cl /winsysroot sysroot main.cc ole32.lib` emitted a "ole32.lib not found" error, even though the linker finds it just fine when I run `clang-cl /winsysroot sysroot main.cc /link ole32.lib`. The same problem occurs if running `clang-cl main.cc ole32.lib` in a non-MSVC shell. The problem is that DiagnoseInputExistence() only looked for libs in %LIB%, but MSVCToolChain uses much more involved techniques. For this particular problem, we could make DiagnoseInputExistence() ask the toolchain to see if it can find a .lib file, but in general the driver can't know what the linker will do to find files, so it shouldn't try. For example, if we implement PR24616, lld-link will look in the registry to determine a good default for %LIB% if it isn't set. This is less or a problem for the gcc driver, since .a paths there are either passed via -l flags (which honor -L), or via a qualified path (that doesn't honor -L) -- but for example ld.lld's --chroot flag can also trigger this problem. Without this patch, `clang -fuse-ld=lld -Wl,--chroot,some/dir /file.o` will complain that `/file.o` doesn't exist, even though `clang -fuse-ld=lld -Wl,--chroot,some/dir -Wl,/file.o` succeeds just fine. This implements rnk's suggestion on the old bug PR27234. Differential Revision: https://reviews.llvm.org/D109624
2021-09-13 20:57:38 +08:00
// RUN: %clang_cl /Brepo -### /Tc%s /link 2>&1 | \
// RUN: FileCheck %s --check-prefix=CL-DID-YOU-MEAN-SLASH
// RUN: not %clang_cl -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Werror=unknown-argument -### -- %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=CL-ERROR
// RUN: not %clang_cl -helo -Werror=unknown-argument -### -- %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=CL-ERROR-DID-YOU-MEAN
// RUN: %clang_cl -cake-is-lie -%0 -%d -HHHH -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Wno-unknown-argument -### -- %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=SILENT
// RUN: not %clang -cc1as -hell --version 2>&1 | \
// RUN: FileCheck %s --check-prefix=CC1AS-DID-YOU-MEAN
// RUN: not %clang -cc1asphalt -help 2>&1 | \
// RUN: FileCheck %s --check-prefix=UNKNOWN-INTEGRATED
// CHECK: error: unknown argument: '-cake-is-lie'
// CHECK: error: unknown argument: '-%0'
// CHECK: error: unknown argument: '-%d'
// CHECK: error: unknown argument: '-HHHH'
// CHECK: error: unknown argument: '-munknown-to-clang-option'
// CHECK: error: unknown argument: '-print-stats'
// CHECK: error: unknown argument: '-funknown-to-clang-option'
// CHECK: error: unknown argument: '-ifoo'
// MULTILIB: warning: argument unused during compilation: '-imultilib dir'
// DID-YOU-MEAN: error: unknown argument '-stdlibs=foo'; did you mean '-stdlib=foo'?
// DID-YOU-MEAN: error: unknown argument '-hell'; did you mean '-help'?
// DID-YOU-MEAN: error: unknown argument '-version'; did you mean '--version'?
// CL: warning: unknown argument ignored in clang-cl: '-cake-is-lie'
// CL: warning: unknown argument ignored in clang-cl: '-%0'
// CL: warning: unknown argument ignored in clang-cl: '-%d'
// CL: warning: unknown argument ignored in clang-cl: '-HHHH'
// CL: warning: unknown argument ignored in clang-cl: '-munknown-to-clang-option'
// CL: warning: unknown argument ignored in clang-cl: '-print-stats'
// CL: warning: unknown argument ignored in clang-cl: '-funknown-to-clang-option'
// CL-DID-YOU-MEAN: warning: unknown argument ignored in clang-cl '-Brepo'; did you mean '-Brepro'?
// CL-DID-YOU-MEAN-SLASH: error: no such file or directory: '/Brepo'; did you mean '/Brepro'?
// CL-ERROR: error: unknown argument ignored in clang-cl: '-cake-is-lie'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-%0'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-%d'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-HHHH'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-munknown-to-clang-option'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-print-stats'
// CL-ERROR: error: unknown argument ignored in clang-cl: '-funknown-to-clang-option'
// CL-ERROR-DID-YOU-MEAN: error: unknown argument ignored in clang-cl '-helo'; did you mean '-help'?
// SILENT-NOT: error:
// SILENT-NOT: warning:
// CC1AS-DID-YOU-MEAN: error: unknown argument '-hell'; did you mean '-help'?
// CC1AS-DID-YOU-MEAN: error: unknown argument '--version'; did you mean '-version'?
// UNKNOWN-INTEGRATED: error: unknown integrated tool '-cc1asphalt'. Valid tools include '-cc1' and '-cc1as'.
// RUN: %clang -S %s -o %t.s -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
// IGNORED: warning: unknown warning option '-Wunknown-to-clang-option'