Files
clang-p2996/compiler-rt/test/ubsan/TestCases/Pointer/align-assume-attribute-align_value-on-lvalue.cpp
Martin Storsjö 2ce71b2c18 [compiler-rt] [test] Use %clangxx for tests that use -x c++
When instrumenting C++ code, ubsan ends up referencing
the ubsan_type_hash_* object files, which require linking against
the C++ ABI library. When building with "clang -x c++", the code
is handled as C++, but the compiler still only links as if it was
C.

Change all cases of "%clang -x c++" into "%clangxx -x c++".

This fixes a lot of ubsan tests in mingw mode.

Differential Revision: https://reviews.llvm.org/D147687
2023-04-11 00:02:33 +03:00

37 lines
2.3 KiB
C++

// RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:"
// RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:"
// RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:"
// RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:"
// RUN: %clangxx -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:"
// RUN: %clangxx -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:"
// RUN: %clangxx -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:"
// RUN: %clangxx -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:"
#include <stdlib.h>
typedef char *__attribute__((align_value(0x8000))) aligned_char;
struct ac_struct {
aligned_char a;
};
char *load_from_ac_struct(struct ac_struct *x) {
return x->a;
}
int main(int argc, char* argv[]) {
char *ptr = (char *)malloc(2);
struct ac_struct x;
x.a = ptr + 1; // FIXME: it is weird that this does not also have an assumption.
load_from_ac_struct(&x);
// CHECK: {{.*}}align-assume-{{.*}}.cpp:[[@LINE-9]]:13: runtime error: assumption of 32768 byte alignment for pointer of type 'aligned_char' (aka 'char *') failed
// CHECK: {{.*}}align-assume-{{.*}}.cpp:[[@LINE-17]]:30: note: alignment assumption was specified here
// CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte
free(ptr);
return 0;
}