1. With a Clang that doesn't default to GNU extensions they need to be enabled explicitly. 2. The X86 directory lit config sets it already, there's no reason for this test to do it by itself. 3. The C frontend executable will fail if there's for example a Clang resource file for the C++ mode that sets C++-specific options: ``` + /home/tambre/dev/llvm/build/bin/clang --target=x86_64-unknown-linux-gnu -fPIE -fuse-ld=lld -Wl,--unresolved-symbols=ignore-all -pie -fPIC -shared /home/tambre/dev/llvm/bolt/test/R_ABS.pic.lld.cpp -o /home/tambre/dev/llvm/build/tools/bolt/test/Output/R_ABS.pic.lld.cpp.tmp.so -Wl,-q -fuse-ld=lld clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument] error: invalid argument '-std=c23' not allowed with 'C++' ```
56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
// A contrived example to test the double jump removal peephole.
|
|
|
|
// RUN: %clangxx %cxxflags -O0 %s -o %t.exe
|
|
// RUN: llvm-bolt %t.exe -o %t.bolt --peepholes=double-jumps | \
|
|
// RUN: FileCheck %s -check-prefix=CHECKBOLT
|
|
// RUN: llvm-objdump --no-print-imm-hex -d %t.bolt | FileCheck %s
|
|
|
|
// CHECKBOLT: BOLT-INFO: Peephole: 1 double jumps patched.
|
|
|
|
// CHECK: <_Z3foom>:
|
|
// CHECK-NEXT: sub sp, sp, #16
|
|
// CHECK-NEXT: str x0, [sp, #8]
|
|
// CHECK-NEXT: ldr [[REG:x[0-28]+]], [sp, #8]
|
|
// CHECK-NEXT: cmp [[REG]], #0
|
|
// CHECK-NEXT: b.eq {{.*}} <_Z3foom+0x34>
|
|
// CHECK-NEXT: add [[REG]], [[REG]], #1
|
|
// CHECK-NEXT: add [[REG]], [[REG]], #1
|
|
// CHECK-NEXT: cmp [[REG]], #2
|
|
// CHECK-NEXT: b.eq {{.*}} <_Z3foom+0x28>
|
|
// CHECK-NEXT: add [[REG]], [[REG]], #1
|
|
// CHECK-NEXT: mov [[REG]], x1
|
|
// CHECK-NEXT: ldr x1, [sp]
|
|
// CHECK-NEXT: b {{.*}} <bar>
|
|
// CHECK-NEXT: ldr x1, [sp]
|
|
// CHECK-NEXT: add [[REG]], [[REG]], #1
|
|
// CHECK-NEXT: b {{.*}} <bar>
|
|
|
|
extern "C" unsigned long bar(unsigned long count) { return count + 1; }
|
|
|
|
unsigned long foo(unsigned long count) {
|
|
asm volatile(" cmp %0,#0\n"
|
|
" b.eq .L7\n"
|
|
" add %0, %0, #1\n"
|
|
" b .L1\n"
|
|
".L1: b .L2\n"
|
|
".L2: add %0, %0, #1\n"
|
|
" cmp %0, #2\n"
|
|
" b.ne .L3\n"
|
|
" b .L4\n"
|
|
".L3: b .L5\n"
|
|
".L5: add %0, %0, #1\n"
|
|
".L4: mov %0,x1\n"
|
|
" ldr x1, [sp]\n"
|
|
" b .L6\n"
|
|
".L7: ldr x1, [sp]\n"
|
|
" add %0, %0, #1\n"
|
|
" b .L6\n"
|
|
".L6: b bar\n"
|
|
:
|
|
: "r"(count)
|
|
:);
|
|
return count;
|
|
}
|
|
|
|
extern "C" int _start() { return foo(38); }
|