llvm-capstone/clang/test/CodeGen/unaligned-struct-copy.c
Jan Ole Hüser d2e7dca5ca [CodeGen] Fix Bug 47499: __unaligned extension inconsistent behaviour with C and C++
For the language C++ the keyword __unaligned (a Microsoft extension) had no effect on pointers.

The reason, why there was a difference between C and C++ for the keyword __unaligned:
For C, the Method getAsCXXREcordDecl() returns nullptr. That guarantees that hasUnaligned() is called.
If the language is C++, it is not guaranteed, that hasUnaligend() is called and evaluated.

Here are some links:

The Bug: https://bugs.llvm.org/show_bug.cgi?id=47499
Thread on the cfe-dev mailing list: http://lists.llvm.org/pipermail/cfe-dev/2020-September/066783.html
Diff, that introduced the check hasUnaligned() in getNaturalTypeAlignment(): https://reviews.llvm.org/D30166

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D90630
2020-11-05 12:57:17 -08:00

33 lines
912 B
C

// RUN: %clang_cc1 -xc -O2 -triple thumbv7a-unknown-windows-eabi -fms-extensions -emit-llvm < %s | FileCheck %s
// RUN: %clang_cc1 -xc++ -O2 -triple thumbv7a-unknown-windows-eabi -fms-extensions -emit-llvm < %s | FileCheck %s
// RUN: %clang_cc1 -xc -O2 -triple x86_64-unknown-linux-gnu -fms-extensions -emit-llvm < %s | FileCheck %s
// RUN: %clang_cc1 -xc++ -O2 -triple x86_64-unknown-linux-gnu -fms-extensions -emit-llvm < %s | FileCheck %s
struct S1 {
unsigned long x;
};
// CHECK: define
// CHECK-SAME: void
// CHECK-SAME: test1
void test1(__unaligned struct S1 *out) {
// CHECK: store
// CHECK-SAME: align 1
out->x = 5;
// CHECK: ret void
}
// CHECK: define
// CHECK-SAME: void
// CHECK-SAME: test2
void test2(__unaligned struct S1 *out, __unaligned struct S1 *in) {
// CHECK: load
// CHECK-SAME: align 1
// CHECK: store
// CHECK-SAME: align 1
*out = *in;
// CHECK: ret void
}