[clang] [clang] Alias cc modifier to c (PR #127719)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 26 10:46:53 PST 2025
https://github.com/PiJoules updated https://github.com/llvm/llvm-project/pull/127719
>From 886754d42cf8619771b0877bc7edde940642c799 Mon Sep 17 00:00:00 2001
From: Leonard Chan <leonardchan at google.com>
Date: Tue, 18 Feb 2025 15:33:05 -0800
Subject: [PATCH] [clang] Alias cc modifier to c
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#GenericOperandmodifiers
provides the `c` and `cc` modifiers. GCC 15 introduces the `cc` modifier
which does the same as `c`. This patch lets Clang handle this for
compatibility.
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/AST/Stmt.cpp | 7 +++++++
clang/test/AST/cc-modifier.cpp | 10 ++++++++++
clang/test/CodeGen/asm.c | 6 ++++++
4 files changed, 25 insertions(+)
create mode 100644 clang/test/AST/cc-modifier.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a91c764860ccd..ec794fd1b9c30 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,8 @@ C23 Feature Support
Non-comprehensive list of changes in this release
-------------------------------------------------
+- Support parsing the `cc` operand modifier and alias it to the `c` modifier (#GH127719).
+
New Compiler Flags
------------------
diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp
index 685c00d0cb44f..c8ff2ecea20cc 100644
--- a/clang/lib/AST/Stmt.cpp
+++ b/clang/lib/AST/Stmt.cpp
@@ -708,6 +708,13 @@ unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
DiagOffs = CurPtr-StrStart-1;
return diag::err_asm_invalid_escape;
}
+
+ // Specifically handle `cc` which we will alias to `c`.
+ // Note this is the only operand modifier that exists which has two
+ // characters.
+ if (EscapedChar == 'c' && *CurPtr == 'c')
+ CurPtr++;
+
EscapedChar = *CurPtr++;
}
diff --git a/clang/test/AST/cc-modifier.cpp b/clang/test/AST/cc-modifier.cpp
new file mode 100644
index 0000000000000..24eb105acd2b7
--- /dev/null
+++ b/clang/test/AST/cc-modifier.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -verify
+// expected-no-diagnostics
+
+void func();
+void func2();
+
+bool func3() {
+ __asm__("%cc0 = %c1" : : "X"(func), "X"(func2));
+ return func2 == func;
+}
diff --git a/clang/test/CodeGen/asm.c b/clang/test/CodeGen/asm.c
index 10102cc2c4db1..9687c993e6464 100644
--- a/clang/test/CodeGen/asm.c
+++ b/clang/test/CodeGen/asm.c
@@ -284,3 +284,9 @@ void *t33(void *ptr)
// CHECK: @t33
// CHECK: %1 = call ptr asm "lea $1, $0", "=r,p,~{dirflag},~{fpsr},~{flags}"(ptr %0)
}
+
+void t34(void) {
+ __asm__ volatile("T34 CC NAMED MODIFIER: %cc[input]" :: [input] "i" (4));
+ // CHECK: @t34()
+ // CHECK: T34 CC NAMED MODIFIER: ${0:c}
+}
More information about the cfe-commits
mailing list