Commit Graph

77263 Commits

Author SHA1 Message Date
Erik Pilkington e3cd735ea6 Add a new attribute, fortify_stdlib
This attribute applies to declarations of C stdlib functions
(sprintf, memcpy...) that have known fortified variants
(__sprintf_chk, __memcpy_chk, ...). When applied, clang will emit
calls to the fortified variant functions instead of calls to the
defaults.

In GCC, this is done by adding gnu_inline-style wrapper functions,
but that doesn't work for us for variadic functions because we don't
support __builtin_va_arg_pack (and have no intention to).

This attribute takes two arguments, the first is 'type' argument
passed through to __builtin_object_size, and the second is a flag
argument that gets passed through to the variadic checking variants.

rdar://47905754

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

llvm-svn: 353765
2019-02-11 23:21:39 +00:00
Eli Friedman 88fccbdea7 [Sema] Mark GNU compound literal array init as an rvalue.
Basically the same issue as string init, except it didn't really have
any visible consequences before I removed the implicit lvalue-to-rvalue
conversion from CodeGen.

While I'm here, a couple minor drive-by cleanups: IgnoreParens never
returns a ConstantExpr, and there was a potential crash with string init
involving a ChooseExpr.

The analyzer test change maybe indicates we could simplify the analyzer
code a little with this fix?  Apparently a hack was added to support
lvalues in initializers in r315750, but I'm not really familiar with the
relevant code.

Fixes regression reported in the kernel build at
https://bugs.llvm.org/show_bug.cgi?id=40430#c6 .

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

llvm-svn: 353762
2019-02-11 22:54:27 +00:00
Heejin Ahn 9d5a089bf5 [WebAssembly] Make thread-related options consistent
Summary:
There have been three options related to threads and users had to set
all three of them separately to get the correct compilation results.
This makes sure the relationship between the options makes sense and
sets necessary options for users if only part of the necessary options
are specified. This does:

- Remove `-matomics`; this option alone does not enable anything, so
  removed it to not confuse users.
- `-mthread-model posix` sets `-target-feature +atomics`
- `-pthread` sets both `-target-feature +atomics` and
  `-mthread-model posix`
Also errors out when explicitly given options don't match, such as
`-pthread` is given with `-mthread-model single`.

Reviewers: dschuff, sbc100, tlively, sunfish

Subscribers: jgravelle-google, jfb, cfe-commits

Tags: #clang

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

llvm-svn: 353761
2019-02-11 22:47:50 +00:00
Nico Weber 346f1e97a9 Fix a few tests that were missing ':' on CHECK lines and weren't testing anything.
Found by `git grep '\/\/ CHECK-[^: ]* ' clang/test/ | grep -v RUN:`.

Also tweak CodeGenCXX/arm-swiftcall.cpp to still pass now that it checks more.

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

llvm-svn: 353744
2019-02-11 20:33:22 +00:00
Petr Hosek 7c8952197b [CodeGen] Set construction vtable visibility after creating initializer
We must only set the construction vtable visibility after we create the
vtable initializer, otherwise the global value will be treated as
declaration rather than definition and the visibility won't be set.

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

llvm-svn: 353742
2019-02-11 20:13:42 +00:00
Tom Tan 42b2424e4f [COFF, ARM64] Remove definitions for _byteswap library functions
_byteswap_* functions are are implemented in below file as normal function
from libucrt.lib and declared in stdlib.h. Define them in intrin.h triggers
lld error "conflicting comdat type" and "duplicate symbols" which was just
added to LLD (https://reviews.llvm.org/D57324).

C:\Program Files (x86)\Windows Kits\10\Source\10.0.17763.0\ucrt\stdlib\byteswap.cpp

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

llvm-svn: 353740
2019-02-11 20:04:02 +00:00
Nico Weber 2e12dce406 Attempt to pacify bots more after r353718 and r353725
llvm-svn: 353729
2019-02-11 18:01:27 +00:00
Nico Weber d7cc3b3908 Attempt to pacify bots after r353718
llvm-svn: 353725
2019-02-11 17:30:25 +00:00
Nico Weber 9bbb721eb2 Make test actually test something (colons were missing)
llvm-svn: 353718
2019-02-11 16:37:02 +00:00
Alexander Kornienko 9a857d2075 Fixed header underline in docs.
+ Removed trailing whitespace.

llvm-svn: 353711
2019-02-11 15:17:13 +00:00
Serge Guelton 3331b6eab3 [tools] Fix python DeprecationWarning: invalid escape sequence
The python documentation says "it’s highly recommended that you use raw strings for all but the simplest expressions." (https://docs.python.org/3/library/re.html)

So do that with the attached patch generated by

    sed -i -e "s/re.search('/re.search(r'/g" $(git grep -l 're.search(')

The warning can be seen in e.g. python3.7:

    $ python3.7 -Wd
    >>> import re; re.search('\s', '')
    <stdin>:1: DeprecationWarning: invalid escape sequence \s

Commited on behalf of Marco Falke.
Differential Revision: https://reviews.llvm.org/D57528

llvm-svn: 353707
2019-02-11 15:03:17 +00:00
Benjamin Kramer 756ecb8e44 Make some helper functions static. NFC.
llvm-svn: 353705
2019-02-11 14:52:15 +00:00
Kristof Umann 8d23999639 [analyzer] New checker for detecting usages of unsafe I/O functions
There are certain unsafe or deprecated (since C11) buffer handling
functions which should be avoided in safety critical code. They
could cause buffer overflows. A new checker,
'security.insecureAPI.DeprecatedOrUnsafeBufferHandling' warns for
every occurrence of such functions (unsafe or deprecated printf,
scanf family, and other buffer handling functions, which now have
a secure variant).

Patch by Dániel Kolozsvári!

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

llvm-svn: 353698
2019-02-11 13:46:43 +00:00
Fangrui Song 0783406120 Format isInSystemMacro after D55782
llvm-svn: 353697
2019-02-11 13:30:04 +00:00
Kadir Cetinkaya 0468fc0b8d [clang][Index] Add a knob to index function parameters in declarations
Summary:
Parameters in declarations are useful for clangd, so that we can
provide symbol information for them as well. It also helps clangd to be
consistent whether a function's definition is accessible or not.

Reviewers: hokein, akyrtzi

Subscribers: ilya-biryukov, ioeric, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 353695
2019-02-11 13:02:21 +00:00
Sven van Haastregt dc2c93017f [libclang] Add attribute support for 'convergent'.
This bumps CINDEX_VERSION_MINOR up (to 51).

Patch by Hsin-Hsiao Lin.

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

llvm-svn: 353690
2019-02-11 11:00:56 +00:00
Gabor Marton 0e04ebdcda [ASTImporter] Add test RedeclChainShouldBeCorrectAmongstNamespaces
Summary:
We add a new test to show that redecl chains are not handled properly
amongst namespaces. We cannot pass this test now, so this is disabled.
Subsequent patches will make this test pass.

Reviewers: a_sidorin, shafik, a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 353684
2019-02-11 10:27:58 +00:00
Petr Hosek f8067f79dc [CMake][Fuchsia] Drop libclang.so from distribution
This is no longer needed now that all users have switched to clangd.

llvm-svn: 353658
2019-02-11 05:38:01 +00:00
Brad Smith 09699a7603 long double is double on OpenBSD/NetBSD/PPC.
Patch by George Koehler.

llvm-svn: 353656
2019-02-11 02:53:16 +00:00
Reid Kleckner 4b96530f8c Fix test to pass on LLP64 targets
llvm-svn: 353654
2019-02-10 20:20:26 +00:00
Reid Kleckner 5bbdfeace6 Fix clang tests broken by r353547 that depend on InstrProf
llvm-svn: 353653
2019-02-10 20:17:07 +00:00
Fangrui Song 9ac13a1244 Use llvm::is_contained. NFC
llvm-svn: 353635
2019-02-10 05:54:57 +00:00
James Y Knight 751fe286dc [opaque pointer types] Cleanup CGBuilder's Create*GEP.
The various EltSize, Offset, DataLayout, and StructLayout arguments
are all computable from the Address's element type and the DataLayout
which the CGBuilder already has access to.

After having previously asserted that the computed values are the same
as those passed in, now remove the redundant arguments from
CGBuilder's Create*GEP functions.

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

llvm-svn: 353629
2019-02-09 22:22:28 +00:00
David L. Jones 191ba3cc03 [StaticAnalyzer] Add missing include to SMTAPI.h. [NFC]
This include is needed for types within SMTAPI.h. (It's very possible that
compilation would succeed without it, but that's only by chance.)

llvm-svn: 353599
2019-02-09 02:41:55 +00:00
Eli Friedman 041adb0ed0 Fix buildbot failure from r353569.
I assumed lvalue-to-rvalue conversions of array type would never
happen, but apparently clang-tidy tries in some cases.

llvm-svn: 353598
2019-02-09 02:22:17 +00:00
Artem Dergachev 37625f3485 [analyzer] Add a comment that FunctionCodeRegions may also need canonicalization
llvm-svn: 353592
2019-02-09 01:00:32 +00:00
Mikhail R. Gadelha 3289ccd848 This reverts commit 1440a848a635849b97f7a5cfa0ecc40d37451f5b.
and commit a1853e834c65751f92521f7481b15cf0365e796b.

They broke arm and aarch64

llvm-svn: 353590
2019-02-09 00:46:12 +00:00
Stanislav Mekhanoshin 1607a37308 [AMDGPU] Split dot-insts feature
Differential Revision: https://reviews.llvm.org/D57972

llvm-svn: 353588
2019-02-09 00:34:41 +00:00
Artem Dergachev 9197056419 [analyzer] CStringSyntaxChecks: Fix an off-by-one error in the strlcat() check.
oth strlcat and strlcpy cut off their safe bound for the argument value
at sizeof(destination). There's no need to subtract 1 in only one
of these cases.

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

rdar://problem/47873212

llvm-svn: 353583
2019-02-08 23:59:52 +00:00
Adrian Prantl 7b6b9a1afc -gmodules: Don't emit incomplete breadcrumbs pointing to nonexistant PCM files.
When a module name is specified as -fmodule-name, that module gets a
clang::Module object, but it won't actually be built or imported; it
will be textual. CGDebugInfo wouldn't detect this and them emit a
DICompileUnit that had a hash but no name and that confused both
dsymutil, LLDB, and myself.

rdar://problem/47926508

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

llvm-svn: 353578
2019-02-08 23:15:42 +00:00
Volodymyr Sapsai 1570571ded [CodeGen][ObjC] Fix assert on calling `__builtin_constant_p` with ObjC objects.
When we are calling `__builtin_constant_p` with ObjC objects of
different classes, we hit the assertion

> Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file include/llvm/Support/Casting.h, line 254.

It happens because LLVM types for `ObjCInterfaceType` are opaque and
have no name (see `CodeGenTypes::ConvertType`). As the result, for
different ObjC classes we have different `is_constant` intrinsics with
the same name `llvm.is.constant.p0s_s`. When we try to reuse an
intrinsic with the same name, we fail because of type mismatch.

Fix by bitcasting `ObjCObjectPointerType` to `id` prior to passing as an
argument to `__builtin_constant_p`. This results in using intrinsic
`llvm.is.constant.p0i8` and correct types.

rdar://problem/47499250

Reviewers: rjmccall, ahatanak, void

Reviewed By: void, ahatanak

Subscribers: ddunbar, jkorous, hans, dexonsmith, cfe-commits

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

llvm-svn: 353577
2019-02-08 23:02:13 +00:00
Eli Friedman 7f98e3c288 [CodeGen][NFC] Update comments in CGExprConstant.cpp.
llvm-svn: 353571
2019-02-08 21:36:04 +00:00
Eli Friedman 3bf72d7d64 [Sema] Make string literal init an rvalue.
This allows substantially simplifying the expression evaluation code,
because we don't have to special-case lvalues which are actually string
literal initialization.

This currently throws away an optimization where we would avoid creating
an array APValue for string literal initialization.  If we really want
to optimize this case, we should fix APValue so it can store simple
arrays more efficiently, like llvm::ConstantDataArray.  This shouldn't
affect the memory usage for other string literals.  (Not sure if this is
a blocker; I don't think string literal init is common enough for this
to be a serious issue, but I could be wrong.)

The change to test/CodeGenObjC/encode-test.m is a weird side-effect of
these changes: we currently don't constant-evaluate arrays in C, so the
strlen call shouldn't be folded, but lvalue string init managed to get
around that check.  I this this is fine.

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

llvm-svn: 353569
2019-02-08 21:18:46 +00:00
Adrian Prantl 57e60a501e Fix typo
llvm-svn: 353568
2019-02-08 21:13:25 +00:00
George Karpenkov 2add627e35 [analyzer] Opt-in C Style Cast Checker for OSObject pointers
Differential Revision: https://reviews.llvm.org/D57261

llvm-svn: 353566
2019-02-08 21:09:00 +00:00
Akira Hatanaka 67b1b451b5 Pass the base element type of an array type to the visit method instead
of the array type itself.

This fixes a bug found by inspection that was introduced in r353459. I
don't have a test case for this since we don't yet have types that would
make the containing C struct non-trivial to copy/move but wouldn't make
it non-trivial to default-initialize or destruct.

llvm-svn: 353556
2019-02-08 19:46:53 +00:00
Craig Topper be4cbe8726 [X86] Add explicit alignment to __m128/__m128i/__m128d/etc. to allow matching of MSVC behavior with #pragma pack.
Summary:
With MSVC, #pragma pack is ignored when there is explicit alignment. This differs from gcc. Clang emulates this difference when compiling for Windows.

It appears that MSVC and its headers consider the __m128/__m128i/__m128d/etc. types to be explicitly aligned and ignores #pragma pack for them. Since we don't have explicit alignment on them in our headers, we don't match the MSVC behavior here.

This patch adds explicit alignment to match this behavior. I'm hoping this won't cause any problems when we're not emulating MSVC. But if someone knows of something that would be different we can swith to conditionally adding the alignment based on _MSC_VER.

I had to add explicitly unaligned types as well so we could use them in the loadu/storeu intrinsics which use __attribute__(__packed__). Using the now explicitly aligned types wouldn't produce align 1 accesses when targeting Windows.

Reviewers: rnk, erichkeane, spatel, RKSimon

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 353555
2019-02-08 19:45:08 +00:00
Alexey Bataev c416e64731 [OPENMP]Delay emission of the error messages for the exceptions.
Fixed diagnostic emission for the exceptions support in case of the
compilation of OpenMP code for the devices. From now on, it uses delayed
diagnostics mechanism, previously used for CUDA only. It allow to
diagnose not allowed used of exceptions only in functions that are going
to be codegen'ed.

llvm-svn: 353542
2019-02-08 18:02:25 +00:00
Alexey Bataev 346fb4bbcd Revert "[OPENMP]Initial support for the delayed diagnostics."
This reverts commit r353540. Erroneously committed, need to fix the
message and description.

llvm-svn: 353541
2019-02-08 17:42:00 +00:00
Alexey Bataev 5e62adad0d [OPENMP]Initial support for the delayed diagnostics.
It is important to delay the emission of the diagnostic messages for the
functions unless it is proved that the function is going to be used on
the device side. It is required to support compilation with some of the
target-specific system headers.

llvm-svn: 353540
2019-02-08 17:38:09 +00:00
Yitzhak Mandelbaum 8a43680217 [ASTMatchers][NFC] Update comments on assorted `CXXMemberCallExpr` matchers.
Specifically:

* fixes the comments on `hasObjectExpression`,
* clarifies comments on `thisPointerType` and `on`,
* adds comments to `onImplicitObjectArgument`.

It also updates associated reference docs (using the doc tool).

Reviewers: alexfh, steveire, aaron.ballman

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

llvm-svn: 353532
2019-02-08 16:00:44 +00:00
Ben Hamilton 30b7d09d7a [Format/ObjC] Fix [foo bar]->baz formatting as lambda arrow
Summary:
Currently, `UnwrappedLineParser` thinks an arrow token after
an ObjC method expression is a C++ lambda arrow, so it formats:

```
[foo bar]->baz
```

as:

```
[foo bar] -> baz
```

Because `UnwrappedLineParser` runs before `TokenAnnotator`, it can't
know if the arrow token is after an ObjC method expression or not.

This diff makes `TokenAnnotator` remove the TT_LambdaArrow on
the arrow token if it follows an ObjC method expression.

Test Plan: New test added. Ran test with:
  % ninja FormatTests && ./tools/clang/unittests/Format/FormatTests
  Confirmed test failed before diff and passed after diff.

Reviewers: krasimir, djasper, sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 353531
2019-02-08 15:55:18 +00:00
James Y Knight f5f1b0e59e [opaque pointer types] Cleanup CGBuilder's Create*GEP.
Some of these functions take some extraneous arguments, e.g. EltSize,
Offset, which are computable from the Type and DataLayout.

Add some asserts to ensure that the computed values are consistent
with the passed-in values, in preparation for eliminating the
extraneous arguments. This also asserts that the Type is an Array for
the calls named "Array" and a Struct for the calls named "Struct".

Then, correct a couple of errors:

1. Using CreateStructGEP on an array type. (this causes the majority
   of the test differences, as struct GEPs are created with i32
   indices, while array GEPs are created with i64 indices)

2. Passing the wrong Offset to CreateStructGEP in TargetInfo.cpp on
   x86-64 NACL (which uses 32-bit pointers).

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

llvm-svn: 353529
2019-02-08 15:34:12 +00:00
Gabor Marton a9cab318e7 [ASTImporter][ASTImporterSpecificLookup] Add test for different operators
Summary:
This is to check that operators are handled properly in
`ASTImporterSpecificLookup`.  Note, this lookup table is not used in LLDB, only
in CTU.

Reviewers: a_sidorin, shafik, a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 353505
2019-02-08 09:19:34 +00:00
Gabor Marton fc638d64e8 [AST] Fix structural inequivalence of operators
Summary: Operators kind was not checked, so we reported e.g. op- to be equal with op+

Reviewers: shafik, a_sidorin, aaron.ballman

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 353504
2019-02-08 08:55:32 +00:00
JF Bastien b347e75258 Variable auto-init: fix __block initialization
Summary:
Automatic initialization [1] of __block variables was trampling over the block's
headers after they'd been initialized, which caused self-init usage to crash,
such as here:

  typedef struct XYZ { void (^block)(); } *xyz_t;
  __attribute__((noinline))
  xyz_t create(void (^block)()) {
    xyz_t myself = malloc(sizeof(struct XYZ));
    myself->block = block;
    return myself;
  }
  int main() {
    __block xyz_t captured = create(^(){ (void)captured; });
  }

This type of code shouldn't be broken by variable auto-init, even if it's
sketchy.

[1] With -ftrivial-auto-var-init=pattern

<rdar://problem/47798396>

Reviewers: rjmccall, pcc, kcc

Subscribers: jkorous, dexonsmith, cfe-commits

Tags: #clang

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

llvm-svn: 353495
2019-02-08 01:29:17 +00:00
Eli Friedman 3189d5f48c [COFF, ARM64] Fix types for _ReadStatusReg, _WriteStatusReg
r344765 added those intrinsics, but used the wrong types.

Patch by Mike Hommey

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

llvm-svn: 353493
2019-02-08 01:17:49 +00:00
JF Bastien ddeb2f2a16 [NFC] Variable auto-init: use getAsVariableArrayType helper
As suggested by @rjmccall in D57797.

llvm-svn: 353490
2019-02-08 00:51:05 +00:00
Jiong Wang 862e7405e8 bpf: teach BPF driver about the new CPU "v3"
This patch simply teach BPF driver about the new CPU "v3" introduced in
LLVM backend.

Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
llvm-svn: 353479
2019-02-07 22:51:56 +00:00
Akira Hatanaka 5fbdccd834 [Sema][ObjC] Disallow non-trivial C struct fields in unions.
This patch fixes a bug where clang doesn’t reject union fields of
non-trivial C struct types. For example:

```
// This struct is non-trivial under ARC.
struct S0 {
  id x;
};

union U0 {
  struct S0 s0; // clang should reject this.
  struct S0 s1; // clang should reject this.
};

void test(union U0 a) {
  // Previously, both 'a.s0.x' and 'a.s1.x' were released in this
  // function.
}
```

rdar://problem/46677858

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

llvm-svn: 353459
2019-02-07 20:21:46 +00:00