diff options
author | Jennifer Yu <jennifer.yu@intel.com> | 2019-05-30 01:05:46 +0000 |
---|---|---|
committer | Jennifer Yu <jennifer.yu@intel.com> | 2019-05-30 01:05:46 +0000 |
commit | 954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a (patch) | |
tree | 23479cbe88acf8d056fb2e8d5c44a9978290c5fb /clang/test/Sema/asm-goto.cpp | |
parent | 192dd7df2f3104274db57e3b853390faa7e1aa25 (diff) | |
download | bcm5719-llvm-954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a.tar.gz bcm5719-llvm-954ec09aed4f2be04bb5f4e10dbb4ea8bd19ef9a.zip |
clang support gnu asm goto.
Syntax:
asm [volatile] goto ( AssemblerTemplate
:
: InputOperands
: Clobbers
: GotoLabels)
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
New llvm IR is "callbr" for inline asm goto instead "call" for inline asm
For:
asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop);
IR:
callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,X,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@foo, %label_true), i8* blockaddress(@foo, %loop)) #1
to label %asm.fallthrough [label %label_true, label %loop], !srcloc !3
asm.fallthrough:
Compiler need to generate:
1> a dummy constarint 'X' for each label.
2> an unique fallthrough label for each asm goto stmt " asm.fallthrough%number".
Diagnostic
1> duplicate asm operand name are used in output, input and label.
2> goto out of scope.
llvm-svn: 362045
Diffstat (limited to 'clang/test/Sema/asm-goto.cpp')
-rw-r--r-- | clang/test/Sema/asm-goto.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/clang/test/Sema/asm-goto.cpp b/clang/test/Sema/asm-goto.cpp new file mode 100644 index 00000000000..f61a8096b83 --- /dev/null +++ b/clang/test/Sema/asm-goto.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 %s -triple i386-pc-linux-gnu -verify -fsyntax-only + +struct NonTrivial { + ~NonTrivial(); + int f(int); +private: + int k; +}; +void JumpDiagnostics(int n) { +// expected-error@+1 {{cannot jump from this goto statement to its label}} + goto DirectJump; +// expected-note@+1 {{jump bypasses variable with a non-trivial destructor}} + NonTrivial tnp1; + +DirectJump: +// expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}} + asm goto("jmp %l0;" ::::Later); +// expected-note@+1 {{jump bypasses variable with a non-trivial destructor}} + NonTrivial tnp2; +// expected-note@+1 {{possible target of asm goto statement}} +Later: + return; +} + +struct S { ~S(); }; +void foo(int a) { + if (a) { +FOO: +// expected-note@+2 {{jump exits scope of variable with non-trivial destructor}} +// expected-note@+1 {{jump exits scope of variable with non-trivial destructor}} + S s; + void *p = &&BAR; +// expected-error@+1 {{cannot jump from this asm goto statement to one of its possible targets}} + asm goto("jmp %l0;" ::::BAR); +// expected-error@+1 {{cannot jump from this indirect goto statement to one of its possible targets}} + goto *p; + p = &&FOO; + goto *p; + return; + } +// expected-note@+2 {{possible target of asm goto statement}} +// expected-note@+1 {{possible target of indirect goto statement}} +BAR: + return; +} |