Bob Wilson [Thu, 27 Feb 2014 21:59:17 +0000 (21:59 +0000)]
Remove an assertion that no longer holds. <rdar://problem/16135814>
In r201528, I changed the PGO instrumentation counter for a "do" loop to not
include the fall-through count. That fall-through count is included later, b
it means that this assertion may fail for "do" loops.
Ted Kremenek [Thu, 27 Feb 2014 21:56:47 +0000 (21:56 +0000)]
[-Wunreachable-code] always treat 'case:' and 'default:' cases as reachable.
This is a heuristic. Many switch statements, although they look covered
over an enum, may actually handle at runtime more values than in the enum.
This is overly conservative, as there are some cases that clearly
can be ruled as being clearly unreachable, e.g. 'switch (42) { case 1: ... }'.
We can refine this later.
John McCall [Thu, 27 Feb 2014 20:30:49 +0000 (20:30 +0000)]
Diagnose attempts to apply ms_struct to records with base classes
or virtual functions, but permit that error to be downgraded to
a warning (with -Wno-error=incompatible-ms-struct), and officially
support this kind of dual, ABI-mixing layout.
The basic problem here is that projects which use ms_struct are often
not very circumspect about what types they annotate; for example,
some projects enable the pragma in a prefix header and then only
selectively disable it around system header inclusions. They may
only care about binary compatibility with MSVC for a subset of
those structs, but that doesn't mean they have no binary
compatibility concerns at all for the rest; thus we are essentially
forced into supporting this hybrid ABI. But it's reasonable for
us to at least point out the places where we're not making
any guarantees.
The original diagnostic was for dynamic classes, i.e. those with
virtual functions or virtual bases; I've extended it to include
all classes with bases, because we are not actually making any
attempt to duplicate MSVC's base subobject layout in ms_struct
(and it is indeed quite different from Itanium, even for
non-virtual bases).
Reid Kleckner [Thu, 27 Feb 2014 19:40:09 +0000 (19:40 +0000)]
MS ABI: Fix vftable mangling by using the vbtable name algorithm
Summary:
This merges VFPtrInfo and VBTableInfo into VPtrInfo, since they hold
almost the same information. With that change, the vbtable mangling
code can easily be applied to vftable data and we magically get the
correct, unambiguous vftable names.
Ben Langmuir [Thu, 27 Feb 2014 19:14:03 +0000 (19:14 +0000)]
Remove constructors from FileEntry that prevent owning resources
This cleans up some constructors that would not be safe once FileEntry
owns the storage for its name. These were already suspect, since they
wouldn't work if the FileEntry had an open file descriptor. The only
user for these constructors was in UniqueFileContainer, which wasn't a
very useful abstraction anyway. So it and UniqueDirContainer have been
replaced with std::map<UniqueID, *>.
This change should not affect anything outside the FileManager.
Rafael Espindola [Thu, 27 Feb 2014 19:01:11 +0000 (19:01 +0000)]
Use private linkage for globals we already name with \01L and \01l.
In llvm the only semantic difference between internal and private is that llvm
tries to hide private globals my mangling them with a private prefix. Since
the globals changed by this patch already had the magic don't mangle marker,
there should be no change in the generated assembly.
A followup patch should then be able to drop the \01L and \01l prefixes and let
llvm mangle as appropriate.
Alexey Samsonov [Thu, 27 Feb 2014 09:09:39 +0000 (09:09 +0000)]
[CMake] Teach build system to build/test compiler-rt with a just-built Clang
With this change, one may set LLVM_BUILD_EXTERNAL_COMPILER_RT option
to build compiler-rt libraries with just-built Clang.
make compiler-rt
in the build tree will build all compiler-rt libraries with just-built Clang
and copy them to the proper location in the Clang resource directory.
make check-compiler-rt
will run the compiler-rt test suite using just-built Clang and runtime
libraries.
The goal is to make LLVM_BUILD_EXTERNAL_COMPILER_RT the default, so that
we can always build compiler-rt libraries with Clang, not the host compiler,
and for all the platforms Clang can target.
[ASTUnit] Fix use-after-free bug in ASTUnit::getMainBufferWithPrecompiledPreamble().
With r197755 we started reading the contents of buffer file entries, but the
buffers may point to ASTReader blobs that have been disposed.
Fix this by having the CompilerInstance object keep a reference to the ASTReader
as well as having the ASTContext keep reference to the ExternalASTSource.
This was very difficult to construct a test case for.
rdar://16149782
Ted Kremenek [Thu, 27 Feb 2014 01:28:58 +0000 (01:28 +0000)]
Add category test case for attribute 'objc_protocol_requires_explicit_implementation'.
This test also illustrates that checking for properties is not working properly with
this attribute, as we are missing a diagnostic for a property not being implemented.
Ben Langmuir [Thu, 27 Feb 2014 00:25:12 +0000 (00:25 +0000)]
Add a 'use-external-names' option to VFS overlay files
When true, sets the name of the file to be the name from
'external-contents'. Otherwise, you get the virtual path that the file
was looked up by. This will not affect any non-virtual paths, or fully
virtual paths (for which there is no reasonable 'external' name anyway).
The setting is available globally, but can be overriden on a per-file
basis.
The goal is that this setting will control which path you see in debug
info, diagnostics, etc. which are sensitive to which path is used. That
will come in future patches that pass the name through to FileManager.
Ted Kremenek [Thu, 27 Feb 2014 00:24:00 +0000 (00:24 +0000)]
Rework CFG edges to encode potentially unreachable edges, instead of just making them NULL.
This is to support some analyses, like -Wunreachable-code, that
will need to recover the original unprunned CFG edges in order
to suppress issues that aren't really bugs in practice.
There are two important changes here:
- AdjacentBlock replaces CFGBlock* for CFG successors/predecessors.
This has the size of 2 pointers, instead of 1. This is unlikely
to have a significant memory impact on Sema since a single
CFG usually exists at one time, but could impact the memory
usage of the static analyzer. This could possibly be optimized
down to a single pointer with some cleverness.
- Predecessors can now contain null predecessors, which means
some analyses doing a reverse traversal will need to take into
account. This already exists for successors, which contain
successor slots for specific branch kinds (e.g., 'if') that
expect a fixed number of successors, even if a branch is
not reachable.
Reid Kleckner [Thu, 27 Feb 2014 00:03:39 +0000 (00:03 +0000)]
PR18962: Fix "Unable to find record layout information for type"
Clang is using llvm::StructType::isOpaque() as a way of signaling if
we've finished record type conversion in
CodeGenTypes::isRecordLayoutComplete(). However, Clang was setting the
body of the type before it finished laying out the type as a base type.
Laying out the %class.C.base LLVM type attempts to convert more types,
eventually recursively attempting to layout 'C' again, at which point we
would say that layout was complete, even though we were still in the
middle of it.
By not setting the body, we correctly signal that layout is not
complete, and things work as expected.
At some point, it might be worth refactoring this to avoid looking at
the LLVM IR types under construction.
Rafael Espindola [Wed, 26 Feb 2014 22:25:45 +0000 (22:25 +0000)]
Refactor linkage computation in CGObjCMac.cpp.
Before this patch the globals were created with the wrong linkage and patched
afterwards. From the comments it looks like something would complain about
having an internal GV with no initializer. At least in clang the verifier will
only run way after we set the initializer, so that is not a problem.
This patch should be a nop. It just figures out the linkage earlier and
converts the old calls to setLinkage to asserts. The only case where that is
not possible is when we first see a weak import that is then implemented. In
that case we have to change the linkage, but that is the only setLinkage left.
NAKAMURA Takumi [Wed, 26 Feb 2014 06:53:16 +0000 (06:53 +0000)]
[CMake] Use target_link_libraries(INTERFACE|PRIVATE) on CMake-2.8.12 to increase opportunity for parallel build.
target_link_libraries(INTERFACE) doesn't bring inter-target dependencies in add_library,
although final targets have dependencies to whole dependent libraries.
It makes most libraries can be built in parallel.
target_link_libraries(PRIVATE) is used to shaared library.
Each dependent library is linked to the target.so, and its user will not see its grandchildren.
For example,
- libclang.so has sufficient libclang*.a(s).
- c-index-test requires just only libclang.so.
FIXME: lld is tweaked minimally. Adding INTERFACE in each library would be better thing.
Richard Trieu [Wed, 26 Feb 2014 02:36:06 +0000 (02:36 +0000)]
PR16074, implement warnings to catch pointer to boolean true and pointer to
null comparison when the pointer is known to be non-null.
This catches the array to pointer decay, function to pointer decay and
address of variables. This does not catch address of function since this
has been previously used to silence a warning.
Pointer to bool conversion is under -Wbool-conversion.
Pointer to null comparison is under -Wtautological-pointer-compare, a sub-group
of -Wtautological-compare.
void foo() {
int arr[5];
int x;
// warn on these conditionals
if (foo);
if (arr);
if (&x);
if (foo == null);
if (arr == null);
if (&x == null);
Richard Trieu [Wed, 26 Feb 2014 01:17:28 +0000 (01:17 +0000)]
Add -Wabsolute-value, warnings about absolute value functions.
The warnings fall into three groups.
1) Using an absolute value function of the wrong type, for instance, using the
int absolute value function when the argument is a floating point type.
2) Using the improper sized absolute value function, for instance, using abs
when the argument is a long long. llabs should be used instead.
From these two cases, an implicit conversion will occur which may cause
unexpected behavior. Where possible, suggest the proper absolute value
function to use, and which header to include if the function is not available.
3) Taking the absolute value of an unsigned value. In addition to this warning,
suggest to remove the function call. This usually indicates a logic error
since the programmer assumed negative values would have been possible.
Roman Divacky [Tue, 25 Feb 2014 18:35:30 +0000 (18:35 +0000)]
Give sparcv9 the ability to set the target cpu. Change it from accepting
-march which doesnt exist on sparc gcc to -mcpu. While here adjust a
few tests to not write an unused temporary file.
Reid Kleckner [Tue, 25 Feb 2014 18:08:48 +0000 (18:08 +0000)]
MS ABI: Just use getTypeInfoInChars to get the field size
This was changed to use manual desugaring and multiplication in r201832
and fixed for multi-dimensional arrays in r201917. However, it breaks
down in the presence of typedefs. Rather than attempting to handle all
the desugaring, just go back to calling the generic type info code.
This was discovered while compiling SIInstrWaits.cpp in the R600
backend.
Benjamin Kramer [Tue, 25 Feb 2014 17:26:26 +0000 (17:26 +0000)]
Pretty Printer: Fix printing of conversion operator decls and calls.
- Don't emit anything when we encounter a call to a conversion operator.
"bar(a & b)" instead of "bar(a & b.operator int())"
This preserves the semantics and is still idempotent if we print the AST multiple times.
- Properly print declarations of conversion operators.
"explicit operator bool();" instead of "bool operator _Bool();"
Tim Northover [Tue, 25 Feb 2014 13:53:01 +0000 (13:53 +0000)]
AArch64: use different type modifier in arm_neon.td
The 'f' modifier is designed for integer type arguments really (according to
its documentation). It's better to use the "half width, same number" modifier.
Add documentation for these attributes, it includes:
- Motivation for their existence.
- Examples on how to use them.
- Examples on how to misuse them.
which not only simplifies reading and writing these files (for humans),
but makes it possible to easily modify locations via textual
replacement, which would not have worked in the old scheme.
Reid Kleckner [Tue, 25 Feb 2014 00:59:14 +0000 (00:59 +0000)]
MS ABI: Return sret parameters when using inalloca
Previously the X86 backend would look for the sret attribute and handle
this for us. inalloca takes that all away, so we have to do the return
ourselves now.
David Majnemer [Mon, 24 Feb 2014 23:34:17 +0000 (23:34 +0000)]
Sema: Make getPreferredTypeAlign respect alignments specified with an aligned attribute on a typedef
When calculating the preferred alignment of a type, consider if a alignment
attribute came from a typedef declaration. If one did, do not naturally align
the type.
Patch by Stephan Tolksdorf, with a little tweaking and an additional testcase by me.
Richard Smith [Mon, 24 Feb 2014 20:50:36 +0000 (20:50 +0000)]
If preprocessing results in a token with leading whitespace that was expanded
from a macro in column 0, ensure that we print whitespace before it in the -E
output. Patch by Harald van Dijk!
Richard Smith [Mon, 24 Feb 2014 20:45:00 +0000 (20:45 +0000)]
If the first token in a macro that appears at the start of a line expands to
nothing, be sure to inform the *next* token expanded from the macro that it is
now at the start of a line. Patch by Harald van Dijk!