Conversation
…V target for release When a user passes '-target spirv' without specififying a vulkan environment ttriple, SPIRVTargetInfo will fire an assert instead of throwing an error diagnostic. Added this diagnostic in CompilerInstance::createTarget() before target is initialized. Fixes llvm#189964
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: PrabbyDD ChangesFixes issue #189964 Full diff: https://github.com/llvm/llvm-project/pull/190840.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 62b74574102e4..0a3e4e82a79e5 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -43,6 +43,9 @@ def note_fe_backend_resource_limit: Note<"%0 (%1) exceeds limit (%2) in '%3'">,
def remark_fe_backend_plugin: Remark<"%0">, BackendInfo, InGroup<RemarkBackendPlugin>;
def note_fe_backend_plugin: Note<"%0">, BackendInfo;
+def err_spirv_requires_vulkan : Error<
+ "SPIR-V target requires a Vulkan environment (e.g. '-target spirv64-unknown-vulkan1.3')">;
+
def warn_fe_override_module : Warning<
"overriding the module target triple with %0">,
InGroup<DiagGroup<"override-module">>;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 0b00ad7128c00..89898d3adfbae 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -112,6 +112,17 @@ void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
bool CompilerInstance::createTarget() {
+
+ // Validate Vulkan environment for SPIRV.
+ llvm::Triple Triple(getInvocation().getTargetOpts().Triple);
+ if (Triple.getArch() == llvm::Triple::spirv) {
+ if (Triple.getOS() != llvm::Triple::Vulkan ||
+ Triple.getVulkanVersion() == llvm::VersionTuple(0)) {
+ getDiagnostics().Report(diag::err_spirv_requires_vulkan) << Triple.str();
+ return false;
+ }
+ }
+
// Create the target instance.
setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(),
getInvocation().getTargetOpts()));
diff --git a/clang/test/Driver/spirv-target-validation.c b/clang/test/Driver/spirv-target-validation.c
new file mode 100644
index 0000000000000..cde5b46c54b94
--- /dev/null
+++ b/clang/test/Driver/spirv-target-validation.c
@@ -0,0 +1,4 @@
+// RUN: %clang -target spirv %s 2>&1 | FileCheck %s
+// CHECK: error: SPIR-V target requires a Vulkan environment
+
+int main() { return 0; }
\ No newline at end of file
|
|
Hello! This is my first PR to LLVM. A small diagnostics fix. If there is any advice for newbie mistakes I might have made, I will gladly fix them. I am trying to work my way up from smaller issues to larger ones in clang because it is complex. I tried to include short but meaningful comments in the code, a unit test that mimics others I saw, and meaningful commit messages. Thanks. |
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions c,cpp -- clang/test/Driver/spirv-target-validation.c clang/lib/Frontend/CompilerInstance.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 89898d3ad..b51f9027b 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -113,7 +113,7 @@ void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
bool CompilerInstance::createTarget() {
- // Validate Vulkan environment for SPIRV.
+ // Validate Vulkan environment for SPIRV.
llvm::Triple Triple(getInvocation().getTargetOpts().Triple);
if (Triple.getArch() == llvm::Triple::spirv) {
if (Triple.getOS() != llvm::Triple::Vulkan ||
|
🐧 Linux x64 Test Results
Failed Tests(click on a test name to see its output) ClangClang.Driver/spirv-target-validation.clldb-apilldb-api.commands/process/attach/TestProcessAttach.pyIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
🪟 Windows x64 Test Results
Failed Tests(click on a test name to see its output) ClangClang.Driver/spirv-target-validation.cIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
|
You should not format code (manually or automatically) outside of your changes. It makes it harder to review your PR. |
Fixes issue #189964
When a user passes '-target spirv' without specififying a vulkan environment ttriple, SPIRVTargetInfo will fire an assert instead of throwing an error diagnostic. Added this diagnostic in CompilerInstance::createTarget() before target is initialized. Fixes #189964