]> granicus.if.org Git - clang/commitdiff
Honor the casted-to alignment of an explicit cast even when
authorJohn McCall <rjmccall@apple.com>
Tue, 29 Sep 2015 04:37:40 +0000 (04:37 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 29 Sep 2015 04:37:40 +0000 (04:37 +0000)
Sema thinks the cast is a no-op, as it does when (e.g.) the
only thing that changes is an alignment attribute.

Fixed PR24944.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248775 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/CodeGen/alignment.c

index c38dbdd7d3034a25a00ffea0141722ddf5c64c44..ece83371db9473ab8e8e292fcfcddcc05a4b265c 100644 (file)
@@ -814,7 +814,6 @@ Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E,
         // If this is an explicit bitcast, and the source l-value is
         // opaque, honor the alignment of the casted-to type.
         if (isa<ExplicitCastExpr>(CE) &&
-            CE->getCastKind() == CK_BitCast &&
             InnerSource != AlignmentSource::Decl) {
           Addr = Address(Addr.getPointer(),
                          getNaturalPointeeTypeAlignment(E->getType(), Source));
index 0a598010c85326c446dd716e815c76e9f6be5a37..c9f58136e38a78a7e325003c672252220ccd1056 100644 (file)
@@ -59,3 +59,11 @@ void test4(float4align64 *p) {
 // CHECK: @test4(
 // CHECK: store <4 x float> {{.*}}, <4 x float>* {{.*}}, align 64
 
+// PR24944 - Typedef alignment not honored on no-op cast.
+typedef float __attribute__((vector_size(16), aligned(16))) float4align16;
+typedef float __attribute__((vector_size(16), aligned(2))) float4align2;
+void test6(float4align64 *p) {
+    float4align64 vec = *(float4align2*) p;
+}
+// CHECK-LABEL: @test6
+// CHECK:       load <4 x float>, <4 x float>* {{.*}}, align 2