diff options
author | Chris Lattner <sabre@nondot.org> | 2011-02-19 22:28:58 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-02-19 22:28:58 +0000 |
commit | b0ed51da1021414c5445b07955579dab625f454e (patch) | |
tree | 9f31cf29ad81ac02353c891a5bdaf296907a0dcd /clang | |
parent | d66828daf633bfc74742339ed6e0e214cb6c959e (diff) | |
download | bcm5719-llvm-b0ed51da1021414c5445b07955579dab625f454e.tar.gz bcm5719-llvm-b0ed51da1021414c5445b07955579dab625f454e.zip |
implement a tiny amount of codegen support for gnu array range
designators: allowing codegen when the element initializer is a
constant or something else without a side effect. This unblocks
enough to let process.c in the linux kernel build, PR9257.
llvm-svn: 126056
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 9 | ||||
-rw-r--r-- | clang/test/CodeGen/init.c | 15 |
2 files changed, 22 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index b0749484f5d..b9a6a5713b8 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -1593,14 +1593,19 @@ InitListChecker::CheckDesignatedInitializer(const InitializedEntity &Entity, } else { assert(D->isArrayRangeDesignator() && "Need array-range designator"); - DesignatedStartIndex = DIE->getArrayRangeStart(*D)->EvaluateAsInt(SemaRef.Context); DesignatedEndIndex = DIE->getArrayRangeEnd(*D)->EvaluateAsInt(SemaRef.Context); IndexExpr = DIE->getArrayRangeEnd(*D); - if (DesignatedStartIndex.getZExtValue() !=DesignatedEndIndex.getZExtValue()) + // Codegen can't handle evaluating array range designators that have side + // effects, because we replicate the AST value for each initialized element. + // As such, set the sawArrayRangeDesignator() bit if we initialize multiple + // elements with something that has a side effect, so codegen can emit an + // "error unsupported" error instead of miscompiling the app. + if (DesignatedStartIndex.getZExtValue()!=DesignatedEndIndex.getZExtValue()&& + DIE->getInit()->HasSideEffects(SemaRef.Context)) FullyStructuredList->sawArrayRangeDesignator(); } diff --git a/clang/test/CodeGen/init.c b/clang/test/CodeGen/init.c index ccb04f343c6..0f94729a949 100644 --- a/clang/test/CodeGen/init.c +++ b/clang/test/CodeGen/init.c @@ -100,3 +100,18 @@ int test10(int X) { // CHECK-NOT: store i32 0 // CHECK: call void @bar } + + +// PR9257 +struct test11S { + int A[10]; +}; +void test11(struct test11S *P) { + *P = (struct test11S) { .A = { [0 ... 3] = 4 } }; + // CHECK: @test11 + // CHECK: store i32 4 + // CHECK: store i32 4 + // CHECK: store i32 4 + // CHECK: store i32 4 + // CHECK: ret void +} |