In tandem with my riscv ECF flag patch I fell over this, where the C++ FE doesn't propagate the NO_VOPS flag. I happen to be using that on our builtins, and we also explicitly declare our builtins (so that code analysis tools are not confused).

Boom, optimizations stop working :(

I wasn't sure whether this was the best place or merge_attribute_bits would be better. I went with here, as that more closely matches the C FE, which is already propagating these bits.

I'll commit in a few days, if there are no comments.

nathan

--
Nathan Sidwell
From f93683d708931708b2ca8bdd85acf781e39c9fab Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <[email protected]>
Date: Tue, 20 Oct 2026 09:11:52 -0400
Subject: [PATCH] [C++] Fix duplicate-decls flag clearing

	gcc/cp/
	* decl.cc (duplicate_decls): Propagate DECL_NO_LIMIT_STACK,
	DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT, DECL_IS_NOVOPS.
---
 gcc/cp/decl.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 593e67fd03b..94782c52017 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2665,6 +2665,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
 	DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
+      DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
+      DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
+	|= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
+      DECL_IS_NOVOPS (newdecl) |= DECL_IS_NOVOPS (olddecl);
       DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
       DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
-- 
2.56.0

Reply via email to