brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · a41412e Raw
91 lines · cpp
1// REQUIRES: x86-registered-target2 3// RUN: rm -rf %t && split-file %s %t4// RUN: %clang_cc1 -triple x86_64-unknown-fuchsia -O2 -flto -ffat-lto-objects \5// RUN:          -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -fvisibility=hidden \6// RUN:          -emit-llvm -o - %t/a.cpp \7// RUN:   | FileCheck %s --check-prefix=TYPE_TEST8 9//--- a.cpp10// TYPE_TEST: llvm.embedded.object11// TYPE_TEST-SAME: section ".llvm.lto"12 13// COM: The FatLTO pipeline should remove all llvm.type.test instructions.14// TYPE_TEST-LABEL: define hidden void @foo15// TYPE_TEST-NOT:   @llvm.type.test16// TYPE_TEST-NEXT:  entry:17// TYPE_TEST-NEXT:    %cmp14.not = icmp eq i64 %len, 018// TYPE_TEST-NEXT:    br i1 %cmp14.not, label %for.end7, label %for.cond1.preheader.preheader19// TYPE_TEST-LABEL: for.cond1.preheader.preheader:                    ; preds = %entry20// TYPE_TEST-NEXT:    %arrayidx.1 = getelementptr inbounds nuw i8, ptr %ptr, i64 421// TYPE_TEST-NEXT:    br label %for.cond1.preheader22 23// The code below is a reduced case from https://github.com/llvm/llvm-project/issues/11205324#define __PRINTFLIKE(__fmt, __varargs) __attribute__((__format__(__printf__, __fmt, __varargs)))25typedef void func(void* arg, const char* fmt, ...) __PRINTFLIKE(2, 3);26typedef __SIZE_TYPE__ size_t;27typedef unsigned long uintptr_t;28 29extern "C"30void foo(const void* ptr, size_t len, long disp_addr,31                     func* printf_func, void* printf_arg) {32  uintptr_t address = (uintptr_t)ptr;33  size_t count;34 35  for (count = 0; count < len; count += 16) {36    union {37      unsigned int buf[4];38      unsigned char cbuf[16];39    } u;40    size_t s = 10;41    size_t i;42 43    for (i = 0; i < s / 4; i++) {44      u.buf[i] = ((const unsigned int*)address)[i];45      printf_func(printf_arg, "%08x ", static_cast<unsigned int>(u.buf[i]));46    }47  }48}49 50//--- b.cpp51// COM: Prior to the introduction of the FatLTO cleanup pass, this used to cause52// COM: the backend to crash, either due to an assertion failure, or because53// COM: the CFI instructions couldn't be correctly generated. So, check to make54// COM: sure that the FatLTO pipeline used by clang does not regress.55 56// COM: Check the generated IR doesn't contain llvm.type.checked.load in the final IR.57// RUN: %clang_cc1 -triple=x86_64-unknown-fuchsia -O1 -emit-llvm -o - \58// RUN:      -ffat-lto-objects -fvisibility=hidden \59// RUN:      -fno-rtti -fsanitize=cfi-icall,cfi-mfcall,cfi-nvcall,cfi-vcall \60// RUN:      -fsanitize-trap=cfi-icall,cfi-mfcall,cfi-nvcall,cfi-vcall \61// RUN:      -fwhole-program-vtables %t/b.cpp 2>&1 | FileCheck %s --check-prefix=NO_CHECKED_LOAD62 63// RUN: %clang_cc1 -triple=x86_64-unknown-fuchsia -O1 -emit-llvm -o - \64// RUN:      -ffat-lto-objects -fvisibility=hidden -fexperimental-relative-c++-abi-vtables \65// RUN:      -fno-rtti -fsanitize=cfi-icall,cfi-mfcall,cfi-nvcall,cfi-vcall \66// RUN:      -fsanitize-trap=cfi-icall,cfi-mfcall,cfi-nvcall,cfi-vcall \67// RUN:      -fwhole-program-vtables %t/b.cpp 2>&1 | FileCheck %s --check-prefix=NO_CHECKED_LOAD68 69// COM: Note that the embedded bitcode section will contain references to70// COM: llvm.type.checked.load, so we need to match the function body first.71// NO_CHECKED_LOAD-LABEL: entry:72// NO_CHECKED_LOAD-NEXT:    %vtable = load ptr, ptr %p173// NO_CHECKED_LOAD-NOT:   llvm.type.checked.load.relative74// NO_CHECKED_LOAD-NEXT:    %rel_load = tail call ptr @llvm.load.relative.i32(ptr %vtable, i32 0)75// NO_CHECKED_LOAD-NEXT:    %call = tail call {{.*}} %rel_load(ptr {{.*}} %p1)76// NO_CHECKED_LOAD-NEXT:    ret void77 78// COM: Ensure that we don't crash in the backend anymore when clang uses79// COM: CFI checks with -ffat-lto-objects.80// RUN: %clang_cc1 -triple=x86_64-unknown-fuchsia -O1 -emit-codegen-only \81// RUN:      -ffat-lto-objects -fvisibility=hidden \82// RUN:      -fno-rtti -fsanitize=cfi-icall,cfi-mfcall,cfi-nvcall,cfi-vcall \83// RUN:      -fsanitize-trap=cfi-icall,cfi-mfcall,cfi-nvcall,cfi-vcall \84// RUN:      -fwhole-program-vtables %t/b.cpp85 86class a {87public:88  virtual long b();89};90void c(a &p1) { p1.b(); }91