On Tue, Jan 07, 2025 at 08:36:29PM +0100, Jakub Jelinek wrote:
> Hi!
> 
> The following patch fixes ICEs when the new inline asm syntax
> to use C++26 static_assert-like constant expressions in place
> of string literals is used in templates.
> As finish_asm_stmt doesn't do any checking for
> processing_template_decl, this patch also just defers handling
> those strings in templates rather than say trying fold_non_dependent_expr
> and if the result is non-dependent and usable, try to extract.

Thanks. I've been looking at a similar patch, but you beat me to it.
Your patch looks good to me, except for two comments below.

> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> There is one case I didn't handle and I'd like to discuss.
> The initial commit to enable this new extension also changed
> cp_parser_asm_specification_opt to use cp_parser_asm_string_expression.
> That function doesn't have anything to do with asm statements though,
> it is about asm redirection of declarations.

I don't know of a use case for this, so i guess it can be rejected
(like this patchlet)

@@ -30067,7 +30063,11 @@ cp_parser_asm_specification_opt (cp_parser* parser)
   parens.require_open (parser);
 
   /* Look for the string-literal.  */
+  token = cp_lexer_peek_token (parser->lexer);
   tree asm_specification = cp_parser_asm_string_expression (parser);
+  if (TREE_CODE (asm_specification) != STRING_CST)
+    error_at (token->location,
+             "%<asm%> specification for declaration must be string");
 
   /* Look for the `)'.  */
   parens.require_close (parser);

Since you add a return of error_mark_node to finish_asm_stmt you
also need this patchlet:

@@ -19170,7 +19170,8 @@ tsubst_stmt (tree t, tree args, tsubst_flags_t 
complain, tree in_decl)
        tree asm_expr = tmp;
        if (TREE_CODE (asm_expr) == CLEANUP_POINT_EXPR)
          asm_expr = TREE_OPERAND (asm_expr, 0);
-       ASM_BASIC_P (asm_expr) = ASM_BASIC_P (t);
+       if (asm_expr != error_mark_node)
+         ASM_BASIC_P (asm_expr) = ASM_BASIC_P (t);
       }
       break;



>    else if (!cp_parser_is_string_literal (tok))
>      {
> --- gcc/testsuite/g++.dg/cpp1z/constexpr-asm-4.C.jj   2025-01-07 
> 12:19:34.472033295 +0100
> +++ gcc/testsuite/g++.dg/cpp1z/constexpr-asm-4.C      2025-01-07 
> 12:28:59.178178486 +0100

It needs a test case with constexpr errors too. In my version I had
a lot of trouble with them.

-Andi

Reply via email to