[clang] [clang][AMDGPU] Reject malformed target IDs with empty components (PR #196140)
github-actions[bot] wrote: @edwardnvv57k Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/196140 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AMDGPU] Reject malformed target IDs with empty components (PR #196140)
https://github.com/arsenm closed https://github.com/llvm/llvm-project/pull/196140 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][AMDGPU] Reject malformed target IDs with empty components (PR #196140)
https://github.com/edwardnvv57k created
https://github.com/llvm/llvm-project/pull/196140
Fixes #196078
An extra colon in `-mcpu` (e.g. `gfx900::xnack+`) produced an empty feature
component and triggered an assertion in `StringRef::back()`.
Return `std::nullopt` for malformed target IDs instead.
>From 51ab2a9116b89009597095fca77684d944a79671 Mon Sep 17 00:00:00 2001
From: Edward Nathan Varghese
Date: Wed, 6 May 2026 23:23:51 +0530
Subject: [PATCH] [clang][AMDGPU] Reject malformed target IDs with empty
components
Fixes #196078
An extra colon in `-mcpu` (e.g. `gfx900::xnack+`) produced an
empty feature component and triggered an assertion in
`StringRef::back()`.
Return `std::nullopt` for malformed target IDs instead.
---
clang/lib/Basic/TargetID.cpp | 2 ++
clang/test/Driver/amdgpu-invalid-target-id.s | 6 ++
2 files changed, 8 insertions(+)
diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index 0aca490e17903..446577930b017 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -89,6 +89,8 @@ parseTargetIDWithFormatCheckingOnly(llvm::StringRef TargetID,
while (!Features.empty()) {
auto Splits = Features.split(':');
+if (Splits.first.empty())
+ return std::nullopt;
auto Sign = Splits.first.back();
auto Feature = Splits.first.drop_back();
if (Sign != '+' && Sign != '-')
diff --git a/clang/test/Driver/amdgpu-invalid-target-id.s
b/clang/test/Driver/amdgpu-invalid-target-id.s
index 7d1d8e4772338..141768701309e 100644
--- a/clang/test/Driver/amdgpu-invalid-target-id.s
+++ b/clang/test/Driver/amdgpu-invalid-target-id.s
@@ -39,3 +39,9 @@
// RUN: %s 2>&1 | FileCheck -check-prefix=NOCOLON %s
// NOCOLON: error: invalid target ID 'gfx900+xnack'
+
+// RUN: not %clang -target amdgcn-amd-amdhsa \
+// RUN: -mcpu=gfx900::xnack+ -nostdlib \
+// RUN: %s 2>&1 | FileCheck -check-prefix=EXTRACOL %s
+
+// EXTRACOL: error: invalid target ID 'gfx900::xnack+'
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
