https://bugs.llvm.org/show_bug.cgi?id=45168

            Bug ID: 45168
           Summary: [inline assembly] "p" constraint is not always a valid
                    address
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: compile-fail, miscompilation
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]

Consider the following (useless) code:

int * f (int *p)
{
    __asm__ ("leal %a1, %0" : "=r" (p) : "p" (p));
    return p;
}

Which produces the following IR:

define dso_local i32* @f(i32* readnone) local_unnamed_addr #0 !dbg !8 {
  call void @llvm.dbg.value(metadata i32* %0, metadata !15, metadata
!DIExpression()), !dbg !16
  %2 = tail call i32* asm "leal ${1:a}, $0",
"=r,im,~{dirflag},~{fpsr},~{flags}"(i32* %0) #2, !dbg !17, !srcloc !18
  call void @llvm.dbg.value(metadata i32* %2, metadata !15, metadata
!DIExpression()), !dbg !16
  ret i32* %2, !dbg !19
}

We can see that "p" has been translated to "im". It is true from at least clang
3.0 to at least 9.0 (tested on https://godbolt.org/).
But "p" definition is "An operand that is a valid memory address is allowed.".
Correct me, but "m" is not a valid memory address as it is already a memory
access.
I think a non-optimal way to encode "p" would rather be "ir" as both constant
and register can be part of an address, but it would miss complex addresses
like "%ebp + 4 * %eax - 8".

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to