Commit Graph

4101 Commits

Author SHA1 Message Date
Vitaly Buka 17def21749 Revert "Give external linkage and mangling to lambdas inside inline variables and variable templates."
To fix: runtime error: load of value 15, which is not a valid value for type 'clang::LVComputationKind'

This reverts commit r313827.

llvm-svn: 313856
2017-09-21 02:51:56 +00:00
Matt Morehouse 4881a23ca8 [MSan] Disable sanitization for __sanitizer_dtor_callback.
Summary:
Eliminate unnecessary instrumentation at __sanitizer_dtor_callback
call sites.  Fixes https://github.com/google/sanitizers/issues/861.

Reviewers: eugenis, kcc

Reviewed By: eugenis

Subscribers: vitalybuka, llvm-commits, cfe-commits, hiraditya

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

llvm-svn: 313831
2017-09-20 22:53:08 +00:00
Richard Smith fb130c6084 Give external linkage and mangling to lambdas inside inline variables and variable templates.
This implements the proposed approach in https://github.com/itanium-cxx-abi/cxx-abi/issues/33

llvm-svn: 313827
2017-09-20 22:17:55 +00:00
Richard Smith 405e2dbf37 Implement C++ [basic.link]p8.
If a function or variable has a type with no linkage (and is not extern "C"),
any use of it requires a definition within the same translation unit; the idea
is that it is not possible to define the entity elsewhere, so any such use is
necessarily an error.

There is an exception, though: some types formally have no linkage but
nonetheless can be referenced from other translation units (for example, this
happens to anonymous structures defined within inline functions). For entities
with those types, we suppress the diagnostic except under -pedantic.

llvm-svn: 313729
2017-09-20 07:22:00 +00:00
Akira Hatanaka 30c93dba5b Revert "Add support for attribute 'noescape'."
This reverts commit r313722.

It looks like compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc cannot be
compiled because some of the functions declared in the file do not match
the ones in the SDK headers (which are annotated with 'noescape').

llvm-svn: 313725
2017-09-20 06:55:43 +00:00
Akira Hatanaka e974479fa5 Add support for attribute 'noescape'.
The attribute informs the compiler that the annotated pointer parameter
of a function cannot escape and enables IRGen to attach attribute
'nocapture' to parameters that are annotated with the attribute. That is
the only optimization that currently takes advantage of 'noescape', but
there are other optimizations that will be added later that improves
IRGen for ObjC blocks.

rdar://problem/19886775

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

llvm-svn: 313722
2017-09-20 06:32:45 +00:00
Akira Hatanaka 1b9418e163 Revert "Add support for attribute 'noescape'."
This reverts r313717.

I closed the wrong phabricator review.

llvm-svn: 313721
2017-09-20 06:27:39 +00:00
Akira Hatanaka fc587e6a57 Add support for attribute 'noescape'.
The attribute informs the compiler that the annotated pointer parameter
of a function cannot escape and enables IRGen to attach attribute
'nocapture' to parameters that are annotated with the attribute. That is
the only optimization that currently takes advantage of 'noescape', but
there are other optimizations that will be added later that improves
IRGen for ObjC blocks.

rdar://problem/19886775

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

llvm-svn: 313720
2017-09-20 06:22:51 +00:00
Adrian McCarthy d91bf3998f Mark static member functions as static in CodeViewDebug
Summary:
To improve CodeView quality for static member functions, we need to make the
static explicit.  In addition to a small change in LLVM's CodeViewDebug to
return the appropriate MethodKind, this requires a small change in Clang to
note the staticness in the debug info metadata.

Subscribers: aprantl, hiraditya

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

llvm-svn: 313192
2017-09-13 20:53:55 +00:00
Vedant Kumar 8e2baf96f0 Tighten up a test case. NFC.
llvm-svn: 313098
2017-09-13 00:04:36 +00:00
Vedant Kumar bb5d485cd3 [ubsan] Function Sanitizer: Don't require writable text segments
This change will make it possible to use -fsanitize=function on Darwin and
possibly on other platforms. It fixes an issue with the way RTTI is stored into
function prologue data.

On Darwin, addresses stored in prologue data can't require run-time fixups and
must be PC-relative. Run-time fixups are undesirable because they necessitate
writable text segments, which can lead to security issues. And absolute
addresses are undesirable because they break PIE mode.

The fix is to create a private global which points to the RTTI, and then to
encode a PC-relative reference to the global into prologue data.

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

llvm-svn: 313096
2017-09-13 00:04:35 +00:00
Bob Haarman c6c9b8fa1f [codeview] omit debug locations for nested exprs unless column info enabled
Summary:
Microsoft Visual Studio expects debug locations to correspond to
statements. We used to emit locations for expressions nested inside statements.
This would confuse the debugger, causing it to stop multiple times on the
same line and breaking the "step into specific" feature. This change inhibits
the emission of debug locations for nested expressions when emitting CodeView
debug information, unless column information is enabled.

Fixes PR34312.

Reviewers: rnk, zturner

Reviewed By: rnk

Subscribers: majnemer, echristo, aprantl, cfe-commits

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

llvm-svn: 312965
2017-09-11 22:11:57 +00:00
Daniel Jasper 7af729b3d2 Revert r312830: "Reinstall the patch "Use EmitPointerWithAlignment to get alignment information of the pointer used in atomic expr"."
This triggers llvm.org/PR31620 in several of our internal builds. I'll
forward reproduction instructions to the original author.

llvm-svn: 312897
2017-09-11 07:35:01 +00:00
Nuno Lopes 9211ceef2d clang fix for LLVM API change: isKnownNonNull -> isKnownNonZero
Differential Revision: https://reviews.llvm.org/D37628

llvm-svn: 312870
2017-09-09 18:25:36 +00:00
Wei Mi 015a484fe2 Reinstall the patch "Use EmitPointerWithAlignment to get alignment information of the pointer used in atomic expr".
This is to fix PR34347. EmitAtomicExpr now only uses alignment information from
Type, instead of Decl, so when the declaration of an atomic variable is marked
to have the alignment equal as its size, EmitAtomicExpr doesn't know about it and
will generate libcall instead of atomic op. The patch uses EmitPointerWithAlignment
to get the precise alignment information.

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

llvm-svn: 312830
2017-09-08 21:58:18 +00:00
Wei Mi 43092c0d00 Delete empty file test/CodeGenCXX/atomic-align.cpp after the revert at rL312805.
llvm-svn: 312810
2017-09-08 18:31:21 +00:00
Wei Mi c8c7cfc2bd Revert rL312801 since it generated some calls from libatomic and broke some tests.
llvm-svn: 312805
2017-09-08 18:10:13 +00:00
Wei Mi 3420ae489c Use EmitPointerWithAlignment to get alignment information of the pointer used in atomic expr.
This is to fix PR34347. EmitAtomicExpr now only uses alignment information from
Type, instead of Decl, so when the declaration of an atomic variable is marked
to have the alignment equal as its size, EmitAtomicExpr doesn't know about it and
will generate libcall instead of atomic op. The patch uses EmitPointerWithAlignment
to get the precise alignment information.

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

llvm-svn: 312801
2017-09-08 17:07:32 +00:00
Sjoerd Meijer cc623ad071 Recommit "Add _Float16 as a C/C++ source language type"
This is a recommit of r312781; in some build configurations
variable names are omitted, so changed the new regression
test accordingly.

llvm-svn: 312794
2017-09-08 15:15:00 +00:00
Sjoerd Meijer 9aeedde7ff Revert "Add _Float16 as a C/C++ source language type"
The clang-with-lto-ubuntu bot didn't like the new regression
test, revert while I investigate the issue.

llvm-svn: 312784
2017-09-08 10:20:52 +00:00
Sjoerd Meijer ab36f33db8 Add _Float16 as a C/C++ source language type
This adds _Float16 as a source language type, which is a 16-bit floating point
type defined in C11 extension ISO/IEC TS 18661-3.

In follow up patches documentation and more tests will be added.

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

llvm-svn: 312781
2017-09-08 09:42:32 +00:00
Benjamin Kramer 1a48ddb864 Fixing incorrectly capitalised regexps.
Patch by Sam Allen!

llvm-svn: 312710
2017-09-07 09:54:03 +00:00
Mehdi Amini 7cb1b304f8 Emit static constexpr member as available_externally definition
By exposing the constant initializer, the optimizer can fold many
of these constructs.

This is a recommit of r311857 that was reverted in r311898 because
an assert was hit when building Chromium.
We have to take into account that the GlobalVariable may be first
created with a different type than the initializer. This can
happen for example when the variable is a struct with tail padding
while the initializer does not have padding. In such case, the
variable needs to be destroyed an replaced with a new one with the
type of the initializer.

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

llvm-svn: 312512
2017-09-05 03:58:35 +00:00
Martin Storsjo c6c5af75f2 Reland r312224 - [ItaniumCXXABI] Always use linkonce_odr linkage for RTTI data on MinGW
This fixes cases where dynamic classes produced RTTI data with
external linkage, producing linker errors about duplicate symbols.

This touches code close to what was changed in SVN r244266, but
this change doesn't break the tests added in that revision.

The previous version had missed to update CodeGenCXX/virt-dtor-key.cpp,
which had a behaviour change only when running the testsuite on windows.

Differential revision: https://reviews.llvm.org/D37327

llvm-svn: 312306
2017-09-01 06:41:55 +00:00
Martin Storsjo 7bfb697259 Revert r312224: "[ItaniumCXXABI] Always use linkonce_odr linkage for RTTI data on MinGW"
Breaks on buildbot:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/4548/steps/test-check-all/logs/stdio

The test in CodeGenCXX/virt-dtor-key.cpp tests using %itanium_abi_triple;
on non-windows platforms, this resolves to the current platform triple
(where there was no behaviour change), while on windows, it resolves to
a mingw triple (where the behaviour was intentionally changed).

llvm-svn: 312229
2017-08-31 09:46:27 +00:00
Martin Storsjo cd7d552e04 [ItaniumCXXABI] Always use linkonce_odr linkage for RTTI data on MinGW
This fixes cases where dynamic classes produced RTTI data with
external linkage, producing linker errors about duplicate symbols.

This touches code close to what was changed in SVN r244266, but
this change doesn't break the tests added in that revision.

Differential revision: https://reviews.llvm.org/D37206

llvm-svn: 312224
2017-08-31 08:29:59 +00:00
Adrian Prantl 58377b4a99 Test-case golfing.
llvm-svn: 312175
2017-08-30 21:31:16 +00:00
Adrian Prantl 9e83fb0838 Adapt testcases to LLVM change r312144 in DIGlobalVariableExpression
llvm-svn: 312148
2017-08-30 18:22:23 +00:00
Reid Kleckner dd6fc83cb4 [ms] Fix vbtable index for covariant overrides of vbase methods
Overriding a method from a virtual base with a covariant return type
consumes a slot from the vftable in the virtual base. This can make it
impossible to implement certain diamond inheritance hierarchies, but we
have to follow along for compatibility in the simple cases.

This patch only affects our vtable dumper and member pointer function
mangling, since all other callers of getMethodVFTableLocation seem to
recompute VBTableIndex instead of using the one in the method location.

Patch by David Majnemer

llvm-svn: 312017
2017-08-29 17:40:04 +00:00
Hans Wennborg edd66ab9dc Revert r311857 "Emit static constexpr member as available_externally definition"
It caused PR759744.

> Emit static constexpr member as available_externally definition
>
> By exposing the constant initializer, the optimizer can fold many
> of these constructs.
>
> Differential Revision: https://reviews.llvm.org/D34992

llvm-svn: 311898
2017-08-28 17:53:00 +00:00
Mehdi Amini f23847604b Emit static constexpr member as available_externally definition
By exposing the constant initializer, the optimizer can fold many
of these constructs.

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

llvm-svn: 311857
2017-08-27 20:24:09 +00:00
Richard Smith f667ad5f98 Add flag to request Clang is ABI-compatible with older versions of itself
This patch adds a flag -fclang-abi-compat that can be used to request that
Clang attempts to be ABI-compatible with some older version of itself.

This is provided on a best-effort basis; right now, this can be used to undo
the ABI change in r310401, reverting Clang to its prior C++ ABI for pass/return
by value of class types affected by that change, and to undo the ABI change in
r262688, reverting Clang to using integer registers rather than SSE registers
for passing <1 x long long> vectors. The intent is that we will maintain this
backwards compatibility path as we make ABI-breaking fixes in future.

The reversion to the old behavior for r310401 is also applied to the PS4 target
since that change is not part of its platform ABI (which is essentially to do
whatever Clang 3.2 did).

llvm-svn: 311823
2017-08-26 01:04:35 +00:00
Alex Lorenz 6cc8317c38 [IRGen] Evaluate constant static variables referenced through member
expressions

C++ allows us to reference static variables through member expressions. Prior to
this commit, non-integer static variables that were referenced using a member
expression were always emitted using lvalue loads. The old behaviour introduced
an inconsistency between regular uses of static variables and member expressions
uses. For example, the following program compiled and linked successfully:

struct Foo {
   constexpr static const char *name = "foo";
};
int main() {
  return Foo::name[0] == 'f';
}

but this program failed to link because "Foo::name" wasn't found:

struct Foo {
   constexpr static const char *name = "foo";
};
int main() {
  Foo f;
  return f.name[0] == 'f';
}

This commit ensures that constant static variables referenced through member
expressions are emitted in the same way as ordinary static variable references.

rdar://33942261

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

llvm-svn: 311772
2017-08-25 10:07:00 +00:00
Richard Smith 376c28e296 [ubsan] PR34266: When sanitizing the 'this' value for a member function that happens to be a lambda call operator, use the lambda's 'this' pointer, not the captured enclosing 'this' pointer (if any).
Do not sanitize the 'this' pointer of a member call operator for a lambda with
no capture-default, since that call operator can legitimately be called with a
null this pointer from the static invoker function. Any actual call with a null
this pointer should still be caught in the caller (if it is being sanitized).

This reinstates r311589 (reverted in r311680) with the above fix.

llvm-svn: 311695
2017-08-24 20:10:33 +00:00
Adrian Prantl 1b6d8713e4 Revert "[ubsan] PR34266: When sanitizing the 'this' value for a member function that happens to be a lambda call operator, use the lambda's 'this' pointer, not the captured enclosing 'this' pointer (if any)."
This reverts commit r311589 because of bot breakage.
http://green.lab.llvm.org/green/job/clang-stage2-cmake-RgSan_check/4115/consoleFull#15752874848254eaf0-7326-4999-85b0-388101f2d404.

llvm-svn: 311680
2017-08-24 18:18:24 +00:00
Coby Tayree cfa3810aa0 Fixups to FE tests affected by D36793
Differential Revision: https://reviews.llvm.org/D36794

llvm-svn: 311640
2017-08-24 08:47:26 +00:00
Richard Smith 39eca9b95a Fix mangling for dependent "type { expr-list }" expressions, and add mangling for designated initializers matching recent cxx-abi-dev discussion.
llvm-svn: 311612
2017-08-23 22:12:08 +00:00
Adrian Prantl 8040a215c9 Fix a bug in CGDebugInfo::EmitInlineFunctionStart causing DILocations to be
parented in function declarations.

Fixes PR33997.
https://bugs.llvm.org/show_bug.cgi?id=33997

llvm-svn: 311601
2017-08-23 21:24:12 +00:00
Reid Kleckner 6d353348e5 Parse and print DIExpressions inline to ease IR and MIR testing
Summary:
Most DIExpressions are empty or very simple. When they are complex, they
tend to be unique, so checking them inline is reasonable.

This also avoids the need for CodeGen passes to append to the
llvm.dbg.mir named md node.

See also PR22780, for making DIExpression not be an MDNode.

Reviewers: aprantl, dexonsmith, dblaikie

Subscribers: qcolombet, javed.absar, eraman, hiraditya, llvm-commits

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

llvm-svn: 311594
2017-08-23 20:31:27 +00:00
Richard Smith e3a5e8f03d [ubsan] PR34266: When sanitizing the 'this' value for a member function that happens to be a lambda call operator, use the lambda's 'this' pointer, not the captured enclosing 'this' pointer (if any).
llvm-svn: 311589
2017-08-23 19:39:04 +00:00
Richard Smith 96cd671cd6 PR19668, PR23034: Fix handling of move constructors and deleted copy
constructors when deciding whether classes should be passed indirectly.

This fixes ABI differences between Clang and GCC:

 * Previously, Clang ignored the move constructor when making this
   determination. It now takes the move constructor into account, per
   https://github.com/itanium-cxx-abi/cxx-abi/pull/17 (this change may
   seem recent, but the ABI change was agreed on the Itanium C++ ABI
   list a long time ago).

 * Previously, Clang's behavior when the copy constructor was deleted
   was unstable -- depending on whether the lazy declaration of the
   copy constructor had been triggered, you might get different behavior.
   We now eagerly declare the copy constructor whenever its deletedness
   is unclear, and ignore deleted copy/move constructors when looking for
   a trivial such constructor.

This also fixes an ABI difference between Clang and MSVC:

 * If the copy constructor would be implicitly deleted (but has not been
   lazily declared yet), for instance because the class has an rvalue
   reference member, we would pass it directly. We now pass such a class
   indirectly, matching MSVC.

Based on a patch by Vassil Vassilev, which was based on a patch by Bernd
Schmidt, which was based on a patch by Reid Kleckner!

This is a re-commit of r310401, which was reverted in r310464 due to ARM
failures (which should now be fixed).

llvm-svn: 310983
2017-08-16 01:49:53 +00:00
Richard Smith 6c716116df PR34163: Don't cache an incorrect key function for a class if queried between
the class becoming complete and its inline methods being parsed.

This replaces the hack of using the "late parsed template" flag to track member
functions with bodies we've not parsed yet; instead we now use the "will have
body" flag, which carries the desired implication that the function declaration
*is* a definition, and that we've just not parsed its body yet.

llvm-svn: 310776
2017-08-12 01:46:03 +00:00
Diana Picus 0c9f193acc Revert "PR19668, PR23034: Fix handling of move constructors and deleted copy constructors when deciding whether classes should be passed indirectly."
This reverts commit r310401 because it seems to have broken some ARM
bot(s).

llvm-svn: 310464
2017-08-09 12:22:25 +00:00
George Burgess IV 2fd1ff81b4 Attempt #2 to appease buildbots
"error: unable to create target: 'No available targets are compatible
with this triple.'"

llvm-svn: 310445
2017-08-09 06:07:08 +00:00
George Burgess IV 8b928feeb4 Attempt to appease msc buildbot
It was timing out on this test, but for reasons unrelated to the
specific bug it was testing for. Randomly breaking in gdb with `clang
-target i686-windows -fmsc-version=1700` reveals *many* frames from
MicrosoftCXXNameMangler. So, it would seem that some caching is needed
there, as well...

Fingers crossed that specifying a triple is sufficient to work around
this.

llvm-svn: 310444
2017-08-09 05:20:05 +00:00
George Burgess IV 35cb4f84a4 [AST] Cache intermediate visibility/linkage results
This is a follow-up to r310436 with actual functional changes. Please
see that commit message for a description of why a cache is appearing
here.

Suggestions for less-bad ways of testing this are appreciated. :)

This fixes PR29160.

llvm-svn: 310437
2017-08-09 04:12:17 +00:00
Tim Northover 0241637c0e Sema: disable implicit conversion from _Complex to real types in C++.
Converting a _Complex type to a real one simply discards the imaginary part.
This can easily lead to loss of information so for safety (and GCC
compatibility) this patch disallows that when the conversion would be implicit.

The one exception is bool, which actually compares both real and imaginary
parts and so is safe.

llvm-svn: 310427
2017-08-08 23:18:05 +00:00
Reid Kleckner e2e82061f9 [codeview] Emit nested enums and typedefs from classes
Previously we limited ourselves to only emitting nested classes, but we
need other kinds of types as well.

This fixes the Visual Studio STL visualizers, so that users can
visualize std::string and other objects.

llvm-svn: 310410
2017-08-08 20:30:14 +00:00
Richard Smith f1a425edb7 PR19668, PR23034: Fix handling of move constructors and deleted copy
constructors when deciding whether classes should be passed indirectly.

This fixes ABI differences between Clang and GCC:

 * Previously, Clang ignored the move constructor when making this
   determination. It now takes the move constructor into account, per
   https://github.com/itanium-cxx-abi/cxx-abi/pull/17 (this change may
   seem recent, but the ABI change was agreed on the Itanium C++ ABI
   list a long time ago).

 * Previously, Clang's behavior when the copy constructor was deleted
   was unstable -- depending on whether the lazy declaration of the
   copy constructor had been triggered, you might get different behavior.
   We now eagerly declare the copy constructor whenever its deletedness
   is unclear, and ignore deleted copy/move constructors when looking for
   a trivial such constructor.

This also fixes an ABI difference between Clang and MSVC:

 * If the copy constructor would be implicitly deleted (but has not been
   lazily declared yet), for instance because the class has an rvalue
   reference member, we would pass it directly. We now pass such a class
   indirectly, matching MSVC.

llvm-svn: 310401
2017-08-08 19:12:28 +00:00
Reid Kleckner 59d1220cfd [codeview] Fix class name formatting
In particular, removes spaces between template arguments of class
templates to better match VS type visualizers.

llvm-svn: 310331
2017-08-08 01:33:53 +00:00
Vedant Kumar a0c3671b20 [ubsan] Have -fsanitize=vptr emit a null check if -fsanitize=null isn't available
In r309007, I made -fsanitize=null a hard prerequisite for -fsanitize=vptr. I
did not see the need for the two checks to have separate null checking logic
for the same pointer. I expected the two checks to either always be enabled
together, or to be mutually compatible.

In the mailing list discussion re: r309007 it became clear that that isn't the
case. If a codebase is -fsanitize=vptr clean but not -fsanitize=null clean,
it's useful to have -fsanitize=vptr emit its own null check. That's what this
patch does: with it, -fsanitize=vptr can be used without -fsanitize=null.

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

llvm-svn: 309846
2017-08-02 18:10:31 +00:00
Yan Wang d79f3f630f [clang] Change the condition of unnecessary packed warning
Summary:
Change the condition of this unnecessary packed warning. The packed is unnecessary when
1. the alignment of the struct/class won't alter.
2. the size is unchanged.
3. the offset of each field is the same.

Remove all field-level warning.

Reviewers: chh, akyrtzi, rtrieu

Reviewed By: chh

Subscribers: rsmith, srhines, cfe-commits, xazax.hun

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

llvm-svn: 309750
2017-08-01 21:41:39 +00:00
Peter Collingbourne 396943a75b Re-apply r309622 with a fix for MSVC.
Patch by Vlad Tsyrklevich!

llvm-svn: 309635
2017-07-31 22:35:33 +00:00
Peter Collingbourne ab65b0dba1 Revert r309622, "Fix logic for generating llvm.type.test()s"
Caused a bot test failure:
http://bb.pgr.jp/builders/test-clang-msc-x64-on-i686-linux-RA/builds/5325

llvm-svn: 309624
2017-07-31 20:53:16 +00:00
Peter Collingbourne 8867b216dc Fix logic for generating llvm.type.test()s
CodeGenFunction::EmitTypeMetadataCodeForVCall() could output an
llvm.assume(llvm.type.test())when CFI was enabled, optimizing out the
vcall check. This case was only reached when: 1) CFI-vcall was enabled,
2) -fwhole-program-tables was specified, and 3)
-fno-sanitize-trap=cfi-vcall was specified.

Patch by Vlad Tsyrklevich!

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

llvm-svn: 309622
2017-07-31 20:45:14 +00:00
Akira Hatanaka 7ce6ed49e8 Update comment in test case after r309308.
llvm-svn: 309352
2017-07-28 01:58:14 +00:00
Akira Hatanaka c47fcf0ae5 Revert r264998 and r265035.
r303175 made changes to have __cxa_allocate_exception return a 16-byte
aligned pointer, so it's no longer necessary to specify a lower
alignment (8-bytes) for exception objects on Darwin.

rdar://problem/32363695

llvm-svn: 309308
2017-07-27 18:52:44 +00:00
Richard Smith ae8d62c9c5 Add branch weights to branches for static initializers.
The initializer for a static local variable cannot be hot, because it runs at
most once per program. That's not quite the same thing as having a low branch
probability, but under the assumption that the function is invoked many times,
modeling this as a branch probability seems reasonable.

For TLS variables, the situation is less clear, since the initialization side
of the branch can run multiple times in a program execution, but we still
expect initialization to be rare relative to non-initialization uses. It would
seem worthwhile to add a PGO counter along this path to make this estimation
more accurate in future.

For globals with guarded initialization, we don't yet apply any branch weights.
Due to our use of COMDATs, the guard will be reached exactly once per DSO, but
we have no idea how many DSOs will define the variable.

llvm-svn: 309195
2017-07-26 22:01:09 +00:00
David Majnemer 8f94a23505 [CodeGen] Correctly model std::byte's aliasing properties
std::byte, when defined as an enum, needs to be given special treatment
with regards to its aliasing properties. An array of std::byte is
allowed to be used as storage for other types.

This fixes PR33916.

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

llvm-svn: 309058
2017-07-25 23:33:58 +00:00
Vedant Kumar bbc953fed4 [ubsan] Null-check pointers in -fsanitize=vptr (PR33881)
The instrumentation generated by -fsanitize=vptr does not null check a
user pointer before loading from it. This causes crashes in the face of
UB member calls (this=nullptr), i.e it's causing user programs to crash
only after UBSan is turned on.

The fix is to make run-time null checking a prerequisite for enabling
-fsanitize=vptr, and to then teach UBSan to reuse these run-time null
checks to make -fsanitize=vptr safe.

Testing: check-clang, check-ubsan, a stage2 ubsan-enabled build

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

https://bugs.llvm.org/show_bug.cgi?id=33881

llvm-svn: 309007
2017-07-25 19:34:23 +00:00
Eric Christopher cf94152f27 Revert "This patch enables the usage of constant Enum identifiers within Microsoft style inline assembly statements." as it is causing msan failures.
This reverts commits r308985 and r308965

llvm-svn: 309004
2017-07-25 19:17:32 +00:00
Matan Haroush b4b8d10355 This patch enables the usage of constant Enum identifiers within Microsoft style inline assembly statements.
Differential Revision:
https://reviews.llvm.org/D33277
https://reviews.llvm.org/D33278

llvm-svn: 308965
2017-07-25 10:43:43 +00:00
Shoaib Meenai cef66e5281 [CodeGen] Propagate dllexport to thunks
Under Windows Itanium, we need to export virtual and non-virtual thunks
if the functions being thunked are exported. These thunks would
previously inherit their dllexport attribute from the declaration, but
r298330 changed declarations to not have dllexport attributes. We
therefore need to add the dllexport attribute to the definition
ourselves now. This is consistent with MinGW GCC's behavior.

This redoes r306770 but limits the logic to Itanium. MicrosoftCXXABI's
setThunkLinkage ensures that thunks aren't exported under that ABI, so
I'm handling this in ItaniumCXXABI's setThunkLinkage for symmetry.

We need to export these thunks because they can be referenced outside
the library they're defined in. For example, if a child class without a
key function inherits from a parent class with a key function, the
parent's thunks will only be defined in the library with the key
function, but the construction vtable for the parent in the child might
be emitted outside the library (since the child doesn't have a key
function), and it needs to reference the parent's thunks.

We don't need to mark these thunks as imported since any references to
them will occur in data, so the compiler can't generate the IAT load
sequence anyway. Instead, we rely on the linker generating import thunks
for the thunks.

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

llvm-svn: 308899
2017-07-24 17:16:27 +00:00
Erich Keane de1b2a9375 Complex Long Double classification In RegCall calling convention
This change is part of the RegCall calling convention support for LLVM. 
Existing RegCall implementation was extended to include correct handling of 
Complex Long Double type. Complex long double types should be returned/passed 
in memory and not register stack. This patch implements this behavior.

Patch by: eandrews

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

llvm-svn: 308769
2017-07-21 18:50:36 +00:00
Adrian Prantl 5649b0e8c9 Update for LLVM IR metadata changes (DIImportedEntity now needs a DIFile).
<rdar://problem/33357889>
https://bugs.llvm.org/show_bug.cgi?id=33822

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

llvm-svn: 308399
2017-07-19 00:09:58 +00:00
Yaxun Liu 9d33fb1bc5 CodeGen: Insert addr space cast for automatic/temp var at right position
The uses of alloca may be in different blocks other than the block containing the alloca.
Therefore if the alloca addr space is non-zero and it needs to be casted to default
address space, the cast needs to be inserted in the same BB as the alloca insted of
the current builder insert point since the current insert point may be in a different BB.

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

llvm-svn: 308313
2017-07-18 14:46:03 +00:00
Mandeep Singh Grang a16b27cfda [clang] Remove redundant check-prefix=CHECK from tests. NFC.
Reviewers: t.p.northover, mstorsjo, rsmith, mcrosier

Reviewed By: mstorsjo, mcrosier

Subscribers: mcrosier, javed.absar, cfe-commits

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

llvm-svn: 308192
2017-07-17 17:31:44 +00:00
Akira Hatanaka 2246167362 [Sema] Mark a virtual CXXMethodDecl as used if a call to it can be
devirtualized.

The code to detect devirtualized calls is already in IRGen, so move the
code to lib/AST and make it a shared utility between Sema and IRGen.

This commit fixes a linkage error I was seeing when compiling the
following code:

$ cat test1.cpp
struct Base {
  virtual void operator()() {}
};

template<class T>
struct Derived final : Base {
  void operator()() override {}
};

Derived<int> *d;

int main() {
  if (d)
    (*d)();
  return 0;
}

rdar://problem/33195657

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

llvm-svn: 307883
2017-07-13 06:08:27 +00:00
Reid Kleckner ec97f3cb76 Add missing dllimport member pointer template argument test from r307446
llvm-svn: 307670
2017-07-11 16:18:05 +00:00
Yaxun Liu cbf647cc3a CodeGen: Fix address space of global variable
Certain targets (e.g. amdgcn) require global variable to stay in global or constant address
space. In C or C++ global variables are emitted in the default (generic) address space.
This patch introduces virtual functions TargetCodeGenInfo::getGlobalVarAddressSpace
and TargetInfo::getConstantAddressSpace to handle this in a general approach.

It only affects IR generated for amdgcn target.

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

llvm-svn: 307470
2017-07-08 13:24:52 +00:00
Yaxun Liu 25d1b4341f [AMDGPU] Fix size and alignment of size_t and pointer types
Differential Revision: https://reviews.llvm.org/D34995

llvm-svn: 307121
2017-07-05 04:58:24 +00:00
Shoaib Meenai 61118e7ecd [CodeGen] Check key function for typeinfo import
If the imported class does not have a key function, we should emit its
typeinfo locally instead of attempting to import it.

llvm-svn: 307052
2017-07-04 01:02:19 +00:00
Reid Kleckner 1898045ba5 [MS] Test that deleting destructor thunks are not exported
The MSVC linker emits the LNK4102 warning if they are.

llvm-svn: 306836
2017-06-30 16:12:14 +00:00
Reid Kleckner ec782b70d2 Revert "[CodeGen] Propagate dllexport to thunks"
This reverts r306770, it causes LNK4102 warnings in MSVC builds.

llvm-svn: 306835
2017-06-30 16:11:49 +00:00
Shoaib Meenai a2222fa1d2 [CodeGen] Propagate dllexport to thunks
Under Windows Itanium, we need to export virtual and non-virtual thunks
if the functions being thunked are exported. These thunks would
previously inherit their dllexport attribute from the declaration, but
r298330 changed declarations to not have dllexport attributes. We
therefore need to add the dllexport attribute to the definition
ourselves now.

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

llvm-svn: 306770
2017-06-30 00:07:54 +00:00
George Burgess IV d3cf025ae2 [Sema] Allow unmarked overloadable functions.
This patch extends the `overloadable` attribute to allow for one
function with a given name to not be marked with the `overloadable`
attribute. The overload without the `overloadable` attribute will not
have its name mangled.

So, the following code is now legal:

  void foo(void) __attribute__((overloadable));
  void foo(int);
  void foo(float) __attribute__((overloadable));

In addition, this patch fixes a bug where we'd accept code with
`__attribute__((overloadable))` inconsistently applied. In other words,
we used to accept:

  void foo(void);
  void foo(void) __attribute__((overloadable));

But we will do this no longer, since it defeats the original purpose of
requiring `__attribute__((overloadable))` on all redeclarations of a
function.

This breakage seems to not be an issue in practice, since the only code
I could find that had this pattern often looked like:

  void foo(void);
  void foo(void) __attribute__((overloadable)) __asm__("foo");
  void foo(int) __attribute__((overloadable));

...Which can now be simplified by simply removing the asm label and
overloadable attribute from the redeclaration of `void foo(void);`

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

llvm-svn: 306467
2017-06-27 21:31:31 +00:00
Saleem Abdulrasool 3cc6d0bc67 AST: enhance mangling for blocks with MS ABI
When generating the decorated name for a static variable inside a
BlockDecl, construct a scope for the block invocation function that
homes the parameter. This allows for arbitrary nesting of the blocks
even if the variables are shadowed. Furthermore, using this for the name
allows for undname to properly undecorated the name for us. It shows up
as the synthetic __block_invocation function that the compiler emitted
in the local scope.

llvm-svn: 306347
2017-06-26 23:28:42 +00:00
Reid Kleckner 33d501f7d1 Revert "[MS] Don't statically initialize dllimport member function pointers"
This reverts commit r306137. It has problems on code like this:

  struct __declspec(dllimport) Foo {
    int a;
    int get_a() { return a; }
  };
  template <int (Foo::*Getter)()> struct HasValue {
    int operator()(Foo *p) { return (p->*Getter)(); }
  };
  int main() {
    Foo f;
    f.a = 3;
    int x = HasValue<&Foo::get_a>()(&f);
  }

llvm-svn: 306175
2017-06-23 22:39:01 +00:00
Reid Kleckner 9c980cb502 [MS] Don't statically initialize dllimport member function pointers
We were already applying the same rules to dllimport function pointers.
David Majnemer added that logic back in r211677 to fix PR20130.  We
failed to extend that logic to non-virtual member function pointers,
which are basically function pointers in a struct with some extra
offsets.

Fixes PR33570.

llvm-svn: 306137
2017-06-23 18:29:13 +00:00
Yaxun Liu 84744c152a CodeGen: Cast temporary variable to proper address space
In C++ all variables are in default address space. Previously change has been
made to cast automatic variables to default address space. However that is
not sufficient since all temporary variables need to be casted to default
address space.

This patch casts all temporary variables to default address space except those
for passing indirect arguments since they are only used for load/store.

This patch only affects target having non-zero alloca address space.

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

llvm-svn: 305711
2017-06-19 17:03:41 +00:00
Peter Collingbourne 89061b2224 IR: Replace the "Linker Options" module flag with "llvm.linker.options" named metadata.
The new metadata is easier to manipulate than module flags.

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

llvm-svn: 305227
2017-06-12 20:10:48 +00:00
Alexey Bataev 56223237b0 [DebugInfo] Add kind of ImplicitParamDecl for emission of FlagObjectPointer.
Summary:
If the first parameter of the function is the ImplicitParamDecl, codegen
automatically marks it as an implicit argument with `this` or `self`
pointer. Added internal kind of the ImplicitParamDecl to separate
'this', 'self', 'vtt' and other implicit parameters from other kind of
parameters.

Reviewers: rjmccall, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 305075
2017-06-09 13:40:18 +00:00
Javed Absar 2a67c9ee39 Add support for #pragma clang section
This patch provides a means to specify section-names for global variables, 
functions and static variables, using #pragma directives. 
This feature is only defined to work sensibly for ELF targets.
One can specify section names as:
#pragma clang section bss="myBSS" data="myData" rodata="myRodata" text="myText"
One can "unspecify" a section name with empty string e.g.
#pragma clang section bss="" data="" text="" rodata=""

Reviewers: Roger Ferrer, Jonathan Roelofs, Reid Kleckner
Differential Revision: https://reviews.llvm.org/D33412

llvm-svn: 304705
2017-06-05 10:11:57 +00:00
NAKAMURA Takumi c226303d3e clang/test/CodeGenCXX/unaligned-member-qualifier.cpp: Satisfy x86_thiscallcc.
llvm-svn: 304535
2017-06-02 09:53:05 +00:00
Roger Ferrer Ibanez b4aef7963e Remove file that I forgot to remove as part of rL304523
llvm-svn: 304524
2017-06-02 07:21:27 +00:00
Roger Ferrer Ibanez fd9384a229 Mangle __unaligned in Itanium ABI
__unaligned is not currently mangled in any way in the Itanium ABI. This causes
failures when using -fms-extensions and C++ in targets using Itanium ABI.

As suggested by @rsmith the simplest thing to do here is actually mangle the
qualifier as a vendor extension.

This patch also removes the change done in D31976 and updates its test to the
new reality.

This fixes
  https://bugs.llvm.org/show_bug.cgi?id=33080
  https://bugs.llvm.org/show_bug.cgi?id=33178

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

llvm-svn: 304523
2017-06-02 07:14:34 +00:00
Piotr Padlewski 4446e508ed Fixed broken test (strict-vtable-pointers)
llvm-svn: 304455
2017-06-01 19:08:05 +00:00
Piotr Padlewski c1d26062f7 Emit invariant.group.barrier when using union field
Summary:
We need to emit barrier if the union field
is CXXRecordDecl because it might have vptrs. The testcode
was wrongly devirtualized. It also proves that having different
groups for different dynamic types is not sufficient.

Reviewers: rjmccall, rsmith, mehdi_amini

Subscribers: amharc, cfe-commits

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

llvm-svn: 304448
2017-06-01 18:39:34 +00:00
Piotr Padlewski d3b1cbd17f Emit available_externally vtables opportunistically
Summary:
We can emit vtable definition having inline function
if they are all emitted.

Reviewers: rjmccall, rsmith

Subscribers: cfe-commits

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

llvm-svn: 304394
2017-06-01 08:04:05 +00:00
Reid Kleckner 0449316ea0 Don't try to spill static allocas when emitting expr cleanups with branches
Credit goes to Gor Nishanov for putting together the fix in
https://reviews.llvm.org/D33733!

This patch is essentially me patching it locally and writing some test
cases to convince myself that it was necessary for GNU statement
expressions with branches as well as coroutines. I'll ask Gor to land
his patch with just the coroutines test.

During LValue expression evaluation, references can be bound to
anything, really: call results, aggregate temporaries, local variables,
global variables, or indirect arguments. We really only want to spill
instructions that were emitted as part of expression evaluation, and
static allocas are not that.

llvm-svn: 304335
2017-05-31 19:59:41 +00:00
Mehdi Amini 6aa9e9b41a IRGen: Add optnone attribute on function during O0
Amongst other, this will help LTO to correctly handle/honor files
compiled with O0, helping debugging failures.
It also seems in line with how we handle other options, like how
-fnoinline adds the appropriate attribute as well.

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

llvm-svn: 304127
2017-05-29 05:38:20 +00:00
Krzysztof Parzyszek 5960a57ef7 [CodeGen] Pessimize aliasing for member unions (and may-alias) objects
Use the TBAA info of the omnipotent char for these objects.

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

llvm-svn: 303851
2017-05-25 12:55:47 +00:00
Matthias Braun a451953224 CodeGenModule: Always output wchar_size, check LLVM assumptions.
Re-commit r303463 now that LLVM is fixed and adjust some lit tests.

llvm::TargetLibraryInfo needs to know the size of wchar_t to work on
functions like `wcslen`. This patch changes clang to always emit the
wchar_size module flag (it would only do so for ARM previously).
This also adds an `assert()` to ensure the LLVM defaults based on the
target triple are in sync with clang.

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

llvm-svn: 303478
2017-05-20 01:29:55 +00:00
Yaxun Liu 6d96f16347 CodeGen: Cast alloca to expected address space
Alloca always returns a pointer in alloca address space, which may
be different from the type defined by the language. For example,
in C++ the auto variables are in the default address space. Therefore
cast alloca to the expected address space when necessary.

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

llvm-svn: 303370
2017-05-18 18:51:09 +00:00
Adrian Prantl 6fc8875739 Fix scope of namespaced DISubprograms when the function definition is out-of-line.
This fixes a regression introduced in r302915.

Using the lexical decl context is not necessary here for what r302915
wast trying to achieve. Not canonicalizing the NamespaceDecl in
getOrCreateNamespace is suficient.

rdar://problem/29339538

llvm-svn: 303222
2017-05-16 23:46:10 +00:00
Faisal Vali 718b7457e8 Silence buildbots by tweaking an IR codegen test to be less specific w register names.
llvm-svn: 303030
2017-05-15 02:56:02 +00:00
Faisal Vali c3dbd7f270 [NFC] Remove some comments (IR aid) from a test file erroneous committed in r303026
llvm-svn: 303027
2017-05-15 01:54:02 +00:00
Faisal Vali 1ca2d9679b Fix PR32933: crash on lambda capture of VLA
https://bugs.llvm.org/show_bug.cgi?id=32933

Turns out clang wasn't really handling vla's (*) in C++11's for-range entirely correctly. 

For e.g. This would lead to generation of buggy IR:

  void foo(int b) {
    int vla[b];
    b = -1;  // This store would affect the '__end = vla + b'
    for (int &c : vla) 
      c = 0;
  }

Additionally, code-gen would get confused when VLA's were reference-captured by lambdas, and then used in a for-range, which would result in an attempt to generate IR for '__end = vla + b' within the lambda's body - without any capture of 'b' - hence the assertion.

This patch modifies clang, so that for VLA's it translates the end pointer approximately into:
  __end = __begin + sizeof(vla)/sizeof(vla->getElementType())

As opposed to the __end = __begin + b;

I considered passing a magic value into codegen - or having codegen special case the '__end' variable when it referred to a variably-modified type, but I decided against that approach, because it smelled like I would be increasing a complicated form of coupling, that I think would be even harder to maintain than the above approach (which can easily be optimized (-O1) to refer to the run-time bound that was calculated upon array's creation or copied into the lambda's closure object).


(*) why oh why gcc would you enable this by default?! ;)

llvm-svn: 303026
2017-05-15 01:49:19 +00:00
Krzysztof Parzyszek 408b272a00 [Hexagon] Make sure to pass empty struct arguments with nontrivial ctors
Thanks to Richard Smith for the suggested fix.

This fixes llvm.org/PR33009

llvm-svn: 302895
2017-05-12 13:18:07 +00:00
Richard Smith 74df05471e XFAIL this test for Hexagon.
It's failing due to Hexagon calling convention lowering being broken (empty
structs are not passed even if they have nontrivial destructors / copy ctors).

llvm-svn: 302825
2017-05-11 21:18:27 +00:00
Richard Smith 2cbd1f6c9f Work around different -std= default for PS4 target.
llvm-svn: 302818
2017-05-11 19:17:54 +00:00
Richard Smith 722363727d PR22877: When constructing an array via a constructor with a default argument
in list-initialization, run cleanups for the default argument after each
iteration of the initialization loop.

We previously only ran the destructor for any temporary once, at the end of the
complete loop, rather than once per iteration!

Re-commit of r302750, reverted in r302776.

llvm-svn: 302817
2017-05-11 18:58:24 +00:00
Diana Picus 1f53d03a15 Revert "PR22877: When constructing an array via a constructor with a default argument in list-initialization, run cleanups for the default argument after each iteration of the initialization loop."
Revert "clang/test/CodeGenCXX/array-default-argument.cpp: Satisfy targets that have x86_thiscallcc."

This reverts commit r302750 and its fixup r302757 because the test is
still breaking on some of the ARM bots.

array-default-argument.cpp:20:12: error: expected string not found in input
 // CHECK: {{call|invoke}}[[THISCALL:( x86_thiscallcc)?]] void @_ZN1AC1Ev([[TEMPORARY:.*]])
           ^
<stdin>:18:1: note: scanning from here
arrayctor.loop: ; preds = %arrayctor.loop, %entry
^
<stdin>:28:2: note: possible intended match here
 call void @_Z1fv()
 ^

--

llvm-svn: 302776
2017-05-11 08:10:41 +00:00
NAKAMURA Takumi 26b3eec258 clang/test/CodeGenCXX/array-default-argument.cpp: Satisfy targets that have x86_thiscallcc.
llvm-svn: 302757
2017-05-11 02:39:30 +00:00
Richard Smith 97a2cdbff3 PR22877: When constructing an array via a constructor with a default argument
in list-initialization, run cleanups for the default argument after each
iteration of the initialization loop.

We previously only ran the destructor for any temporary once, at the end of the
complete loop, rather than once per iteration!

llvm-svn: 302750
2017-05-11 00:17:17 +00:00
Adrian Prantl dfa7f613ed Update testcase for upstream LLVM changes (r302469).
llvm-svn: 302577
2017-05-09 19:47:41 +00:00
Hans Wennborg fb82abd845 Revert r302476 "Update testcase for upstream LLVM changes."
That test update was for r302469, which was reverted in r302533 due to PR32977.

llvm-svn: 302542
2017-05-09 15:55:39 +00:00
Adrian Prantl 4fa6a33ff6 Update testcase for upstream LLVM changes.
llvm-svn: 302476
2017-05-08 22:44:00 +00:00
Reid Kleckner 6d2ea6ec80 [ms-inline-asm] Use the frontend size only for ambiguous instructions
This avoids problems on code like this:
  char buf[16];
  __asm {
    movups xmm0, [buf]
    mov [buf], eax
  }

The frontend size in this case (1) is wrong, and the register makes the
instruction matching unambiguous. There are also enough bytes available
that we shouldn't complain to the user that they are potentially using
an incorrectly sized instruction to access the variable.

Supersedes D32636 and D26586 and fixes PR28266

llvm-svn: 302179
2017-05-04 18:19:52 +00:00
Adrian Prantl 3b243608f5 Relax testcase to fix a PS4 buildbot failure.
llvm-svn: 301805
2017-05-01 15:49:40 +00:00
Adrian Prantl 6ee72d743b Adapt to LLVM API change (DINamespace no longer takes line/file info).
rdar://problem/17484998
https://reviews.llvm.org/D32648

llvm-svn: 301707
2017-04-28 22:25:53 +00:00
Oren Ben Simhon 318a6eae06 [X86] Support of no_caller_saved_registers attribute
Implements the Clang part for no_caller_saved_registers attribute as appears here: 
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=5ed3cc7b66af4758f7849ed6f65f4365be8223be.

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

llvm-svn: 301535
2017-04-27 12:01:00 +00:00
Vedant Kumar 6b22dda5a3 [ubsan] nullability-assign: Check assignments into C++ structs
Fix the nullability-assign check so that it can handle assignments into
C++ structs. Previously, such assignments were not instrumented.

Testing: check-clang, check-ubsan, enabling the existing test in ObjC++
mode, and building some Apple frameworks with -fsanitize=nullability.

llvm-svn: 301482
2017-04-26 21:55:17 +00:00
Vedant Kumar e859ebbd06 [ubsan] Skip alignment checks on allocas with known alignment
It's possible to determine the alignment of an alloca at compile-time.
Use this information to skip emitting some runtime alignment checks.

Testing: check-clang, check-ubsan.

This significantly reduces the amount of alignment checks we emit when
compiling X86ISelLowering.cpp. Here are the numbers from patched/unpatched
clangs based on r301361.

  ------------------------------------------
  | Setup          | # of alignment checks |
  ------------------------------------------
  | unpatched, -O0 |                 47195 |
  | patched, -O0   |                 30876 | (-34.6%)
  ------------------------------------------

llvm-svn: 301377
2017-04-26 02:17:21 +00:00
Piotr Padlewski 34046bd358 [Devirtualization] Emit invariant.group loads with empty group md
Summary:
As discussed here
http://lists.llvm.org/pipermail/llvm-dev/2017-January/109332.html
having different groups doesn't solve the problem entirly.

Reviewers: rjmccall, rsmith

Subscribers: amharc, cfe-commits

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

llvm-svn: 301178
2017-04-24 12:58:43 +00:00
Richard Smith 645386cf4b Rearrange some Modules TS testcases into test/CXX/modules-ts.
llvm-svn: 301066
2017-04-22 00:47:53 +00:00
Richard Smith 81328ac3a5 P0629R0: Switch to latest proposal for distinguishing module interface from implementation.
This switches from the prototype syntax in P0273R0 ('module' and 'module
implementation') to the consensus syntax 'export module' and 'module'.

In passing, drop the "module declaration must be first" enforcement, since EWG
seems to have changed its mind on that.

llvm-svn: 301056
2017-04-21 22:39:18 +00:00
Shoaib Meenai a90474544e [Sema] Use MSVC inner class behavior on Itanium
Windows Itanium aims to use MSVC export and import semantics. Inner
class members shouldn't be exported on a dllexport explicit
instantiation definition of the outer class, and they shouldn't be
imported on a dllimport explicit instantiation declaration of the outer
class (instead a local copy should be emitted). We were doing the first
but not the second, and this mismatch can lead to link errors. Fix the
behavior and add tests for both.

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

llvm-svn: 300804
2017-04-20 01:11:42 +00:00
Richard Smith 2b0d6134c7 Add a triple to codegen test.
llvm-svn: 300803
2017-04-20 01:02:29 +00:00
Richard Smith ada0888a11 Fix assertion failure in codegen on non-template deduction guide.
llvm-svn: 300762
2017-04-19 21:15:45 +00:00
Roger Ferrer Ibanez cb89513bc7 Avoid assert when a non-static member function is qualified with __unaligned
Under -fms-extensions __unaligned is a type-qualifier that can be applied to a
non-static member function declaration.

This causes an assertion when mangling the name under Itanium, where that
qualifier is not mangled.

This patch justs makes the minimal change to avoid the crash and avoid mangling
__unaligned, as it currently happens with non-member functions.

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

llvm-svn: 300686
2017-04-19 12:23:28 +00:00
Adrian Prantl c3782a1a6f Debug Info: Remove special-casing of indirect function argument handling.
LLVM has changed the semantics of dbg.declare for describing function
arguments. After this patch a dbg.declare always takes the *address*
of a variable as the first argument, even if the argument is not an
alloca.

https://bugs.llvm.org/show_bug.cgi?id=32382
rdar://problem/31205000

llvm-svn: 300523
2017-04-18 01:22:01 +00:00
Vedant Kumar dbbdda4d23 [ubsan] Skip null checks if they are constant-folded away
The IR builder can constant-fold null checks if the pointer operand
points to a constant. If the "is-non-null" check is folded away to
"true", don't emit the null check + branch.

Testing: check-clang, check-ubsan.

This slightly reduces the amount of null checks we emit when compiling
X86ISelLowering.cpp. Here are the numbers from patched/unpatched clangs
based on r300371.

  -------------------------------------
  | Setup          | # of null checks |
  -------------------------------------
  | unpatched, -O0 |            25251 |
  | patched, -O0   |            23925 | (-5.3%)
  -------------------------------------

llvm-svn: 300509
2017-04-17 22:26:10 +00:00
Vedant Kumar 379d9c1dc6 [ubsan] Skip null checks on pointers to the start of an alloca
Pointers to the start of an alloca are non-null, so we don't need to
emit runtime null checks for them.

Testing: check-clang, check-ubsan.

This significantly reduces the amount of null checks we emit when
compiling X86ISelLowering.cpp. Here are the numbers from patched /
unpatched clangs based on r300371.

  -------------------------------------
  | Setup          | # of null checks |
  -------------------------------------
  | unpatched, -O0 |            45439 |
  | patched, -O0   |            25251 | (-44.4%)
  -------------------------------------

llvm-svn: 300508
2017-04-17 22:26:07 +00:00
Vedant Kumar 116aebcae0 [ubsan] Don't check alignment if the alignment is 1
If a pointer is 1-byte aligned, there's no use in checking its
alignment. Somewhat surprisingly, ubsan can spend a significant amount
of time doing just that!

This loosely depends on D30283.

Testing: check-clang, check-ubsan, and a stage2 ubsan build.

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

llvm-svn: 300371
2017-04-14 22:03:37 +00:00
Vedant Kumar ffd7c887d6 [ubsan] Reduce alignment checking of C++ object pointers
This patch teaches ubsan to insert an alignment check for the 'this'
pointer at the start of each method/lambda. This allows clang to emit
significantly fewer alignment checks overall, because if 'this' is
aligned, so are its fields.

This is essentially the same thing r295515 does, but for the alignment
check instead of the null check. One difference is that we keep the
alignment checks on member expressions where the base is a DeclRefExpr.
There's an opportunity to diagnose unaligned accesses in this situation
(as pointed out by Eli, see PR32630).

Testing: check-clang, check-ubsan, and a stage2 ubsan build.

Along with the patch from D30285, this roughly halves the amount of
alignment checks we emit when compiling X86FastISel.cpp. Here are the
numbers from patched/unpatched clangs based on r298160.

  ------------------------------------------
  | Setup          | # of alignment checks |
  ------------------------------------------
  | unpatched, -O0 |                 24326 |
  | patched, -O0   |                 12717 | (-47.7%)
  ------------------------------------------

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

llvm-svn: 300370
2017-04-14 22:03:34 +00:00
Matt Arsenault d972949b10 Update for lifetime intrinsic signature change
llvm-svn: 299877
2017-04-10 20:18:45 +00:00
Peter Collingbourne dc205b3db2 IRGen: Do not set dllexport on declarations.
Setting dllexport on a declaration has no effect, as we do not emit export
directives for declarations.

Part of the fix for PR32334.

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

llvm-svn: 298330
2017-03-21 02:02:41 +00:00
Vedant Kumar 129edab125 Retry: [ubsan] Detect UB loads from bitfields
It's possible to load out-of-range values from bitfields backed by a
boolean or an enum. Check for UB loads from bitfields.

This is the motivating example:

  struct S {
    BOOL b : 1; // Signed ObjC BOOL.
  };

  S s;
  s.b = 1; // This is actually stored as -1.
  if (s.b == 1) // Evaluates to false, -1 != 1.
    ...

Changes since the original commit:

- Single-bit bools are a special case (see CGF::EmitFromMemory), and we
  can't avoid dealing with them when loading from a bitfield. Don't try to
  insert a check in this case.

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

llvm-svn: 297389
2017-03-09 16:06:27 +00:00
Vedant Kumar 3dea91fec6 Revert "[ubsan] Detect UB loads from bitfields"
This reverts commit r297298. It breaks the self-host on this bot:

  http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/962/steps/build%20clang%2Fubsan/logs/stdio

llvm-svn: 297331
2017-03-09 00:18:53 +00:00
Vedant Kumar 5c13623a69 [ubsan] Detect UB loads from bitfields
It's possible to load out-of-range values from bitfields backed by a
boolean or an enum. Check for UB loads from bitfields.

This is the motivating example:

  struct S {
    BOOL b : 1; // Signed ObjC BOOL.
  };

  S s;
  s.b = 1; // This is actually stored as -1.
  if (s.b == 1) // Evaluates to false, -1 != 1.
    ...

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

llvm-svn: 297298
2017-03-08 17:38:57 +00:00
Roger Ferrer Ibanez 3fa38a14ac Honor __unaligned in codegen for declarations and expressions
This patch honors the unaligned type qualifier (currently available through he
keyword __unaligned and -fms-extensions) in CodeGen. In the current form the
patch affects declarations and expressions. It does not affect fields of
classes.

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

llvm-svn: 297276
2017-03-08 14:00:44 +00:00
Reid Kleckner ef23e9574e Relax stmtexpr.cpp checks for PPC64
llvm-svn: 297099
2017-03-06 23:49:18 +00:00
Reid Kleckner 092d065265 Don't assume cleanup emission preserves dominance in expr evaluation
Summary:
Because of the existence branches out of GNU statement expressions, it
is possible that emitting cleanups for a full expression may cause the
new insertion point to not be dominated by the result of the inner
expression. Consider this example:

  struct Foo { Foo(); ~Foo(); int x; };
  int g(Foo, int);
  int f(bool cond) {
    int n = g(Foo(), ({ if (cond) return 0; 42; }));
    return n;
  }

Before this change, result of the call to 'g' did not dominate its use
in the store to 'n'. The early return exit from the statement expression
branches to a shared cleanup block, which ends in a switch between the
fallthrough destination (the assignment to 'n') or the function exit
block.

This change solves the problem by spilling and reloading expression
evaluation results when any of the active cleanups have branches.

I audited the other call sites of enterFullExpression, and they don't
appear to keep and Values live across the site of the cleanup, except in
ARC code. I wasn't able to create a test case for ARC that exhibits this
problem, though.

Reviewers: rjmccall, rsmith

Subscribers: cfe-commits

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

llvm-svn: 297084
2017-03-06 22:18:34 +00:00
Charles Li f22a68714f [Test] Make Lit tests C++11 compatible - IR ordering
Differential Revision: https://reviews.llvm.org/D30430

llvm-svn: 296549
2017-03-01 00:10:00 +00:00
Adrian Prantl b7acfc0139 PR32042: Create inlined debug info for EmitInlinedInheritingCXXConstructorCall.
When clang emits an inheriting C++ constructor it may inline code
during the CodeGen phase. This patch ensures that any debug info in
this inlined code gets a proper inlined location. Otherwise we can end
up with invalid debug info metadata, since all inlined local variables
and function arguments would be reparented into the call site.

Analogous to ApplyInlineLocation this patch introduces a
ApplyInlineDebugLocation scoped helper to facilitate entering an
inlined scope and cleaning up afterwards.

This fixes one of the issues discovered in PR32042.

rdar://problem/30679307

llvm-svn: 296388
2017-02-27 21:30:05 +00:00
Richard Smith df054d3d22 C++ DR1611, 1658, 2180: implement "potentially constructed subobject" rules for special member functions.
Essentially, as a base class constructor does not construct virtual bases, such
a constructor for an abstract class does not need the corresponding base class
construction to be valid, and likewise for destructors.

This creates an awkward situation: clang will sometimes generate references to
the complete object and deleting destructors for an abstract class (it puts
them in the construction vtable for a derived class). But we can't generate a
"correct" version of these because we can't generate references to base class
constructors any more (if they're template specializations, say, we might not
have instantiated them and can't assume any other TU will emit a copy).
Fortunately, we don't need to, since no correct program can ever invoke them,
so instead emit symbols that just trap.

We should stop emitting references to these symbols, but still need to emit
definitions for compatibility.

llvm-svn: 296275
2017-02-25 23:53:05 +00:00
Charles Li 9ea0817c5a [Test] Make Lit tests C++11 compatible #9
[Test] Make Lit tests C++11 compatible #9

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

llvm-svn: 296184
2017-02-24 22:22:05 +00:00
Richard Smith 382bc51fdd PR32044: Fix some cases where we would confuse a transparent init-list expression with an aggregate init.
llvm-svn: 296033
2017-02-23 22:41:47 +00:00
Bob Haarman 4f5a98570f stop using associative comdats for SEH filter functions
Summary: We implement structured exception handling (SEH) by generating filter functions for functions that use exceptions. Currently, we use associative comdats to ensure that the filter functions are preserved if and only if the functions we generated them for are preserved. This can lead to problems when generating COFF objects - LLVM may decide to inline a function that uses SEH and remove its body, at which point we will end up with a comdat that COFF cannot represent. To avoid running into that situation, this change makes us not use associative comdats for SEH filter functions. We can still get the benefits we used the associative comdats for: we will always preserve filter functions we use, and dead stripping can eliminate the ones we don't use.

Reviewers: rnk, pcc, ruiu

Reviewed By: rnk

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

llvm-svn: 295872
2017-02-22 20:29:39 +00:00
Richard Smith a0abc42911 Fix assertion failure when generating debug information for a variable
declaration declared using class template argument deduction.

Patch by Eric Fiselier (who is busy and asked me to commit this on his behalf)!

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

llvm-svn: 295794
2017-02-22 00:13:14 +00:00
Brad Smith 0561a5a7fe Enable support for __float128 in Clang on OpenBSD/X86
/usr/local/include/c++/4.9.4/type_traits:279:39: error: __float128 is not
supported on this target

llvm-svn: 295635
2017-02-20 03:18:15 +00:00
Vedant Kumar 34b1fd6aaa Retry^2: [ubsan] Reduce null checking of C++ object pointers (PR27581)
This patch teaches ubsan to insert exactly one null check for the 'this'
pointer per method/lambda.

Previously, given a load of a member variable from an instance method
('this->x'), ubsan would insert a null check for 'this', and another
null check for '&this->x', before allowing the load to occur.

Similarly, given a call to a method from another method bound to the
same instance ('this->foo()'), ubsan would a redundant null check for
'this'. There is also a redundant null check in the case where the
object pointer is a reference ('Ref.foo()').

This patch teaches ubsan to remove the redundant null checks identified
above.

Testing: check-clang, check-ubsan, and a stage2 ubsan build.

I also compiled X86FastISel.cpp with -fsanitize=null using
patched/unpatched clangs based on r293572. Here are the number of null
checks emitted:

  -------------------------------------
  | Setup          | # of null checks |
  -------------------------------------
  | unpatched, -O0 |            21767 |
  | patched, -O0   |            10758 |
  -------------------------------------

Changes since the initial commit:
- Don't introduce any unintentional object-size or alignment checks.
- Don't rely on IRGen of C labels in the test.

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

llvm-svn: 295515
2017-02-17 23:22:59 +00:00
Vedant Kumar 29ba8d9bfe Revert "Retry: [ubsan] Reduce null checking of C++ object pointers (PR27581)"
This reverts commit r295401. It breaks the ubsan self-host. It inserts
object size checks once per C++ method which fire when the structure is
empty.

llvm-svn: 295494
2017-02-17 20:59:40 +00:00
Charles Li 0ee7c63fd7 [Test] Make Lit tests C++11 compatible - misc
Updated 5 tests.

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

llvm-svn: 295484
2017-02-17 19:36:19 +00:00
Vedant Kumar 55875b9955 Retry: [ubsan] Reduce null checking of C++ object pointers (PR27581)
This patch teaches ubsan to insert exactly one null check for the 'this'
pointer per method/lambda.

Previously, given a load of a member variable from an instance method
('this->x'), ubsan would insert a null check for 'this', and another
null check for '&this->x', before allowing the load to occur.

Similarly, given a call to a method from another method bound to the
same instance ('this->foo()'), ubsan would a redundant null check for
'this'. There is also a redundant null check in the case where the
object pointer is a reference ('Ref.foo()').

This patch teaches ubsan to remove the redundant null checks identified
above.

Testing: check-clang and check-ubsan. I also compiled X86FastISel.cpp
with -fsanitize=null using patched/unpatched clangs based on r293572.
Here are the number of null checks emitted:

  -------------------------------------
  | Setup          | # of null checks |
  -------------------------------------
  | unpatched, -O0 |            21767 |
  | patched, -O0   |            10758 |
  -------------------------------------

Changes since the initial commit: don't rely on IRGen of C labels in the
test.

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

llvm-svn: 295401
2017-02-17 02:03:51 +00:00
Vedant Kumar 4f94a94bea Revert "[ubsan] Reduce null checking of C++ object pointers (PR27581)"
This reverts commit r295391. It breaks this bot:

http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/1898

I need to not rely on labels in the IR test.

llvm-svn: 295396
2017-02-17 01:42:36 +00:00
Vedant Kumar 3e5a9a6be8 [ubsan] Reduce null checking of C++ object pointers (PR27581)
This patch teaches ubsan to insert exactly one null check for the 'this'
pointer per method/lambda.

Previously, given a load of a member variable from an instance method
('this->x'), ubsan would insert a null check for 'this', and another
null check for '&this->x', before allowing the load to occur.

Similarly, given a call to a method from another method bound to the
same instance ('this->foo()'), ubsan would a redundant null check for
'this'. There is also a redundant null check in the case where the
object pointer is a reference ('Ref.foo()').

This patch teaches ubsan to remove the redundant null checks identified
above.

Testing: check-clang and check-ubsan. I also compiled X86FastISel.cpp
with -fsanitize=null using patched/unpatched clangs based on r293572.
Here are the number of null checks emitted:

  -------------------------------------
  | Setup          | # of null checks |
  -------------------------------------
  | unpatched, -O0 |            21767 |
  | patched, -O0   |            10758 |
  -------------------------------------

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

llvm-svn: 295391
2017-02-17 01:05:42 +00:00
Hans Wennborg cac8ce06dd [dllimport] Check for dtor references in functions
Destructor references are not modelled explicitly in the AST. This adds
checks for destructor calls due to variable definitions and temporaries.

If a dllimport function references a non-dllimport destructor, it must
not be emitted available_externally, as the referenced destructor might
live across the DLL boundary and isn't exported.

llvm-svn: 295258
2017-02-15 23:28:10 +00:00
Hans Wennborg 6c3d625fd9 [dllimport] Look through typedefs and arrays in HasNonDllImportDtor
The function is used to check whether a type is a class with
non-dllimport destructor. It needs to look through typedefs and array
types.

llvm-svn: 295257
2017-02-15 23:28:07 +00:00
David Majnemer dc169759ca [MS ABI] Correctly mangling vbase destructors
They are a little bit of a special case in the mangling. They are always
mangled without taking into account their virtual-ness of the
destructor. They are also mangled to return void, unlike the actual
destructor.

This fixes PR31931.

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

llvm-svn: 295010
2017-02-14 00:54:11 +00:00
Nick Lewycky 0752762180 When the new expr's array size is an ICE, emit it as a constant expression.
This bypasses integer sanitization checks which are redundant on the expression since it's been checked by Sema. Fixes a clang codegen assertion on "void test() { new int[0+1]{0}; }" when building with -fsanitize=signed-integer-overflow.

llvm-svn: 295006
2017-02-13 23:49:55 +00:00
Reid Kleckner 9de921470d [CodeGen] Treat auto-generated __dso_handle symbol as HiddenVisibility
Fixes https://bugs.llvm.org/show_bug.cgi?id=31932

Based on a patch by Roland McGrath

Reviewed By: phosek

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

llvm-svn: 294978
2017-02-13 18:49:21 +00:00
Charles Li 58a221a4e2 [Test] Make Lit tests C++11 compatible - nounwind noexcept
C++11 destructors are nothrow by default.

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

llvm-svn: 294972
2017-02-13 17:56:30 +00:00
Reid Kleckner a858981c1d [MS] Fix C++ destructor thunk line info for a declaration
Sometimes the MS ABI needs to emit thunks for declarations that don't
have bodies. Destructor thunks make calls to inlinable functions, so
they need line info or LLVM will complain.

Fixes PR31893

llvm-svn: 294465
2017-02-08 16:09:32 +00:00
Warren Ristow 8d17b40500 Prevent ICE in dllexport class with _Atomic data member
Guard against a null pointer dereference that caused Clang to crash
when processing a class containing an _Atomic qualified data member,
and that is tagged with 'dllexport'.

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

llvm-svn: 293911
2017-02-02 17:53:34 +00:00
Hans Wennborg 9d17df8b46 Drop 'dllimport' when redeclaring inline function template without the attribute (PR31695)
For non-template dllimport functions, MSVC allows providing an inline
definition without spelling out the attribute again. In the example below, f
remains a dllimport function.

  __declspec(dllimport) int f();
  inline int f() { return 42; }

  int useit() {
    return f();
  }

However, for a function template, not putting dllimport on the redeclaration
causes it to be dropped. In the example below, f is not dllimport.

  template <typename> __declspec(dllimport) int f();
  template <typename> inline int f() { return 42; }

  int useit() {
    return f<int>();
  }

This patch makes Clang match MSVC for the second example.

MSVC does not warn about the attribute being dropped in the example above, but
I think we should. (MSVC does warn if the inline keyword isn't used.)

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

llvm-svn: 293800
2017-02-01 18:52:53 +00:00
Hans Wennborg fd350a3b4f Follow-up to r293732: add a proper triple to the test
llvm-svn: 293735
2017-02-01 02:48:02 +00:00
Hans Wennborg 27dcc6c0e2 clang-cl: Evaluate arguments left-to-right in constructor call with initializer list (PR31831)
clang-cl would evaluate the arguments right-to-left (see PR), and for
non-Windows targets I suppose we only got it because we were already
emitting left-to-right in CodeGenFunction::EmitCallArgs.

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

llvm-svn: 293732
2017-02-01 02:21:07 +00:00
David Blaikie 4d92301075 Fix modules codegen to be compatible with modules-ts
The Module::WithCodegen flag was only being set when the module was
parsed from a ModuleMap. Instead set it late, in the ASTWriter to match
the layer where the MODULAR_CODEGEN_DECLs list is determined (the
WithCodegen flag essentially means "are this module's decls in
MODULAR_CODEGEN_DECLs").

When simultaneous emission of AST file and modular object is implemented
this may need to change - the Module::WithCodegen flag will need to be
set earlier, and ideally the MODULAR_CODEGEN_DECLs gathering will
consult this flag (that's not possible right now since Decls destined
for an AST File don't have a Module - only if they're /read/ from a
Module is that true - I expect that would need to change as well).

llvm-svn: 293692
2017-01-31 21:28:19 +00:00
David Blaikie b11c87324e Reapply "DebugInfo: Omit class definitions even in the presence of available_externally vtables"
Accounts for a case that caused an assertion failure by attempting to
query for the vtable linkage of a non-dynamic type.t

This reverts commit r292801.

llvm-svn: 293462
2017-01-30 06:36:08 +00:00
David Blaikie eb21001111 Fix linkage of static locals in available_externally functions to be DiscardableODR/linkonce_odr
As Mehdi put it, entities should either be
available_externally+weak_odr, or linkonce_odr+linkonce_odr. While some
functions are emitted a_e/weak, their local variables were emitted
a_e/linkonce_odr.

While it might be nice to emit them a_e/weak, the Itanium ABI (& best
guess at MSVC's behavior as well) requires the local to be
linkonce/linkonce.

Reviewers: rsmith, mehdi_amini

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

llvm-svn: 293344
2017-01-27 23:11:10 +00:00
Peter Collingbourne b884716f6a Re-apply r292662, "IRGen: Start using the WriteThinLTOBitcode pass."
The internal build issue has been resolved.

llvm-svn: 293231
2017-01-26 23:51:50 +00:00
Richard Smith 6536f6058d Strengthen test from r292632 to also check we get the mangling correct for this case.
llvm-svn: 292978
2017-01-24 21:03:48 +00:00
Hans Wennborg 251c204e57 Re-commit "Don't inline dllimport functions referencing non-imported methods"
This re-commits r292522 with the addition that it also handles calls
through pointer to member functions without crashing.

llvm-svn: 292856
2017-01-23 23:57:50 +00:00
David Blaikie 8cf0c27404 Revert "DebugInfo: Omit class definitions even in the presence of available_externally vtables"
Patch crashing on a bootstrapping sanitizer bot:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/679

Reverting while I investigate.

This reverts commit r292768.

llvm-svn: 292801
2017-01-23 16:57:14 +00:00
Martin Bohme 5057766d87 Revert "IRGen: Start using the WriteThinLTOBitcode pass."
Summary:
This reverts commit r292662.

This change broke internal builds. Will provide a reproducer internally.

Subscribers: pcc, mehdi_amini, cfe-commits, mgorny

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

llvm-svn: 292791
2017-01-23 14:33:42 +00:00
David Blaikie b06bcde1ab DebugInfo: Omit class definitions even in the presence of available_externally vtables
To ensure optimization level doesn't pessimize the -fstandalone-debug
vtable debug info optimization (where class definitions are only emitted
where the vtable is emitted - reducing redundant debug info) ensure the
debug info class definition is still omitted when an
available_externally vtable definition is emitted for optimization
purposes.

llvm-svn: 292768
2017-01-23 02:24:03 +00:00
Peter Collingbourne 6f16ac1473 IRGen: Start using the WriteThinLTOBitcode pass.
This is the final change necessary to support CFI with ThinLTO.

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

llvm-svn: 292662
2017-01-20 22:39:16 +00:00
Reid Kleckner 25019ca828 Revert "Don't inline dllimport functions referencing non-imported methods"
This reverts commit r292522. It appears to be causing crashes in builds
using dllimport.

llvm-svn: 292643
2017-01-20 20:44:50 +00:00
Richard Smith 91fb1f4be7 Fix actually-reachable llvm_unreachable.
llvm-svn: 292632
2017-01-20 18:50:12 +00:00
Richard Smith 5e29dd3fe0 P0426: Make the library implementation of constexpr char_traits a little easier
by providing a memchr builtin that returns char* instead of void*.

Also add a __has_feature flag to indicate the presence of constexpr forms of
the relevant <string> functions.

llvm-svn: 292555
2017-01-20 00:45:35 +00:00
Hans Wennborg 7c650777b0 Don't inline dllimport functions referencing non-imported methods
This is another follow-up to r246338. I had assumed methods were already
handled by the AST visitor, but turns out they weren't.

llvm-svn: 292522
2017-01-19 21:33:13 +00:00
Peter Collingbourne 1e1475ace5 Move vtable type metadata emission behind a cc1-level flag.
In ThinLTO mode, type metadata will require the module to be written as a
multi-module bitcode file, which is currently incompatible with the Darwin
linker. It is also useful to be able to enable or disable multi-module bitcode
for testing purposes. This introduces a cc1-level flag, -f{,no-}lto-unit,
which is used by the driver to enable multi-module bitcode on all but
Darwin+ThinLTO, and can also be used to enable/disable the feature manually.

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

llvm-svn: 292448
2017-01-18 23:55:27 +00:00
David Majnemer 7291a3e7d2 [AST] AttributedType should derive type properties from the EquivalentType
Using the canonical type instead of the equivalent type can result in
insufficient template instantiations.

This fixes PR31656.

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

llvm-svn: 292194
2017-01-17 04:14:25 +00:00
Reid Kleckner 791bbf6f18 Use less byval on 32-bit Windows x86 for classes with bases
This comes up in V8, which has a Handle template class that wraps a
typed pointer, and is frequently passed by value. The pointer is stored
in the base, HandleBase. This change allows us to pass the struct as a
pointer instead of using byval. This avoids creating tons of temporary
allocas that we copy from during call lowering.

Eventually, it would be good to use FCAs here instead.

llvm-svn: 291917
2017-01-13 17:18:19 +00:00
Shoaib Meenai 5adfb5a814 [Sema] Restrict explicit instantation definition dllexport
In the case where the template class itself is already `dllexport`, the
implicit instantiation will have already emitted all members. When we
check the explicit instantiation definition, the `Specialization` will
have inherited the `dllexport` attribute, so we'll attempt to emit all
members for a second time, which causes an assertion failure. Restrict
the exporting to when the `dllexport` attribute is newly introduced by
the explicit instantiation definition.

Fixes PR31608.

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

llvm-svn: 291877
2017-01-13 01:28:34 +00:00
Richard Smith fbe2369f1a Improve handling of instantiated thread_local variables in Itanium C++ ABI.
* Do not initialize these variables when initializing the rest of the
   thread_locals in the TU; they have unordered initialization so they can be
   initialized by themselves.

   This fixes a rejects-valid bug: we would make the per-variable initializer
   function internal, but put it in a comdat keyed off the variable, resulting
   in link errors when the comdat is selected from a different TU (as the per
   TU TLS init function tries to call an init function that does not exist).

 * On Darwin, when we decide that we're not going to emit a thread wrapper
   function at all, demote its linkage to External. Fixes a verifier failure
   on explicit instantiation of a thread_local variable on Darwin.

llvm-svn: 291865
2017-01-13 00:43:31 +00:00
Chandler Carruth 7e8283ae6b Replace some stray uses of the old spelling of the flag with the new
spelling. NFC.

llvm-svn: 291851
2017-01-12 22:43:37 +00:00
Matthias Braun 44bfe03da9 CGDecl: Skip static variable initializers in unreachable code
This fixes http://llvm.org/PR31054

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

llvm-svn: 291576
2017-01-10 17:43:01 +00:00
Richard Smith cf63b845df MSVC seems to use (void) in __FUNCSIG__ for a zero-parameter function even in C++. Follow suit.
llvm-svn: 291489
2017-01-09 22:16:16 +00:00
Richard Smith 2f63d4612f PR31587: Fix handling of __FUNCSIG__ in C.
Fix crash if __FUNCSIG__ is used in a function without a prototype, and use
"(void)" as parameter list instead of "()" for a function with a no-parameters
prototype, matching MSVC's observed behavior.

llvm-svn: 291484
2017-01-09 21:40:40 +00:00
David L. Jones f55ce36c02 Allow constexpr construction of subobjects unconditionally, not just in C++14.
Summary:
Per https://wg21.link/CWG1677, the C++11 standard did not clarify that constant
initialization of an object allowed constexpr brace-or-equal initialization of
subobjects:

  struct foo_t { union { int i; volatile int j; } u; };

  __attribute__((__require_constant_initialization__))
  static const foo_t x = {{0}};

Because foo_t::u has a volatile member, the initializer for x fails. However,
there is really no good reason, because this:

  union foo_u { int i; volatile int j; };
  __attribute__((__require_constant_initialization__))
  static const foo_u x = {0};

does have a constant initializer.

(This was triggered by musl's pthread_mutex_t type when building under C++11.)

Reviewers: rsmith

Subscribers: EricWF, cfe-commits

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

llvm-svn: 291480
2017-01-09 21:38:07 +00:00
Charles Li fad02411e0 [Lit Test] Make tests C++11 compatible - nothrow destructors
In C++11, a destructor's implicit exception-spec is nothrow.
The IR for the destructor's invocation changed from invoke to call.

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

llvm-svn: 291458
2017-01-09 18:24:16 +00:00
Reid Kleckner 82713bf352 [MS] Mark default args of exported default constructors as used
Fixes a regression introduced in r291045, which would lead to link
errors. While we should no longer encounter unparsed or uninstantiated
default arguments in this codepath, we still need to call
CheckCXXDefaultArgExpr to mark the default argument expressions as
ODR-used.

llvm-svn: 291453
2017-01-09 17:27:17 +00:00
Reid Kleckner 6615ea89cb Split dllexport default constructor closure tests out into a separate file
test/CodeGenCXX/dllexport.cpp has grown quite large at this point. NFC

llvm-svn: 291452
2017-01-09 17:25:30 +00:00
Reid Kleckner 290feb9c19 [MS] Fix function type mangling of default ctor closures
Use the canonical decl in pointer comparisons with the default
constructor closure decl. Otherwise we don't produce the correct
"@@QAEXXZ" mangling, which essentially means "void(void) thiscall public
instance method".

llvm-svn: 291448
2017-01-09 17:04:37 +00:00
Filipe Cabecinhas fe5e5afd53 [ubsan] Minimize size of data for type_mismatch (Redo of D19667)
Summary:
This patch makes the type_mismatch static data 7 bytes smaller (and it
ends up being 16 bytes smaller due to alignment restrictions, at least
on some x86-64 environments).

It revs up the type_mismatch handler version since we're breaking binary
compatibility. I will soon post a patch for the compiler-rt side.

Reviewers: rsmith, kcc, vitalybuka, pgousseau, gbedwell

Subscribers: llvm-commits

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

llvm-svn: 291236
2017-01-06 14:40:12 +00:00
Reid Kleckner 61195e12fc [MS] Instantiate default args during instantiation of exported default ctors
Summary:
Replace some old code that probably pre-dated the change to delay
emission of dllexported code until after the closing brace of the
outermost record type. Only uninstantiated default argument expressions
need to be handled now. It is enough to instantiate default argument
expressions when instantiating dllexported default ctors. This also
fixes some double-diagnostic issues in this area.

Fixes PR31500

Reviewers: rsmith

Subscribers: cfe-commits

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

llvm-svn: 291045
2017-01-05 01:08:22 +00:00
Erich Keane 521ed960ed Correct Vectorcall Register passing and HVA Behavior
Front end component (back end changes are D27392).  The vectorcall 
calling convention was broken subtly in two cases.  First, 
it didn't properly handle homogeneous vector aggregates (HVAs). 
Second, the vectorcall specification requires that only the 
first 6 parameters be eligible for register assignment. 
This patch fixes both issues.

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

llvm-svn: 291041
2017-01-05 00:20:51 +00:00
Alex Lorenz 89172792dd Fix a buildbot failure introduced by r290960.
The commit r290960 checked the the basic block label name which isn't there
when clang is compiled in release mode.

llvm-svn: 290968
2017-01-04 15:07:13 +00:00
Alex Lorenz c1608f7f69 Add -f[no-]strict-return flag that can be used to avoid undefined behaviour
in non-void functions that fall off at the end without returning a value when
compiling C++.

Clang uses the new compiler flag to determine when it should treat control flow
paths that fall off the end of a non-void function as unreachable. If
-fno-strict-return is on, the code generator emits the ureachable and trap
IR only when the function returns either a record type with a non-trivial
destructor or another non-trivially copyable type.

The primary goal of this flag is to avoid treating falling off the end of a
non-void function as undefined behaviour. The burden of undefined behaviour
is placed on the caller instead: if the caller ignores the returned value then
the undefined behaviour is avoided. This kind of behaviour is useful in
several cases, e.g. when compiling C code in C++ mode.

rdar://13102603

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

llvm-svn: 290960
2017-01-04 13:40:34 +00:00
David Blaikie deeca6de08 DebugInfo: Don't include size/alignment on class declarations
This seems like it must've been a leftover by accident - no tests were
backing it up & it doesn't make much sense to include size/alignment on
class declarations (it'd only be on those declarations for which the
definition was available - otherwise the size/alignment would not be
known).

llvm-svn: 290631
2016-12-27 22:05:35 +00:00
David Majnemer a5cfddc367 [MS ABI] Mangle unnamed enums correctly
Unnamed enums take the name of the first enumerator they define.

llvm-svn: 290509
2016-12-25 05:26:02 +00:00
Chandler Carruth fcd33149b4 Cleanup the handling of noinline function attributes, -fno-inline,
-fno-inline-functions, -O0, and optnone.

These were really, really tangled together:
- We used the noinline LLVM attribute for -fno-inline
  - But not for -fno-inline-functions (breaking LTO)
  - But we did use it for -finline-hint-functions (yay, LTO is happy!)
  - But we didn't for -O0 (LTO is sad yet again...)
- We had weird structuring of CodeGenOpts with both an inlining
  enumeration and a boolean. They interacted in weird ways and
  needlessly.
- A *lot* of set smashing went on with setting these, and then got worse
  when we considered optnone and other inlining-effecting attributes.
- A bunch of inline affecting attributes were managed in a completely
  different place from -fno-inline.
- Even with -fno-inline we failed to put the LLVM noinline attribute
  onto many generated function definitions because they didn't show up
  as AST-level functions.
- If you passed -O0 but -finline-functions we would run the normal
  inliner pass in LLVM despite it being in the O0 pipeline, which really
  doesn't make much sense.
- Lastly, we used things like '-fno-inline' to manipulate the pass
  pipeline which forced the pass pipeline to be much more
  parameterizable than it really needs to be. Instead we can *just* use
  the optimization level to select a pipeline and control the rest via
  attributes.

Sadly, this causes a bunch of churn in tests because we don't run the
optimizer in the tests and check the contents of attribute sets. It
would be awesome if attribute sets were a bit more FileCheck friendly,
but oh well.

I think this is a significant improvement and should remove the semantic
need to change what inliner pass we run in order to comply with the
requested inlining semantics by relying completely on attributes. It
also cleans up tho optnone and related handling a bit.

One unfortunate aspect of this is that for generating alwaysinline
routines like those in OpenMP we end up removing noinline and then
adding alwaysinline. I tried a bunch of other approaches, but because we
recompute function attributes from scratch and don't have a declaration
here I couldn't find anything substantially cleaner than this.

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

llvm-svn: 290398
2016-12-23 01:24:49 +00:00
Chandler Carruth 93786da2cb Make '-disable-llvm-optzns' an alias for '-disable-llvm-passes'.
Much to my surprise, '-disable-llvm-optzns' which I thought was the
magical flag I wanted to get at the raw LLVM IR coming out of Clang
deosn't do that. It still runs some passes over the IR. I don't want
that, I really want the *raw* IR coming out of Clang and I strongly
suspect everyone else using it is in the same camp.

There is actually a flag that does what I want that I didn't know about
called '-disable-llvm-passes'. I suspect many others don't know about it
either. It both does what I want and is much simpler.

This removes the confusing version and makes that spelling of the flag
an alias for '-disable-llvm-passes'. I've also moved everything in Clang
to use the 'passes' spelling as it seems both more accurate (*all* LLVM
passes are disabled, not just optimizations) and much easier to remember
and spell correctly.

This is part of simplifying how Clang drives LLVM to make it cleaner to
wire up to the new pass manager.

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

llvm-svn: 290392
2016-12-23 00:23:01 +00:00
George Burgess IV e37633713d Add the alloc_size attribute to clang, attempt 2.
This is a recommit of r290149, which was reverted in r290169 due to msan
failures. msan was failing because we were calling
`isMostDerivedAnUnsizedArray` on an invalid designator, which caused us
to read uninitialized memory. To fix this, the logic of the caller of
said function was simplified, and we now have a `!Invalid` assert in
`isMostDerivedAnUnsizedArray`, so we can catch this particular bug more
easily in the future.

Fingers crossed that this patch sticks this time. :)

Original commit message:

This patch does three things:
- Gives us the alloc_size attribute in clang, which lets us infer the
  number of bytes handed back to us by malloc/realloc/calloc/any user
  functions that act in a similar manner.
- Teaches our constexpr evaluator that evaluating some `const` variables
  is OK sometimes. This is why we have a change in
  test/SemaCXX/constant-expression-cxx11.cpp and other seemingly
  unrelated tests. Richard Smith okay'ed this idea some time ago in
  person.
- Uniques some Blocks in CodeGen, which was reviewed separately at
  D26410. Lack of uniquing only really shows up as a problem when
  combined with our new eagerness in the face of const.

llvm-svn: 290297
2016-12-22 02:50:20 +00:00
Richard Smith 505ef81422 Fix defaulted-functions-in-C++98 extension to give the functions the same
effect they would have in C++11. In particular, they do not prevent
value-initialization from performing zero-initialization, nor do they prevent a
struct from being an aggregate.

llvm-svn: 290229
2016-12-21 01:57:02 +00:00
Paul Robinson bd463120ab Make a test use a specific C++ dialect
In stack-reuse-miscompile.cpp, the allocas for the temps come out in
a different order depending on whether the dialect is C++03 or
C++11. Specify C++03 explicitly to avoid depending on the default.

Differential Revision: http://reviews.llvm.org/D27956

llvm-svn: 290208
2016-12-20 22:30:44 +00:00
Paul Robinson a4549879a5 C++11 test cleanup: nonthrowing destructors
If a dtor has no interesting members, then it ends up being nothrow,
which affects the generated IR. Modify some tests to tolerate this
difference between C++03 and C++11.

Differential Revision: http://reviews.llvm.org/D27936

llvm-svn: 290207
2016-12-20 22:26:11 +00:00