Commit Graph

5908 Commits

Author SHA1 Message Date
Peter Collingbourne a4ccff3281 Implement Control Flow Integrity for virtual calls.
This patch introduces the -fsanitize=cfi-vptr flag, which enables a control
flow integrity scheme that checks that virtual calls take place using a vptr of
the correct dynamic type. More details in the new docs/ControlFlowIntegrity.rst
file.

It also introduces the -fsanitize=cfi flag, which is currently a synonym for
-fsanitize=cfi-vptr, but will eventually cover all CFI checks implemented
in Clang.

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

llvm-svn: 230055
2015-02-20 20:30:56 +00:00
David Majnemer 67a8ec6258 Itanium ABI: Pack expansions change the arity of expressions to unknown
llvm-svn: 229918
2015-02-19 21:41:48 +00:00
NAKAMURA Takumi 8f2085ed16 CXXNameMangler::mangleUnresolvedPrefix(): Prune an obsolete \param, according to r229809. [-Wdocumentation]
llvm-svn: 229823
2015-02-19 07:14:26 +00:00
David Majnemer cb34c67c2a Itanium ABI: Don't pass nullptr to a bool argument
llvm-svn: 229822
2015-02-19 05:51:14 +00:00
David Majnemer b8014dd7c0 Itanium ABI: Properly qualify the destructor-name
We didn't have enough qualificaiton before the scope specifier and we
had too much qualification in the destructor name itself.

llvm-svn: 229809
2015-02-19 02:16:16 +00:00
David Majnemer a16d4707bc Itanium ABI: Write a character instead of a string literal
No functional change intended.

llvm-svn: 229726
2015-02-18 19:08:14 +00:00
David Majnemer f8c02e6bfb Itanium ABI: Properly mangle extern "C" template arguments
extern "C" declarations should be considered like global declarations
for mangling purposes.

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

llvm-svn: 229724
2015-02-18 19:08:11 +00:00
Zoran Jovanovic 26a1216a74 Change representation of member function pointers for MIPS targets
Differential Revision: http://reviews.llvm.org/D7148

llvm-svn: 229680
2015-02-18 15:21:35 +00:00
David Majnemer 7ff7eb706a Itanium ABI: Mangle <mangled-name> according to the ABI
We attempted to be compatible with GCC's buggy mangling for templates
with a declaration for a template argument.

However, we weren't completely successful in copying their bug in cases
like:
  char foo;
  template <char &C> decltype(C) f() { return foo; };
  template char &f<foo>();

Instead, just follow the ABI specification.  This fixes PR22621.

llvm-svn: 229644
2015-02-18 07:47:09 +00:00
David Majnemer a88b359fdc Itanium ABI: Improve our mangling of <destructor-name>
Our mangling of <destructor-name> wasn't quite right: we'd introduce
mangling substitutions where one shouldn't be possible.  We also didn't
correctly handle the case where the destroyed type was not dependent but
still a TemplateSpecializationType.

N.B. There isn't a mangling for a template-template parameter showing up
as the destroyed type.  We do the 'obvious' thing and mangle the index
of the parameter.

llvm-svn: 229615
2015-02-18 02:28:01 +00:00
Benjamin Kramer f989042f18 Prefer SmallVector::append/insert over push_back loops. Clang edition.
Same functionality, but hoists the vector growth out of the loop.

llvm-svn: 229508
2015-02-17 16:48:30 +00:00
Fariborz Jahanian b0553e21cc [Objctive-C sema]. Do not do the unused-getter-return-value
warning when property getter is used in direct method call
and return value of property is unused. rdar://19773512

llvm-svn: 229458
2015-02-16 23:49:44 +00:00
Serge Pavlov 6b92603481 Enhance printing SizeOfPackExpr in dump.
llvm-svn: 229428
2015-02-16 19:58:41 +00:00
Aaron Ballman abc1892057 Removing LLVM_DELETED_FUNCTION, as MSVC 2012 was the last reason for requiring the macro. NFC; Clang edition.
llvm-svn: 229339
2015-02-15 22:54:08 +00:00
Aaron Ballman 673476684e Removing LLVM_EXPLICIT, as MSVC 2012 was the last reason for requiring the macro. NFC; Clang edition.
llvm-svn: 229336
2015-02-15 22:00:28 +00:00
David Majnemer 1dabfdcf6f ItaniumMangle: Correctly mangle <base-unresolved-name>
We had two bugs:
- We were missing the "on" prefix for unresolved operators.
- We didn't handle the mangling of destructors at all.

This fixes PR22584.

llvm-svn: 229255
2015-02-14 13:23:54 +00:00
Richard Smith 902a0238aa DR1748: the reserved placement allocation functions have undefined behavior if
they're given a null pointer as an argument, so we do not need to emit null
checks on their results.

llvm-svn: 229213
2015-02-14 01:52:20 +00:00
Benjamin Kramer ece036e5a8 CXXInheritance: Modernize removal of hidden virtual base class decls.
NFC.

llvm-svn: 228864
2015-02-11 19:09:16 +00:00
Richard Smith e8292b10a6 [modules] When determining whether a name from a module replaces a name we
already have, check whether the name from the module is actually newer than the
existing declaration. If it isn't, we might (say) replace a visible declaration
with an injected friend, and thus make it invisible (or lose a default argument
or an array bound).

llvm-svn: 228661
2015-02-10 03:28:10 +00:00
Richard Smith 2b56057517 [modules] Treat friend declarations that are lexically within a dependent
context as anonymous for merging purposes. They can't be found by their names,
so we merge them based on their position within the surrounding context.

llvm-svn: 228485
2015-02-07 03:11:11 +00:00
Richard Smith a3271c1390 [modules] Don't accidentally trigger deserialization from DeclContext::noload_lookup.
llvm-svn: 228475
2015-02-07 00:45:52 +00:00
Benjamin Kramer b4ef66832d Update APIs that return a pair of iterators to return an iterator_range instead.
Convert uses of those APIs into ranged for loops. NFC.

llvm-svn: 228404
2015-02-06 17:25:10 +00:00
Richard Smith ed83ebd77e PR22465: when performing list-initialization for a class type C, if we see an
initializer of the form {x}, where x is of type C or a type derived from C,
perform *non-list* initialization of the entity from x, but create a
CXXConstructExpr that knows that we used list-initialization syntax.

Plus some fixes to ensure we mangle correctly in this and related cases.

llvm-svn: 228276
2015-02-05 07:02:11 +00:00
Richard Smith 520449d55e Various fixes to mangling of list-initialization.
llvm-svn: 228274
2015-02-05 06:15:50 +00:00
Josh Magee 4d1a79b8c0 Catch more cases when diagnosing integer-constant-expression overflows.
When visiting AssignmentOps, keep evaluating after a failure (when possible) in
order to identify overflow in subexpressions.

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

llvm-svn: 228202
2015-02-04 21:50:20 +00:00
Alexey Samsonov a511cdd247 Allow to specify multiple -fsanitize-blacklist= arguments.
Summary:
Allow user to provide multiple blacklists by passing several
-fsanitize-blacklist= options. These options now don't override
default blacklist from Clang resource directory, which is always
applied (which fixes PR22431).

-fno-sanitize-blacklist option now disables all blacklists that
were specified earlier in the command line (including the default
one).

This change depends on http://reviews.llvm.org/D7367.

Test Plan: regression test suite

Reviewers: timurrrr

Subscribers: cfe-commits, kcc, pcc

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

llvm-svn: 228156
2015-02-04 17:40:08 +00:00
Larisse Voufo 404e142ed7 Generalize r228066 to give all implicit global allocation functions default visibility.
llvm-svn: 228107
2015-02-04 02:34:32 +00:00
Larisse Voufo fce61d3fc8 PR22419: Give implicit sized deallocation functions default visibility
llvm-svn: 228066
2015-02-03 23:31:50 +00:00
David Majnemer 5821ff78ef AST: Hoist RT->getDecl() into a variable
llvm-svn: 227953
2015-02-03 08:49:29 +00:00
David Majnemer 7d82131abe MS ABI: Records with required alignment can't have common linkage
This fixes PR22441.

llvm-svn: 227950
2015-02-03 07:35:55 +00:00
David Majnemer 8ab003a0db The prefix 'Ms-' should be 'MS-'
Clang is otherwise consistent that Microsoft be abbreviated as MS, not
Ms.

llvm-svn: 227842
2015-02-02 19:30:52 +00:00
Benjamin Kramer 04ec7e316b Reimplement iterator wrappers on top of llvm::iterator_adaptor_base.
Eliminates a ton of boilerplate proxying the iterator methods. NFC.

llvm-svn: 227764
2015-02-01 20:31:36 +00:00
Richard Smith d0e102fece Teach AST printing to not print whitespace inside {} and () for initialization,
to match LLVM's preferred style.

llvm-svn: 227545
2015-01-30 02:04:26 +00:00
Richard Smith 1ae689c2b8 PR22367: Don't forget to create a CXXFunctionalCastExpr around
list-initialization that gets converted to some form other than an
InitListExpr. CXXTemporaryObjectExpr is a special case here, because it
represents a fused CXXFunctionalCastExpr + CXXConstructExpr. That, in
itself, is probably a design error...

llvm-svn: 227377
2015-01-28 22:06:01 +00:00
Derek Schuff 3970a7ec9b Remove support for pnaclcall attribute
Summary:
It was used for interoperability with PNaCl's calling conventions, but
it's no longer needed.

Also Remove NaCl*ABIInfo which just existed to delegate to either the portable
or native ABIInfo, and remove checkCallingConvention which was now a no-op
override.

Reviewers: jvoung

Subscribers: jfb, llvm-commits

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

llvm-svn: 227362
2015-01-28 20:24:52 +00:00
Richard Trieu 15b66535ca When checking the template argument list, use a copy of that list for changes
and only update the orginal list on a valid arugment list.  When checking an
individual expression template argument, and conversions are required, update
the expression in the template argument.  Since template arguments are
speculatively checked, the copying of the template argument list prevents
updating the template arguments when the list does not match the template.

Additionally, clean up the integer checking code in the template diffing code.
The code performs unneccessary conversions from APSInt to APInt.

Fixes PR21758.

This essentially reverts r224770 to recommits r224667 and r224668 with extra
changes to prevent the template instantiation problems seen in PR22006.
A test to catch the discovered problem is also added.

llvm-svn: 226983
2015-01-24 02:48:32 +00:00
Richard Smith 8a63989728 [modules] Sometimes we can deserialize a class member but not have yet
encountered any definition for the class; this happens when the definition is
added by an update record that is not yet loaded. In such a case, eagerly pick
the original parent of the member as the canonical definition of the class
rather than muddling through with the canonical declaration (the latter can
lead to us failing to merge properly later if the canonical definition turns
out to be some other declaration).

llvm-svn: 226977
2015-01-24 01:07:20 +00:00
Reid Kleckner 1d59f99f5c Initial support for Win64 SEH IR emission
The lowering looks a lot like normal EH lowering, with the exception
that the exceptions are caught by executing filter expression code
instead of matching typeinfo globals. The filter expressions are
outlined into functions which are used in landingpad clauses where
typeinfo would normally go.

Major aspects that still need work:
- Non-call exceptions in __try bodies won't work yet. The plan is to
  outline the __try block in the frontend to keep things simple.
- Filter expressions cannot use local variables until capturing is
  implemented.
- __finally blocks will not run after exceptions. Fixing this requires
  work in the LLVM SEH preparation pass.

The IR lowering looks like this:

// C code:
bool safe_div(int n, int d, int *r) {
  __try {
    *r = normal_div(n, d);
  } __except(_exception_code() == EXCEPTION_INT_DIVIDE_BY_ZERO) {
    return false;
  }
  return true;
}

; LLVM IR:
define i32 @filter(i8* %e, i8* %fp) {
  %ehptrs = bitcast i8* %e to i32**
  %ehrec = load i32** %ehptrs
  %code = load i32* %ehrec
  %matches = icmp eq i32 %code, i32 u0xC0000094
  %matches.i32 = zext i1 %matches to i32
  ret i32 %matches.i32
}

define i1 zeroext @safe_div(i32 %n, i32 %d, i32* %r) {
  %rr = invoke i32 @normal_div(i32 %n, i32 %d)
      to label %normal unwind to label %lpad

normal:
  store i32 %rr, i32* %r
  ret i1 1

lpad:
  %ehvals = landingpad {i8*, i32} personality i32 (...)* @__C_specific_handler
      catch i8* bitcast (i32 (i8*, i8*)* @filter to i8*)
  %ehptr = extractvalue {i8*, i32} %ehvals, i32 0
  %sel = extractvalue {i8*, i32} %ehvals, i32 1
  %filter_sel = call i32 @llvm.eh.seh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @filter to i8*))
  %matches = icmp eq i32 %sel, %filter_sel
  br i1 %matches, label %eh.except, label %eh.resume

eh.except:
  ret i1 false

eh.resume:
  resume
}

Reviewers: rjmccall, rsmith, majnemer

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

llvm-svn: 226760
2015-01-22 01:36:17 +00:00
Saleem Abdulrasool 97a01f0161 Fix isTriviallyCopyableType for arrays
Fix isTriviallyCopyableType for arrays. An array of type T is trivially copyable
if T is trivially copyable.

Patch by Agustín Bergé!

llvm-svn: 226696
2015-01-21 19:39:10 +00:00
David Majnemer 475b25eefa AST: Don't ignore alignas on EnumDecls when calculating alignment
We didn't consider any alignment attributes on an EnumDecl when
calculating alignment.

While we are here, ignore alignment specifications on typedef types if
one is used as the underlying type.  Otherwise, weird things happen:

enum Y : int;
Y y;

typedef int __attribute__((aligned(64))) u;
enum Y : u {};

What is the alignment of 'Y'?  It would be more consistent with the
overall design of enums with fixed underlying types to consider the
underlying type's UnqualifiedDesugaredType.

This fixes PR22279.

llvm-svn: 226653
2015-01-21 10:54:38 +00:00
Alexander Kornienko 21de0ae3d4 Re-apply "r226548 - Introduce SPIR calling conventions" reverted in r226558.
The test was fixed after a discussion with the revision author: the check
pattern was made more flexible as the "%call" part is not what we actually want
to check strictly there.

The original patch description:
===
Introduce SPIR calling conventions.

This implements Section 3.7 from the SPIR 1.2 spec:

    SPIR kernels should use "spir_kernel" calling convention.
    Non-kernel functions use "spir_func" calling convention. All
    other calling conventions are disallowed.

The patch works only for OpenCL source. Any other uses will need
to ensure that kernels are assigned the spir_kernel calling
convention correctly.
===

llvm-svn: 226561
2015-01-20 11:20:41 +00:00
Alexander Kornienko 22c9d67e34 Reverting r226548 as one of the tests fails in some configurations.
Here's the fail log from our internal setup:
===
  .../tools/clang/clang -cc1 -internal-isystem .../tools/clang/staging/include -nostdsysteminc .../tools/clang/test/CodeGenOpenCL/spir-calling-conv.cl -triple spir-unknown-unknown -emit-llvm -o -
  FileCheck .../tools/clang/test/CodeGenOpenCL/spir-calling-conv.cl
.../tools/clang/test/CodeGenOpenCL/spir-calling-conv.cl:11:12: error: expected string not found in input
 // CHECK: %call = tail call spir_func i32 @get_dummy_id(i32 0)
           ^
<stdin>:6:52: note: scanning from here
define spir_kernel void @foo(i32 addrspace(1)* %A) #0 {
                                                   ^
<stdin>:7:2: note: possible intended match here
 %1 = tail call spir_func i32 @get_dummy_id(i32 0) #2
 ^
===

Here's a failure on a public CI server:
http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/1183/

llvm-svn: 226558
2015-01-20 10:55:33 +00:00
Sameer Sahasrabuddhe 450a58b8af Introduce SPIR calling conventions.
This implements Section 3.7 from the SPIR 1.2 spec:

    SPIR kernels should use "spir_kernel" calling convention.
    Non-kernel functions use "spir_func" calling convention. All
    other calling conventions are disallowed.

The patch works only for OpenCL source. Any other uses will need
to ensure that kernels are assigned the spir_kernel calling
convention correctly.

llvm-svn: 226548
2015-01-20 06:44:32 +00:00
David Blaikie a81d410d4f DebugInfo: Correct the debug location of non-static data member initializers
This was causing some trouble for otherwise dead code removed in r225085
(reverted in r225361). The location being set for function arguments was
leaking out to the call which wasn't setting its own location (so a
quality bug turned into a crasher with r225085). Fix this so r225085 can
be recommitted.

llvm-svn: 226382
2015-01-18 00:12:58 +00:00
Chandler Carruth 6f4d3a2e39 [msan] Fix a uninitialized-use bug in the template argument diffing
logic.

In one place we would try to check for the difference between integers
even if we were missing one of the integers. This would eventually end
up reading uninitialized data out of the APSInt objects. The fix is to
short circuit the sameness test when we don't have integers on both
sides.

This fixes a test failure I was seeing with MSan. Not sure whether other
bots were seeing it or not, but yay MSan. In particular the feature to
very carefully track origins back through stores throughout the program
was invaluable.

llvm-svn: 226375
2015-01-17 14:20:14 +00:00
Jordan Rose 16ba553f75 ObjC getters with names like "newItem" should still be linked to the @property.
Two years ago I added a compile-time "optimization" to
ObjCMethodDecl::findPropertyDecl: exit early if the current method is part
of a special Objective-C method family (like 'new' or 'init'). However, if a
property (declared with @property) has a name that matches a method family,
the getter picks up that family despite being declared by the property. The
early exit then made ObjCMethodDecl::findPropertyDecl decide that there
was no associated property, despite the method itself being marked as an
accessor. This corrects that by removing the early exit.

This does /not/ change the fact that such a getter is considered to return a
value with a +1 retain count. The best way to eliminate this is by adding the
objc_method_family(none) attribute to the getter, but unlike the existing
ns_returns_not_retained that can't be applied directly to the property -- you
have to redeclare the getter instead.

(It'd be nice if @property just implied objc_method_family(none) for its
getter, but that would be a backwards-incompatible change.)

rdar://problem/19038838

llvm-svn: 226338
2015-01-16 23:04:26 +00:00
Sean Silva 2a995148e8 Fix some copypasta typos in asserts.
Fixes PR22236

Patch by Nicolas Brunie! <nicolas.brunie@kalray.eu>

llvm-svn: 226328
2015-01-16 21:44:26 +00:00
David Majnemer 10fd83d11f AST: alignof might be dependent because of alignment attributes
Dependent alignment attributes should make an alignof expression
dependent as well.

llvm-svn: 226156
2015-01-15 10:04:14 +00:00
David Majnemer f8637360e2 AST: Ensure implicit records have default visibility
Types composed with certain implicit record types would have their RTTI
marked as hidden because the implicit record type didn't have any
visibility.

This manifests itself as triggering false positives from tools like
clang's -fsantize=function feature.  The RTTI for a function type's
return type wouldn't match if the return type was an implicit record
type.

Patch by Stephan Bergmann!

llvm-svn: 226148
2015-01-15 08:41:25 +00:00
Alexey Bataev 19acc3d351 Rename RefersToCapturedVariable to RefersToEnclosingVariableOrCapture, NFC
llvm-svn: 225624
2015-01-12 10:17:46 +00:00