[clang] [Clang][RISCV] Mark non-temporal load and store builtins as non-throwing (PR #249403)
Christian Sagstetter via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 6 03:46:05 PST 2026
https://github.com/saggl created https://github.com/llvm/llvm-project/pull/249403
For an `int *p`, Clang currently evaluates both `noexcept(__builtin_riscv_ntl_load(p, 2))` and `noexcept(__builtin_riscv_ntl_store(p, 0, 2))` to `false`. These Zihintntl builtins perform an ordinary load or store with a locality hint.
Mark both builtins `NoThrow`, as suggested in [the Zihintpause review](https://github.com/llvm/llvm-project/pull/139519#discussion_r2085166621). The C++ regression test checks both expressions and a store whose value argument calls a potentially throwing function.
On RV32 and RV64, the first two assertions failed before the change and all three passed with the rebuilt RISC-V frontend. The existing RV32 `riscv32-zihintntl.c` code-generation test also passed its FileCheck checks.
Assisted-by: OpenAI Codex
>From 46ffb816878b016477862760c0b68376c764853f Mon Sep 17 00:00:00 2001
From: Christian Sagstetter <christian.sagstetter at gmail.com>
Date: Sun, 6 Dec 2026 10:01:11 +0000
Subject: [PATCH] [Clang][RISCV] Mark non-temporal load and store builtins as
non-throwing
The Zihintntl builtins perform ordinary memory accesses with locality
hints. Without NoThrow, noexcept reports that even a load or store
through an int pointer can throw a C++ exception.
Add the missing attribute to both builtins. Test their exception
specifications and a store with a potentially throwing value argument.
Assisted-by: OpenAI Codex
---
clang/include/clang/Basic/BuiltinsRISCV.td | 4 ++--
clang/test/SemaCXX/riscv-ntl-noexcept.cpp | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
create mode 100644 clang/test/SemaCXX/riscv-ntl-noexcept.cpp
diff --git a/clang/include/clang/Basic/BuiltinsRISCV.td b/clang/include/clang/Basic/BuiltinsRISCV.td
index a41c39bfe5533d..38159b5867553e 100644
--- a/clang/include/clang/Basic/BuiltinsRISCV.td
+++ b/clang/include/clang/Basic/BuiltinsRISCV.td
@@ -142,10 +142,10 @@ def sm3p1 : RISCVBuiltin<"unsigned int(unsigned int)">;
//===----------------------------------------------------------------------===//
// Zihintntl extension.
//===----------------------------------------------------------------------===//
-let Features = "zihintntl", Attributes = [CustomTypeChecking] in {
+let Features = "zihintntl", Attributes = [NoThrow, CustomTypeChecking] in {
def ntl_load : RISCVBuiltin<"void(...)">;
def ntl_store : RISCVBuiltin<"void(...)">;
-} // Features = "zihintntl", Attributes = [CustomTypeChecking]
+} // Features = "zihintntl", Attributes = [NoThrow, CustomTypeChecking]
//===----------------------------------------------------------------------===//
// Zihintpause extension.
diff --git a/clang/test/SemaCXX/riscv-ntl-noexcept.cpp b/clang/test/SemaCXX/riscv-ntl-noexcept.cpp
new file mode 100644
index 00000000000000..bf12605e218eb4
--- /dev/null
+++ b/clang/test/SemaCXX/riscv-ntl-noexcept.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zihintntl -std=c++17 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+int value();
+
+void test(int *p) {
+ static_assert(noexcept(__builtin_riscv_ntl_load(p, 2)));
+ static_assert(noexcept(__builtin_riscv_ntl_store(p, 0, 2)));
+ static_assert(!noexcept(__builtin_riscv_ntl_store(p, value(), 2)));
+}
More information about the cfe-commits
mailing list