[clang] 820e0c4 - [clang][cli] Pass '-Wspir-compat' to cc1 from driver
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 22 00:55:25 PST 2021
Author: Jan Svoboda
Date: 2021-02-22T09:54:44+01:00
New Revision: 820e0c49fc48024d8b426f4b10b50b5b5659a705
URL: https://github.com/llvm/llvm-project/commit/820e0c49fc48024d8b426f4b10b50b5b5659a705
DIFF: https://github.com/llvm/llvm-project/commit/820e0c49fc48024d8b426f4b10b50b5b5659a705.diff
LOG: [clang][cli] Pass '-Wspir-compat' to cc1 from driver
This patch moves the creation of the '-Wspir-compat' argument from cc1 to the driver.
Without this change, generating command line arguments from `CompilerInvocation` cannot be done reliably: there's no way to distinguish whether '-Wspir-compat' was passed to cc1 on the command line (should be generated), or if it was created within `CompilerInvocation::CreateFromArgs` (should not be generated).
This is also in line with how other '-W' flags are handled.
(This was introduced in D21567.)
Reviewed By: Anastasia
Differential Revision: https://reviews.llvm.org/D97041
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/opencl.cl
clang/test/SemaOpenCL/sampler_t.cl
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 180d9cfec225..386bec831175 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4264,6 +4264,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// are provided.
TC.addClangWarningOptions(CmdArgs);
+ // FIXME: Subclass ToolChain for SPIR and move this to addClangWarningOptions.
+ if (Triple.isSPIR())
+ CmdArgs.push_back("-Wspir-compat");
+
// Select the appropriate action.
RewriteKind rewriteKind = RK_None;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 45fb4f60a396..a870940ac110 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4628,10 +4628,6 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
Success = false;
}
- // Turn on -Wspir-compat for SPIR target.
- if (T.isSPIR())
- Res.getDiagnosticOpts().Warnings.push_back("spir-compat");
-
// If sanitizer is enabled, disable OPT_ffine_grained_bitfield_accesses.
if (Res.getCodeGenOpts().FineGrainedBitfieldAccesses &&
!Res.getLangOpts()->Sanitize.empty()) {
diff --git a/clang/test/Driver/opencl.cl b/clang/test/Driver/opencl.cl
index 44ae12330662..b6a9b8a32448 100644
--- a/clang/test/Driver/opencl.cl
+++ b/clang/test/Driver/opencl.cl
@@ -19,6 +19,8 @@
// RUN: %clang -S -### -cl-uniform-work-group-size %s 2>&1 | FileCheck --check-prefix=CHECK-UNIFORM-WG %s
// RUN: not %clang -cl-std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s
// RUN: not %clang -cl-std=invalid -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID %s
+// RUN: %clang -S -### -target spir-unknown-unknown %s 2>&1 | FileCheck --check-prefix=CHECK-W-SPIR-COMPAT %s
+// RUN: %clang -S -### -target amdgcn-amd-amdhsa-opencl %s 2>&1 | FileCheck --check-prefix=CHECK-NO-W-SPIR-COMPAT %s
// CHECK-CL: "-cc1" {{.*}} "-cl-std=CL"
// CHECK-CL10: "-cc1" {{.*}} "-cl-std=CL1.0"
@@ -45,4 +47,7 @@
// CHECK-C99: error: invalid value 'c99' in '-cl-std=c99'
// CHECK-INVALID: error: invalid value 'invalid' in '-cl-std=invalid'
+// CHECK-W-SPIR-COMPAT: "-Wspir-compat"
+// CHECK-NO-W-SPIR-COMPAT-NOT: "-Wspir-compat"
+
kernel void func(void);
diff --git a/clang/test/SemaOpenCL/sampler_t.cl b/clang/test/SemaOpenCL/sampler_t.cl
index 888e973cc31d..a9fcab7faf06 100644
--- a/clang/test/SemaOpenCL/sampler_t.cl
+++ b/clang/test/SemaOpenCL/sampler_t.cl
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple spir-unknown-unknown
// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple spir-unknown-unknown
#define CLK_ADDRESS_CLAMP_TO_EDGE 2
#define CLK_NORMALIZED_COORDS_TRUE 1
More information about the cfe-commits
mailing list