llvm-project/clang/lib/CodeGen
Faisal Vali 57ae056a5c Quick-Fix pointer arithmetic when performing multi-D new-array initialization.
clang still doesn't emit the right llvm code when initializing multi-D arrays it seems.

For e.g. the following code would still crash for me on Windows 7, 64 bit:

auto f4 = new int[100][200][300]{{{1,2,3}, {4, 5, 6}}, {{10, 20, 30}}};

It seems that the final new loop that iterates through each outermost array and memsets it to zero gets confused with its final ptr arithmetic.

This patch ensures that it converts the pointer to the allocated type (int [200][300]) before incrementing it (instead of using the base type: 'int').

Richard somewhat squeamishly approved the patch (as a quick fix to potentially make it into 3.4) - while exhorting for a more optimized fix in the future. http://llvm-reviews.chandlerc.com/D2398
 
Thanks Richard!

llvm-svn: 197294
2013-12-14 00:40:05 +00:00
..
ABIInfo.h Add CodeGenABITypes.h for use in LLDB. 2013-10-30 21:53:58 +00:00
BackendUtil.cpp Add -freroll-loops to enable loop rerolling 2013-11-17 16:03:29 +00:00
CGAtomic.cpp Add CodeGenABITypes.h for use in LLDB. 2013-10-30 21:53:58 +00:00
CGBlocks.cpp Fix a tranche of comment, test and doc typos 2013-12-05 16:25:25 +00:00
CGBlocks.h Remove useless 'llvm::' qualifier from names like StringRef and others that are 2013-01-12 19:30:44 +00:00
CGBuilder.h Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate to 2013-01-02 11:45:17 +00:00
CGBuiltin.cpp [AArch64] Refactor NEON floating-point Max/Min/Maxnm/Minnm across vector AArch64 2013-12-11 23:21:39 +00:00
CGCUDANV.cpp Use the actual ABI-determined C calling convention for runtime 2013-02-28 19:01:20 +00:00
CGCUDARuntime.cpp Implement function type checker for the undefined behavior sanitizer. 2013-10-20 21:29:19 +00:00
CGCUDARuntime.h CUDA: IR generation support for device stubs 2011-10-06 18:51:56 +00:00
CGCXX.cpp Avoid adding some decls to DeferredDeclsToEmit. 2013-12-09 04:29:47 +00:00
CGCXXABI.cpp No functionality change. Reflow lines that could fit on one line. Break lines 2013-10-01 21:51:38 +00:00
CGCXXABI.h Move C++ destructor emission into CGCXXABI 2013-12-13 00:53:54 +00:00
CGCall.cpp [ms-cxxabi] Construct and destroy call arguments in the correct order 2013-12-04 19:23:12 +00:00
CGCall.h Add CodeGenABITypes.h for use in LLDB. 2013-10-30 21:53:58 +00:00
CGClass.cpp Move C++ destructor emission into CGCXXABI 2013-12-13 00:53:54 +00:00
CGCleanup.cpp Reapply r183721, reverted in r183776, with a fix for a bug in the former (we 2013-06-12 20:42:33 +00:00
CGCleanup.h [CodeGen] Move EHScopeStack into its own header 2013-06-19 17:07:50 +00:00
CGDebugInfo.cpp Correct hyphenations in comments and assert messages 2013-12-05 04:47:09 +00:00
CGDebugInfo.h DebugInfo: omit debug info for friends 2013-09-13 18:45:00 +00:00
CGDecl.cpp Fix a tranche of comment, test and doc typos 2013-12-05 16:25:25 +00:00
CGDeclCXX.cpp Fix crashes when creating global instances of polymorphic classes without fields 2013-10-02 16:03:16 +00:00
CGException.cpp Thread a SourceLocation into the EmitCheck for "load_invalid_value". This occurs 2013-10-02 02:29:49 +00:00
CGExpr.cpp Add front-end infrastructure now address space casts are in LLVM IR. 2013-12-11 13:39:46 +00:00
CGExprAgg.cpp Add front-end infrastructure now address space casts are in LLVM IR. 2013-12-11 13:39:46 +00:00
CGExprCXX.cpp Quick-Fix pointer arithmetic when performing multi-D new-array initialization. 2013-12-14 00:40:05 +00:00
CGExprComplex.cpp Add front-end infrastructure now address space casts are in LLVM IR. 2013-12-11 13:39:46 +00:00
CGExprConstant.cpp Add front-end infrastructure now address space casts are in LLVM IR. 2013-12-11 13:39:46 +00:00
CGExprScalar.cpp Eliminate BinaryTypeTraitExpr 2013-12-13 20:49:58 +00:00
CGObjC.cpp Remove a whole lot of unused variables 2013-11-27 05:22:15 +00:00
CGObjCGNU.cpp Fix a tranche of comment, test and doc typos 2013-12-05 16:25:25 +00:00
CGObjCMac.cpp Add CodeGenABITypes.h for use in LLDB. 2013-10-30 21:53:58 +00:00
CGObjCRuntime.cpp Add CodeGenABITypes.h for use in LLDB. 2013-10-30 21:53:58 +00:00
CGObjCRuntime.h Use the actual ABI-determined C calling convention for runtime 2013-02-28 19:01:20 +00:00
CGOpenCLRuntime.cpp Add OpenCL samplers as Clang builtin types and check sampler related restrictions. 2013-02-07 10:55:47 +00:00
CGOpenCLRuntime.h Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate to 2013-01-02 11:45:17 +00:00
CGRTTI.cpp Fix vbtable indices when a class shares the vbptr with a non-virtual base 2013-11-05 15:54:58 +00:00
CGRecordLayout.h Correct hyphenations in comments and assert messages 2013-12-05 04:47:09 +00:00
CGRecordLayoutBuilder.cpp Fix a tranche of comment, test and doc typos 2013-12-05 16:25:25 +00:00
CGStmt.cpp Correct hyphenations in comments and assert messages 2013-12-05 04:47:09 +00:00
CGVTT.cpp Fix vbtable indices when a class shares the vbptr with a non-virtual base 2013-11-05 15:54:58 +00:00
CGVTables.cpp Avoid adding some decls to DeferredDeclsToEmit. 2013-12-09 04:29:47 +00:00
CGVTables.h Fix vbtable indices when a class shares the vbptr with a non-virtual base 2013-11-05 15:54:58 +00:00
CGValue.h Simplify atomic load/store IRGen. 2013-07-11 01:32:21 +00:00
CMakeLists.txt [CMake] clang/lib: Prune redundant dependencies. 2013-12-10 02:36:22 +00:00
CodeGenABITypes.cpp Simplify the constructor to CodeGenABITypes. 2013-12-05 01:23:01 +00:00
CodeGenAction.cpp PR16214, PR14467: DebugInfo: use "RequireCompleteType" to decide when to emit the full definition of a type in -flimit-debug-info 2013-07-13 21:08:14 +00:00
CodeGenFunction.cpp Add an AdjustedType sugar node for adjusting calling conventions 2013-12-05 01:23:43 +00:00
CodeGenFunction.h [ms-cxxabi] Construct and destroy call arguments in the correct order 2013-12-04 19:23:12 +00:00
CodeGenModule.cpp [ms-cxxabi] Fix linkage of dtor thunks for anonymous classes 2013-12-11 19:21:27 +00:00
CodeGenModule.h Save another call to GetAddrOfFunction. 2013-12-09 16:01:03 +00:00
CodeGenTBAA.cpp Add a mangler entry point for TBAA rather than using RTTI directly 2013-11-19 23:23:00 +00:00
CodeGenTBAA.h Fixed comment typo. 2013-06-08 00:27:19 +00:00
CodeGenTypes.cpp Add CodeGenABITypes.h for use in LLDB. 2013-10-30 21:53:58 +00:00
CodeGenTypes.h Fix Windows build by including CGFunctionInfo.h. 2013-10-30 23:40:28 +00:00
EHScopeStack.h [CodeGen] Move EHScopeStack into its own header 2013-06-19 17:07:50 +00:00
ItaniumCXXABI.cpp Move C++ destructor emission into CGCXXABI 2013-12-13 00:53:54 +00:00
Makefile
MicrosoftCXXABI.cpp Move C++ destructor emission into CGCXXABI 2013-12-13 00:53:54 +00:00
MicrosoftVBTables.cpp Fix vbtable indices when a class shares the vbptr with a non-virtual base 2013-11-05 15:54:58 +00:00
MicrosoftVBTables.h [ms-cxxabi] Emit and install appropriately mangled vbtables 2013-06-19 15:20:38 +00:00
ModuleBuilder.cpp When we decide to output a deferred decl, remember the llvm GlobalValue. 2013-12-09 14:59:08 +00:00
README.txt
TargetInfo.cpp Replace use of Triple::getEnvironmentName with the simpler 2013-12-12 21:29:27 +00:00
TargetInfo.h Fix a tranche of comment, test and doc typos 2013-12-05 16:25:25 +00:00

README.txt

IRgen optimization opportunities.

//===---------------------------------------------------------------------===//

The common pattern of
--
short x; // or char, etc
(x == 10)
--
generates an zext/sext of x which can easily be avoided.

//===---------------------------------------------------------------------===//

Bitfields accesses can be shifted to simplify masking and sign
extension. For example, if the bitfield width is 8 and it is
appropriately aligned then is is a lot shorter to just load the char
directly.

//===---------------------------------------------------------------------===//

It may be worth avoiding creation of alloca's for formal arguments
for the common situation where the argument is never written to or has
its address taken. The idea would be to begin generating code by using
the argument directly and if its address is taken or it is stored to
then generate the alloca and patch up the existing code.

In theory, the same optimization could be a win for block local
variables as long as the declaration dominates all statements in the
block.

NOTE: The main case we care about this for is for -O0 -g compile time
performance, and in that scenario we will need to emit the alloca
anyway currently to emit proper debug info. So this is blocked by
being able to emit debug information which refers to an LLVM
temporary, not an alloca.

//===---------------------------------------------------------------------===//

We should try and avoid generating basic blocks which only contain
jumps. At -O0, this penalizes us all the way from IRgen (malloc &
instruction overhead), all the way down through code generation and
assembly time.

On 176.gcc:expr.ll, it looks like over 12% of basic blocks are just
direct branches!

//===---------------------------------------------------------------------===//