Commit Graph

70790 Commits

Author SHA1 Message Date
Alex Lorenz f5ca27cc37 [refactor] allow the use of refactoring diagnostics
This commit allows the refactoring library to use its own set of
refactoring-specific diagnostics to reports things like initiation errors.

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

llvm-svn: 315924
2017-10-16 18:28:26 +00:00
Alex Lorenz 528435002a clang-refactor: Use llvm_unreachable in an unused override
As suggested by David Blaikie!

llvm-svn: 315923
2017-10-16 18:07:16 +00:00
Evgeniy Stepanov d5d36a162d Do not link clang_rt.cfi on Android.
Summary:
The OS provides cross-dso CFI support starting with Android O.
Trapping mode does not require any runtime at all, and diagnostic mode
requires just ubsan-standalone.

Reviewers: pcc

Subscribers: srhines, cfe-commits

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

llvm-svn: 315921
2017-10-16 18:02:57 +00:00
Alex Lorenz e1b7b95901 Recommit r315738 "[clang-refactor] Apply source replacements"
The fixed commit ensures that ParsedSourceRange works correctly
with Windows paths.

Original message:

This commit actually brings clang-refactor to a usable state as it can now
apply the refactoring changes to source files.
The -selection option is now also fully supported.

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

llvm-svn: 315918
2017-10-16 17:31:16 +00:00
Wei Mi 9b3d627280 [Bitfield] Add an option to access bitfield in a fine-grained manner.
Currently all the consecutive bitfields are wrapped as a large integer unless there is unamed zero sized bitfield in between. The patch provides an alternative manner which makes the bitfield to be accessed as separate memory location if it has legal integer width and is naturally aligned. Such separate bitfield may split the original consecutive bitfields into subgroups of consecutive bitfields, and each subgroup will be wrapped as an integer. Now This is all controlled by an option -ffine-grained-bitfield-accesses. The alternative of bitfield access manner can improve the access efficiency of those bitfields with legal width and being aligned, but may reduce the chance of load/store combining of other bitfields, so it depends on how the bitfields are defined and actually accessed to choose when to use the option. For now the option is off by default.

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

llvm-svn: 315915
2017-10-16 16:50:27 +00:00
Jonas Hahnfeld e2c342fc65 [CUDA] Require libdevice only if needed
If the user passes -nocudalib, we can live without it being present.
Simplify the code by just checking whether LibDeviceMap is empty.

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

llvm-svn: 315902
2017-10-16 13:31:30 +00:00
Haojian Wu 6f60ff84cd [clang-rename] Add function unit tests.
Summary:
Also contain a fix:

* Fix a false positive of renaming a using shadow function declaration.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, mgorny, cfe-commits

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

llvm-svn: 315898
2017-10-16 10:37:42 +00:00
Krasimir Georgiev 35599fdfa0 [clang-format] Break non-trailing comments, try 2
Summary:
This patch enables `BreakableToken` to manage the formatting of non-trailing
block comments. It is a refinement of https://reviews.llvm.org/D37007.
We discovered that the optimizer outsmarts us on cases where breaking the comment
costs considerably less than breaking after the comment. This patch addresses
this by ensuring that a newline is inserted between a block comment and the next
token.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 315893
2017-10-16 09:08:53 +00:00
Roman Lebedev 6de129e710 [Sema] Re-land: Diagnose tautological comparison with type's min/max values
The first attempt, rL315614 was reverted because one libcxx
test broke, and i did not know at the time how to deal with it.

Summary:
Currently, clang only diagnoses completely out-of-range comparisons (e.g. `char` and constant `300`),
and comparisons of unsigned and `0`. But gcc also does diagnose the comparisons with the
`std::numeric_limits<>::max()` / `std::numeric_limits<>::min()` so to speak

Finally Fixes https://bugs.llvm.org/show_bug.cgi?id=34147
Continuation of https://reviews.llvm.org/D37565

Reviewers: rjmccall, rsmith, aaron.ballman

Reviewed By: rsmith

Subscribers: rtrieu, jroelofs, cfe-commits

Tags: #clang

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

llvm-svn: 315875
2017-10-15 20:13:17 +00:00
Alexander Richardson 6d989436d0 Convert clang::LangAS to a strongly typed enum
Summary:
Convert clang::LangAS to a strongly typed enum

Currently both clang AST address spaces and target specific address spaces
are represented as unsigned which can lead to subtle errors if the wrong
type is passed. It is especially confusing in the CodeGen files as it is
not possible to see what kind of address space should be passed to a
function without looking at the implementation.
I originally made this change for our LLVM fork for the CHERI architecture
where we make extensive use of address spaces to differentiate between
capabilities and pointers. When merging the upstream changes I usually
run into some test failures or runtime crashes because the wrong kind of
address space is passed to a function. By converting the LangAS enum to a
C++11 we can catch these errors at compile time. Additionally, it is now
obvious from the function signature which kind of address space it expects.

I found the following errors while writing this patch:

- ItaniumRecordLayoutBuilder::LayoutField was passing a clang AST address
  space to  TargetInfo::getPointer{Width,Align}()
- TypePrinter::printAttributedAfter() prints the numeric value of the
  clang AST address space instead of the target address space.
  However, this code is not used so I kept the current behaviour
- initializeForBlockHeader() in CGBlocks.cpp was passing
  LangAS::opencl_generic to TargetInfo::getPointer{Width,Align}()
- CodeGenFunction::EmitBlockLiteral() was passing a AST address space to
  TargetInfo::getPointerWidth()
- CGOpenMPRuntimeNVPTX::translateParameter() passed a target address space
  to Qualifiers::addAddressSpace()
- CGOpenMPRuntimeNVPTX::getParameterAddress() was using
  llvm::Type::getPointerTo() with a AST address space
- clang_getAddressSpace() returns either a LangAS or a target address
  space. As this is exposed to C I have kept the current behaviour and
  added a comment stating that it is probably not correct.

Other than this the patch should not cause any functional changes.

Reviewers: yaxunl, pcc, bader

Reviewed By: yaxunl, bader

Subscribers: jlebar, jholewinski, nhaehnle, Anastasia, cfe-commits

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

llvm-svn: 315871
2017-10-15 18:48:14 +00:00
Martell Malone 4806f70060 Fix test case regresstion from rL315864
The patch should have been checking against STDCXX17 not STDCXX14.

llvm-svn: 315868
2017-10-15 18:01:28 +00:00
Martell Malone e5639e9dd9 Driver: use ld64.lld when -fuse-ld=lld for darwin
When using lld on macOS the current level of detection between ld and
ld64 forces us to rename lld to ld.

For ELF targets we have the ld.lld alias so for MACHO we should have
ld64.lld so we can use lld without replacing the system compiler.

This also solves the additional issue of cross compiling for MACHO
where renaming lld to ld with only target ELF.

This is the clang driver component change to use this new alias.

Reviewers: ruiu, rnk

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

llvm-svn: 315867
2017-10-15 17:53:45 +00:00
Martell Malone f6f6a9c199 [driver] [cl] Add/fix c++17/c++latest
Patch by: daxpedda

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

llvm-svn: 315864
2017-10-15 17:27:58 +00:00
Aaron Ballman 606093a53b Add -f[no-]double-square-bracket-attributes as new driver options to control use of [[]] attributes in all language modes. This is the initial implementation of WG14 N2165, which is a proposal to add [[]] attributes to C2x, but also allows you to enable these attributes in C++98, or disable them in C++11 or later.
llvm-svn: 315856
2017-10-15 15:01:42 +00:00
Benjamin Kramer 8b54a1c686 [Lex] Remove unused variables. No functionality change.
llvm-svn: 315845
2017-10-15 04:27:37 +00:00
Faisal Vali b7c0b089f2 [c++2a] Fix failing regression test related to not adding the extension warning to a diagnostic group (in r315840)
In passing also complete a comment that I left uncompleted.

For ease of reference, here's the parent commit: https://reviews.llvm.org/rL315840

llvm-svn: 315842
2017-10-15 02:13:17 +00:00
Faisal Vali 1826842865 [c++2a] Implement P0306 __VA_OPT__ (Comma omission and comma deletion)
This patch implements an extension to the preprocessor:

__VA_OPT__(contents) --> which expands into its contents if variadic arguments are supplied to the parent macro, or behaves as an empty token if none.

  - Currently this feature is only enabled for C++2a (this could be enabled, with some careful tweaks, for other dialects with the appropriate extension or compatibility warnings)

  - The patch was reviewed here: https://reviews.llvm.org/D35782 and asides from the above (and moving some of the definition and expansion recognition logic into the corresponding state machines), I believe I incorporated all of Richard's suggestions.

A few technicalities (most of which were clarified through private correspondence between rsmith, hubert and thomas) are worth mentioning.  Given:

    #define F(a,...) a #__VA_OPT__(a ## a)  a ## __VA_OPT__(__VA_ARGS__)

    - The call F(,) Does not supply any tokens for the variadic arguments and hence VA_OPT behaves as a placeholder.
    - When expanding VA_OPT (for e.g. F(,1) token pasting occurs eagerly within its contents if the contents need to be stringified.
    - A hash or a hashhash prior to VA_OPT does not inhibit expansion of arguments if they are the first token within VA_OPT.
    - When a variadic argument is supplied, argument substitution occurs within the contents as does stringification - and these resulting tokens are inserted back into the macro expansions token stream just prior to the entire stream being rescanned and concatenated.

See wg21.link/P0306 for further details on the feature.


Acknowledgment: This patch would have been poorer if not for Richard Smith's usual thoughtful analysis and feedback.
llvm-svn: 315840
2017-10-15 01:26:26 +00:00
Konstantin Zhuravlyov 202c1b715f Revert "Mark test as unsupported until r315808 is fixed"
Test is fixed in r315830

llvm-svn: 315831
2017-10-14 22:24:31 +00:00
Bruno Cardoso Lopes b37d05c9c1 Mark test as unsupported until r315808 is fixed
This is causing:
http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/43381

llvm-svn: 315829
2017-10-14 22:14:23 +00:00
Benjamin Kramer 2b8ad7312d Re-land r315787, "[Sema] Warn about unused variables if we can constant evaluate the initializer."
The warnings in libc++ tests were fixed in the meantime.

llvm-svn: 315811
2017-10-14 15:59:34 +00:00
NAKAMURA Takumi 93638b751a Revert rL315787, "[Sema] Warn about unused variables if we can constant evaluate the initializer."
check-libcxx dislikes it.

llvm-svn: 315806
2017-10-14 14:46:04 +00:00
Yaxun Liu 98f0c43f85 Fix build failure on android due to missing std::to_string()
llvm-svn: 315805
2017-10-14 12:51:52 +00:00
Yaxun Liu c2a87a05f1 [OpenCL] Emit enqueued block as kernel
In OpenCL the kernel function and non-kernel function has different calling conventions.
For certain targets they have different argument ABIs. Also kernels have special function
attributes and metadata for runtime to launch them.

The blocks passed to enqueue_kernel is supposed to be executed as kernels. As such,
the block invoke function should be emitted as kernel with proper calling convention and
argument ABI.

This patch emits enqueued block as kernel. If a block is both called directly and passed
to enqueue_kernel, separate functions will be generated.

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

llvm-svn: 315804
2017-10-14 12:23:50 +00:00
Benjamin Kramer 819ec01ce3 [Sema] Warn about unused variables if we can constant evaluate the initializer.
If the variable construction can be constant evaluated it doesn't have
side effects, so removing it is always safe. We only try to evaluate
variables that are unused, there should be no impact on compile time.

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

llvm-svn: 315787
2017-10-14 01:30:49 +00:00
Vedant Kumar aa4ea5fb45 [ubsan] Don't emit function signatures for non-static member functions
The function sanitizer only checks indirect calls through function
pointers. This excludes all non-static member functions (constructor
calls, calls through thunks, etc. all use a separate code path). Don't
emit function signatures for functions that won't be checked.

Apart from cutting down on code size, this should fix a regression on
Linux caused by r313096. For context, see the mailing list discussion:

r313096 - [ubsan] Function Sanitizer: Don't require writable text segments

Testing: check-clang, check-ubsan

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

llvm-svn: 315786
2017-10-14 01:23:30 +00:00
Alex Lorenz d5bf436d3a [Lex] Avoid out-of-bounds dereference in SkipLineComment
Credit to OSS-Fuzz for discovery:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3145

rdar://34526482

llvm-svn: 315785
2017-10-14 01:18:30 +00:00
Richard Smith 40e202f7d9 Fix backwards warning for use of C++17 attributes-on-namespaces-and-enumerators feature.
llvm-svn: 315784
2017-10-14 00:56:24 +00:00
George Karpenkov cb24b14995 Allow building libFuzzer tests in two-stage compiler-rt build.
llvm-svn: 315776
2017-10-13 23:50:53 +00:00
Alex Lorenz 9ce566fc18 Revert r315738
The ParsedSourceRange class does not work correctly on Windows with the ':'
drive separators

llvm-svn: 315774
2017-10-13 22:47:44 +00:00
Benjamin Kramer 17ba669ad9 [Sema] Avoid iterator invalidation when code completing.
It's possible for the code completion consumer to add new decls to the
current scope while lookup happens on it. Avoid this by making a copy
first.

Sadly I wasn't able to get a self-contained test case for this as it
requires code completion + precompiled preamble + the stars aligning to
deserialize at exactly the right time.

llvm-svn: 315772
2017-10-13 22:14:34 +00:00
George Karpenkov a3cd5247b3 Allow building libFuzzer in two-stage compiler-rt build
When LLVM_BUILD_EXTERNAL_COMPILER_RT option is set to true,
all of projects in compiler-rt are built with a freshly-built compiler using
a recursive CMake invocation.
(e.g. that's how compiler-rt is used in Swift)

Just now I have noticed that libFuzzer binaries were missing in such a case,
and ninja fuzzer returned "no such target", while ninja asan worked just fine.

To my surprise, the list of allowed targets was actually hardcoded in Clang!
While the current setup is clearly suboptimal, for the lack of a better fix
I'm just adding `fuzzer` to a list of `compiler-rt` targets.

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

llvm-svn: 315771
2017-10-13 22:03:09 +00:00
Alex Lorenz 3e3dd1dbd7 Fix -Woverloaded-virtual warning in clang-refactor
llvm-svn: 315755
2017-10-13 21:15:25 +00:00
Artem Dergachev cd25c38dc0 [analyzer] pr28449: Fix support for various array initializers.
In some cases the analyzer didn't expect an array-type variable to be
initialized with anything other than a string literal. The patch essentially
removes the assertion, and ensures relatively sane behavior.

There is a bigger problem with these initializers. Currently our memory model
(RegionStore) is being ordered to initialize the array with a region that
is assumed to be storing the initializer rvalue, and it guesses to copy
the contents of that region to the array variable. However, it would make
more sense for RegionStore to receive the correct initializer in the first
place. This problem isn't addressed with this patch.

rdar://problem/27248428
Differential Revision: https://reviews.llvm.org/D23963

llvm-svn: 315750
2017-10-13 20:54:56 +00:00
Artem Dergachev db65f969f2 [analyzer] CStringChecker: pr34460: Avoid a crash when a cast is not modeled.
The checker used to crash when a mempcpy's length argument is symbolic. In this
case the cast from 'void *' to 'char *' failed because the respective
ElementRegion that represents cast is hard to add on top of the existing
ElementRegion that represents the offset to the last copied byte, while
preseving a sane memory region structure.

Additionally, a few test cases are added (to casts.c) which demonstrate problems
caused by existing sloppy work we do with multi-layer ElementRegions. If said
cast would be modeled properly in the future, these tests would need to be
taken into account.

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

llvm-svn: 315742
2017-10-13 20:11:00 +00:00
Saleem Abdulrasool 52dbdc04fe Basic: adjust attributes on `nan` LIBBUILTINs
The `nan` family of functions will inspect the contents of the parameter
that they are passed. As a result, the function cannot be annotated as
`const`.  The documentation of the `const` attribute explicitly states
this:
  Note that a function that has pointer arguments and examines the data
  pointed to must not be declared const.
Adjust the annotations on this family of functions.

llvm-svn: 315741
2017-10-13 20:07:30 +00:00
Ivan A. Kosarev ce601eedf6 Revert "[CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info", r315731.
With this change we fail on the clang-x86_64-linux-selfhost-modules builder.

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

llvm-svn: 315739
2017-10-13 19:55:01 +00:00
Alex Lorenz 57e060b309 [clang-refactor] Apply source replacements
This commit actually brings clang-refactor to a usable state as it can now
apply the refactoring changes to source files.
The -selection option is now also fully supported.

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

llvm-svn: 315738
2017-10-13 19:42:05 +00:00
Artem Dergachev 2041cbdcf5 [analyzer] RetainCount: Ignore annotations on user-made CFRetain wrappers.
It is not uncommon for the users to make their own wrappers around
CoreFoundation's CFRetain and CFRelease functions that are defensive
against null references. In such cases CFRetain is often incorrectly
marked as CF_RETURNS_RETAINED. Ignore said annotation and treat such
wrappers similarly to the regular CFRetain.

rdar://problem/31699502
Differential Revision: https://reviews.llvm.org/D38877

llvm-svn: 315736
2017-10-13 19:10:42 +00:00
Ivan A. Kosarev 0e528202b8 [CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info
Differential Revision: https://reviews.llvm.org/D38796

llvm-svn: 315731
2017-10-13 18:40:18 +00:00
Craig Topper 9c6a31ae1d [X86] Remove 'knm' defines from predefined-arch-macros.c test.
Direction seems to be that we dont' want to keep adding these, but I forgot to remove it from the test before I committed r315723.

llvm-svn: 315729
2017-10-13 18:38:10 +00:00
Craig Topper f8c10aa3a3 [X86] Add skeleton support for knm cpu
This adds support Knights Mill CPU. Preprocessor defines match gcc's implementation.

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

llvm-svn: 315723
2017-10-13 18:14:24 +00:00
Ivan A. Kosarev cbee219700 [CodeGen] emitOMPArraySectionBase() to generate TBAA info along with LValue base info
Differential Revision: https://reviews.llvm.org/D38795

llvm-svn: 315715
2017-10-13 17:34:18 +00:00
Bruno Cardoso Lopes 7ccaff7db0 Revert "[lit] Raise the logic for enabling clang & lld substitutions to llvm."
This reverts commit r315627, fixing bot failures:
http://green.lab.llvm.org/green/job/clang-stage1-configure-RA

LIT is failing to properly apply substitution to debuginfo-tests
after this change.

rdar://problem/34979568

llvm-svn: 315712
2017-10-13 17:11:13 +00:00
Ivan A. Kosarev 78f486d136 [CodeGen] getNaturalTypeAlignment() to generate TBAA info along with LValue base info
This patch should not bring in any functional changes.

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

llvm-svn: 315708
2017-10-13 16:58:30 +00:00
Reid Kleckner 65fa869c23 [SEH] Use the SEH personality on frontend-outlined funclets
This allows __try inside __finally to work.

Fixes PR34939

llvm-svn: 315707
2017-10-13 16:55:14 +00:00
Ivan A. Kosarev 1590fd3aa8 [CodeGen] EmitLoadOfReference() to generate TBAA info along with LValue base info
This patch should not bring in any functional changes.

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

llvm-svn: 315705
2017-10-13 16:50:50 +00:00
Ivan A. Kosarev 9029564e8c [CodeGen] EmitLoadOfPointer() to generate TBAA info along with LValue base info
This patch should not bring in any functional changes.

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

llvm-svn: 315704
2017-10-13 16:47:22 +00:00
Ivan A. Kosarev 229a6d8d17 [CodeGen] EmitCXXMemberDataPointerAddress() to generate TBAA info along with LValue base info
This patch should not bring in any functional changes.

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

llvm-svn: 315702
2017-10-13 16:38:32 +00:00
Reid Kleckner e257e18b1c Hide "#pragma optimize("", off)" from clang when it pretends to be MSVC 2017
These pragmas work around a bug in VC 1911 that isn't present in clang,
and clang warns about them.

llvm-svn: 315699
2017-10-13 16:18:32 +00:00
Haojian Wu 5b5c81f683 Fix an unused-variable warning.
llvm-svn: 315689
2017-10-13 15:37:53 +00:00