Commit Graph

46 Commits

Author SHA1 Message Date
Richard Smith 1bc857476c Revert r332847; it caused us to miscompile certain forms of reference initialization.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332886 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-21 20:36:58 +00:00
Serge Pavlov 6b450481a2 [CodeGen] Recognize more cases of zero initialization
If a variable has an initializer, codegen tries to build its value. If
the variable is large in size, building its value requires substantial
resources. It causes strange behavior from user viewpoint: compilation
of huge zero initialized arrays like:

    char data_1[2147483648u] = { 0 };

consumes enormous amount of time and memory.

With this change codegen tries to determine if variable initializer is
equivalent to zero initializer. In this case variable value is not
constructed.

This change fixes PR18978.

Differential Revision: https://reviews.llvm.org/D46241


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332847 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-21 16:09:54 +00:00
David Majnemer 57db772581 [CodeGen] Use pointer-sized integers for ptrtoint sources
Given something like:
void *v = (void *)100;

We need to synthesize a ptrtoint operation from 100.  During constant
emission, we choose i64 as the type for our constant because it
guaranteed not to drop any bits from our CharUnits representation of the
value.  However, this is suboptimal for 32-bit targets: LLVM passes like
GlobalOpt will get confused by these sorts of casts resulting in
pessimization.

Instead, make sure the ptrtoint operand has a pointer-sized integer
type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273020 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-17 17:47:24 +00:00
David Blaikie a6eaa6b50b Test case updates for explicit type parameter to the gep operator
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232187 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-13 18:21:46 +00:00
David Majnemer 05db1e2826 CodeGen: ConstStructBuilder must verify packed constraints after padding
This reverts commit r220169 which reverted r220153.  However, it also
contains additional changes:
- We may need to add padding *after* we've packed the struct.  This
  occurs when the aligned next field offset is greater than the new
  field's offset.  When this occurs, we make the struct packed.
  *However*, once packed the next field offset might be less than the
  new feild's offset.  It is in this case that we might further pad the
  struct.
- We would pad structs which were perfectly sized!  This behavior is
  immensely old.  This behavior came from blindly subtracting
  NextFieldOffsetInChars from RecordSize.  This doesn't take into
  account the fact that the struct might have a greater overall
  alignment than the last field.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220175 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-19 23:40:06 +00:00
Chandler Carruth 0334832bd5 Revert r220153: "CodeGen: ConstStructBuilder must verify packed constraints after padding"
This commit caused two tests in LNT to regress. I'm able to reproduce on
any platform and will send reproduction steps to the original commit
log. This should restore the LNT bots that have been failing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220169 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-19 19:41:46 +00:00
David Majnemer 9fd8cd1b67 CodeGen: ConstStructBuilder must verify packed constraints after padding
Before, ConstStructBuilder::AppendBytes would check packed constraints
prior to padding being added before the field's offset.  However, adding
this padding might force our struct to be packed.  Because we wouldn't
check *after* adding padding, ConstStructBuilder would be in an
inconsistent state leading to a crash.

This fixes PR21300.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220153 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-19 00:03:10 +00:00
Rafael Espindola 4f868f75ec Add missing expected-warning.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185644 91177308-0d34-0410-b5e6-96231b3b80d8
2013-07-04 15:04:25 +00:00
Eli Friedman f0a26499c0 Fix InitListExpr::isStringLiteralInit so it handles various edge cases correctly. PR13643.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162226 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-20 20:55:45 +00:00
Eli Friedman e6a24e83e7 Add support for bitcasts to vector type in Evaluate.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147137 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-22 03:51:45 +00:00
Chris Lattner cd87d1e4d1 fix an unintended behavior change in the type system rewrite, which caused us to compile
stuff like this:

typedef struct {
 int x, y, z; 
} foo_t;

foo_t g;

into:
%"struct.<anonymous>" = type { i32, i32, i32 }
we now get:
%struct.foo_t = type { i32, i32, i32 }

This doesn't change the behavior of the compiler, but makes the IR much easier to read.




git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134969 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-12 05:53:08 +00:00
Chris Lattner 9cbe4f0ba0 clang side to match the LLVM IR type system rewrite patch.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134831 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-09 17:41:47 +00:00
Chris Lattner c5cbb909e8 Update to match mainline ConstantStruct::get API change. Also, use
ConvertType on InitListExprs as they are being converted.  This is
needed for a forthcoming patch, and improves the IR generated anyway
(see additional type names in testcases). 

This patch also converts a bunch of std::vector's in CGObjCMac to use
C arrays.  There are a ton more that should be converted as well.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133413 91177308-0d34-0410-b5e6-96231b3b80d8
2011-06-20 04:01:35 +00:00
Benjamin Kramer 0483a6fcf8 Only emit string initializers in-place if types match. Fixes PR9373.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126883 91177308-0d34-0410-b5e6-96231b3b80d8
2011-03-02 21:27:44 +00:00
Rafael Espindola 1257bc6ee7 Add unnamed_addr when creating artificial string globals. For example, in
static const char foo[] = "foo";
static const char *bar = "bar";

the global created to hold "bar" will have it, but foo will not.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123192 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-10 22:34:03 +00:00
John McCall 9c20fa9d46 A constant initializer never matches the type of the variable it's
initializing;  it at best matches the element type of the variable
it's initializing.  Fixes PR8073.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112992 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-03 18:58:50 +00:00
Daniel Dunbar a5728872c7 Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.
- This is designed to make it obvious that %clang_cc1 is a "test variable"
   which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it
   can be useful to redefine what gets run as 'clang -cc1' (for example, to set
   a default target).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91446 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-15 20:14:24 +00:00
Ken Dyck baf524d213 Use intptr_t from stdint.h (in freestanding mode) instead of redefining it here
with __INTPTR_TYPE__.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89609 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-22 18:29:06 +00:00
Eli Friedman f70b24e7fa Make __func__ and friends work correctly within the initializer for a static
local variable.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88766 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-14 08:37:13 +00:00
Eli Friedman 64241fc930 Obvious fix for PR5474.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88696 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-13 21:23:46 +00:00
John Thompson 0653066e2b Removed math.h include, as Windows math.h has a compile error.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84160 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-15 00:39:58 +00:00
Mike Stump e36803167e In VC++, the *printf functions put an extra "0" in the exponent part
of a floating point number.  This add regular expressions to account
for this.  Patch by John Thompson.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83581 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-08 21:57:41 +00:00
Benjamin Kramer d9097ffe6e FileCheckize test case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83244 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-02 10:32:51 +00:00
Anders Carlsson 2df96e7019 Don't update the struct alignment when adding fields to a packed struct. Fixes PR5118.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83235 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-02 04:52:12 +00:00
Anders Carlsson 31f2f9ced8 When building constant structs, check if the resulting LLVM struct will be bigger than the record layout size and use a packed struct if that's the case. Fixes PR5108.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83230 91177308-0d34-0410-b5e6-96231b3b80d8
2009-10-02 02:15:20 +00:00
Dan Gohman 1da83fafba Update this test to expect the "inbounds" keyword, which LLVM's constant
folder is now automatically adding.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81491 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-11 00:27:06 +00:00
Anders Carlsson abdad358b5 Enable the new struct type builder now that the constant struct builder works. (The old code will still be there until we know that everything works well.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77190 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-27 15:31:55 +00:00
Anders Carlsson 8dca3b3d09 Enable the new constant struct builder by default. The old code is still in place but will be removed shortly. The new struct builder works on big endian systems.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77185 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-27 05:54:15 +00:00
Eli Friedman c219a1579c Remove the -arch option from clang-cc: for all practical purposes, it's
redundant with -triple.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72108 91177308-0d34-0410-b5e6-96231b3b80d8
2009-05-19 11:12:40 +00:00
Eli Friedman 944af7156d Fix for PR4108: be a bit looser with the casts that we accept in
constant initializers.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70483 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-30 07:03:22 +00:00
Eli Friedman 48f9122dc6 Move where block-related variables are initialized so that block
types don't get generated when blocks aren't used.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67898 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-28 03:24:54 +00:00
Daniel Dunbar d7d5f0223b Rename clang to clang-cc.
Tests and drivers updated, still need to shuffle dirs.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67602 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-24 02:24:46 +00:00
Chris Lattner 6f877cd174 adjust to changes in the mainline llvm .ll printer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65745 91177308-0d34-0410-b5e6-96231b3b80d8
2009-03-01 00:59:19 +00:00
Daniel Dunbar e5731f8149 Allow constant initializers to reference their defining decl.
- PR3662.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65472 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-25 20:08:33 +00:00
Daniel Dunbar 5ec41c2423 Remove a FIXME; I was mistaken in believing gcc rejected this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65420 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-25 00:22:25 +00:00
Daniel Dunbar d01b669f26 Fix IRgen of constant expressions referring to external/static
variables.
 - PR3657.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65381 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-24 18:41:57 +00:00
Mike Stump 20733cd4fd Cleanp code with some recent suggestions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65285 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-22 13:27:11 +00:00
Daniel Dunbar 8d7d6e9a48 Force arch for these test cases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65252 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-21 23:45:41 +00:00
Daniel Dunbar 69ab26a862 Handle constant int -> ptr casts of lvalue results.
- PR3463 (again).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65133 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-20 18:22:23 +00:00
Daniel Dunbar dd2116462a Extend Evaluate() to fold (int) <pointer type>.
- PR3463, PR3398, <rdar://problem/6553401> crash on relocatable
   symbol addresses as constants in static locals.

 - There are many more scenarious we could handle (like arithmetic on
   such an int) but this is the main use case.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65074 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-19 22:24:01 +00:00
Daniel Dunbar 4087e24f73 Evaluate ==,!= for complex types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63280 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-29 06:43:41 +00:00
Daniel Dunbar a5fd07bbc5 Implement basic _Complex integer constant folding.
- Merged into single ComplexEvaluator, these share too much logic to
   be worth splitting for float/int (IMHO). Will split on request.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63248 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-28 22:24:07 +00:00
Anders Carlsson cd761cd1a7 Add test for PR2992.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59861 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-22 06:42:54 +00:00
Daniel Dunbar da8bf14c01 Fix const-init test case
- Use -verify and added expected warnings for EXTWARN change.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54342 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-05 06:30:41 +00:00
Eli Friedman bc5ed6ef52 Add codegen support for a few more kinds of initializer constant
expressions.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51677 91177308-0d34-0410-b5e6-96231b3b80d8
2008-05-29 11:22:45 +00:00
Eli Friedman cca196b553 Some const initializer tests for stuff I just committed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47442 91177308-0d34-0410-b5e6-96231b3b80d8
2008-02-21 18:07:36 +00:00