2015-10-08 12:24:12 +08:00
|
|
|
// RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -triple x86_64-apple-darwin -o - %s | FileCheck %s
|
2013-03-15 01:53:33 +08:00
|
|
|
//
|
|
|
|
// Test that debug location is generated for a captured "self" inside
|
|
|
|
// a block.
|
|
|
|
//
|
|
|
|
// This test is split into two parts, this one for the frontend, and
|
|
|
|
// then llvm/test/DebugInfo/debug-info-block-captured-self.ll to
|
|
|
|
// ensure that DW_AT_location is generated for the captured self.
|
|
|
|
@class T;
|
|
|
|
@interface S
|
|
|
|
@end
|
|
|
|
@interface Mode
|
|
|
|
-(int) count;
|
|
|
|
@end
|
|
|
|
@interface Context
|
|
|
|
@end
|
|
|
|
@interface ViewController
|
|
|
|
@property (nonatomic, readwrite, strong) Context *context;
|
|
|
|
@end
|
|
|
|
typedef enum {
|
|
|
|
Unknown = 0,
|
|
|
|
} State;
|
|
|
|
@interface Main : ViewController
|
|
|
|
{
|
|
|
|
T * t1;
|
|
|
|
T * t2;
|
|
|
|
}
|
|
|
|
@property(readwrite, nonatomic) State state;
|
|
|
|
@end
|
|
|
|
@implementation Main
|
|
|
|
- (id) initWithContext:(Context *) context
|
|
|
|
{
|
|
|
|
t1 = [self.context withBlock:^(id obj){
|
|
|
|
id *mode1;
|
|
|
|
t2 = [mode1 withBlock:^(id object){
|
|
|
|
Mode *mode2 = object;
|
|
|
|
if ([mode2 count] != 0) {
|
|
|
|
self.state = 0;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
// The important part of this test is that there is a dbg.value
|
|
|
|
// intrinsic associated with the implicit .block_descriptor argument
|
|
|
|
// of the block. We also test that this value gets alloca'd, so the
|
|
|
|
// register llocator won't accidentally kill it.
|
|
|
|
|
|
|
|
// outer block:
|
|
|
|
// CHECK: define internal void {{.*}}_block_invoke{{.*}}
|
|
|
|
|
|
|
|
// inner block:
|
|
|
|
// CHECK: define internal void {{.*}}_block_invoke{{.*}}
|
2013-03-30 03:20:35 +08:00
|
|
|
// CHECK: %[[MEM1:.*]] = alloca i8*, align 8
|
|
|
|
// CHECK-NEXT: %[[MEM2:.*]] = alloca i8*, align 8
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
// CHECK-NEXT: [[DBGADDR:%.*]] = alloca [[BLOCK_T:<{.*}>]]*, align 8
|
2013-03-30 03:20:35 +08:00
|
|
|
// CHECK: store i8* [[BLOCK_DESC:%.*]], i8** %[[MEM1]], align 8
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: %[[TMP0:.*]] = load i8*, i8** %[[MEM1]]
|
2014-12-16 03:10:08 +08:00
|
|
|
// CHECK: call void @llvm.dbg.value(metadata i8* %[[TMP0]], i64 0, metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
|
|
|
|
// CHECK: call void @llvm.dbg.declare(metadata i8* [[BLOCK_DESC]], metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
// CHECK: store [[BLOCK_T]]* {{%.*}}, [[BLOCK_T]]** [[DBGADDR]], align 8
|
|
|
|
// CHECK: call void @llvm.dbg.declare(metadata [[BLOCK_T]]** [[DBGADDR]], metadata ![[SELF:.*]], metadata !{{.*}})
|
2013-03-30 03:20:35 +08:00
|
|
|
// make sure we are still in the same function
|
|
|
|
// CHECK: define {{.*}}__copy_helper_block_
|
|
|
|
// Metadata
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[MAIN:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Main"
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: line: 23,
|
2015-04-30 00:40:08 +08:00
|
|
|
// CHECK: ![[PMAIN:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[MAIN]],
|
2015-08-01 02:59:37 +08:00
|
|
|
// CHECK: ![[BDMD]] = !DILocalVariable(name: ".block_descriptor", arg:
|
|
|
|
// CHECK: ![[SELF]] = !DILocalVariable(name: "self"
|
|
|
|
// CHECK-NOT: arg:
|
2015-03-04 01:25:55 +08:00
|
|
|
// CHECK-SAME: line: 40,
|