From 173fc51082e5821d8d8d54c81f3d9222999de36c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 5 Sep 2025 13:42:56 +0200 Subject: [PATCH 1/3] [LangRef] inline asm: the template string is treated opaquely --- llvm/docs/LangRef.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index e64b9343b7622..7ee137d50cfbc 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -5227,7 +5227,10 @@ represents the inline assembler as a template string (containing the instructions to emit), a list of operand constraints (stored as a string), a flag that indicates whether or not the inline asm expression has side effects, and a flag indicating whether the function containing the asm needs to align its -stack conservatively. +stack conservatively. The compiler's understanding of the semantics of the +expression comes only from the list of operand constraints and the flags -- not +the contents of the template string. In particular, no optimizations or analyses +will be performed based on the contents of that string. The template string supports argument substitution of the operands using "``$``" followed by a number, to indicate substitution of the given register/memory From e5d04c8447b2bcf45e928ad7ab34b25a536b14cf Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 15 Sep 2025 15:52:35 +0200 Subject: [PATCH 2/3] explicitly mention self-modifying code --- llvm/docs/LangRef.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 7ee137d50cfbc..01a160c958a9d 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -5227,10 +5227,15 @@ represents the inline assembler as a template string (containing the instructions to emit), a list of operand constraints (stored as a string), a flag that indicates whether or not the inline asm expression has side effects, and a flag indicating whether the function containing the asm needs to align its -stack conservatively. The compiler's understanding of the semantics of the -expression comes only from the list of operand constraints and the flags -- not -the contents of the template string. In particular, no optimizations or analyses -will be performed based on the contents of that string. +stack conservatively. + +The compiler's understanding of the semantics of the expression comes only from +the list of operand constraints and the flags -- not the contents of the +template string. In particular, no optimizations or analyses will be performed +based on the contents of that string. This ensures correct behavior if the +assembly code emitted by this expression is altered later, e.g. via +self-modifying code, as long as the code keeps upholding the requirements of the +operand constraints and the flags. The template string supports argument substitution of the operands using "``$``" followed by a number, to indicate substitution of the given register/memory From 077349a2bd9399ca218252e22e812ba36f1062a7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 3 Oct 2025 16:52:40 +0200 Subject: [PATCH 3/3] only forbid correctness-critical analyses from inspecting the template string --- llvm/docs/LangRef.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 01a160c958a9d..f5873fcd150e6 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -5229,13 +5229,13 @@ flag that indicates whether or not the inline asm expression has side effects, and a flag indicating whether the function containing the asm needs to align its stack conservatively. -The compiler's understanding of the semantics of the expression comes only from -the list of operand constraints and the flags -- not the contents of the -template string. In particular, no optimizations or analyses will be performed -based on the contents of that string. This ensures correct behavior if the -assembly code emitted by this expression is altered later, e.g. via -self-modifying code, as long as the code keeps upholding the requirements of the -operand constraints and the flags. +The compiler may not assume that the actual code executed at runtime matches the +contents of the template string. Correctness-critical analyses must base their +results only on the list of operand constraints and the flags -- not the +contents of the template string. This ensures correct behavior if the assembly +code emitted by this expression is altered later, e.g. via self-modifying code, +as long as the code keeps upholding the requirements of the operand constraints +and the flags. The template string supports argument substitution of the operands using "``$``" followed by a number, to indicate substitution of the given register/memory