David Majnemer [Mon, 7 Jul 2014 08:09:15 +0000 (08:09 +0000)]
CodeGen: Cleanup MS ABI RTTI LLVM IR
The MS ABI RTTI emission code would choose names for IR types like
%"MSRTTITypeDescriptor\02". This name is undesirable because it
requires escaping; the underlying reason for this is that the name is
unprintable. Fix this by naming it %rtti.TypeDescriptor2.
While here, stop trying to do lookups in the LLVM Module's type table.
Instead, store the IR types in MicrosoftCXXABI. Lookups by name aren't
particularly fast.
Richard Smith [Mon, 7 Jul 2014 06:38:20 +0000 (06:38 +0000)]
Fix an iterator invalidation issue: deserializing a key function can write to
the key functions table. Don't hold references to anything within that table
across such an access.
David Majnemer [Mon, 7 Jul 2014 06:20:47 +0000 (06:20 +0000)]
CodeGen: Refactor RTTI emission
Let's not expose ABI specific minutia inside of CodeGenModule and Type.
Instead, let's abstract it through CXXABI.
This gets rid of:
CodeGenModule::getCompleteObjectLocator,
CodeGenModule::EmitFundamentalTypeDescriptor{s,},
CodeGenModule::getMSTypeDescriptor,
CodeGenModule::getMSCompleteObjectLocator,
CGCXXABI::shouldRTTIBeUnique,
CGCXXABI::classifyRTTIUniqueness.
CGRTTI was *almost* entirely centered around providing Itanium-style
RTTI information. Instead of providing interfaces that only it
consumes, move it to the ItaniumCXXABI implementation file. This allows
it to have access to Itanium-specific implementation details without
providing useless expansion points for the Microsoft ABI side.
Alp Toker [Mon, 7 Jul 2014 06:05:00 +0000 (06:05 +0000)]
Fix layering of file remapping and header search initialization
These two functions initialize the source manager and header search objects and
shouldn't be in InitPreprocessor which is concerned with priming the
preprocessor itself and predefining macros.
StmtDumper.cpp is called ASTDumper.cpp these days, and usually works well
for new AST nodes without changes. There's now DataRecursiveASTVisitor
in addition to RecursiveASTVisitor, and serialization wasn't mentioned.
Sema: Check that __leave is contained in a __try block.
Give scope a SEHTryScope bit, set that in ParseSEHTry(), and let Sema
walk the scope chain to find the SEHTry parent on __leave statements.
(They are rare enough that it seems better to do the walk instead of
giving Scope a SEHTryParent pointer -- this is similar to AtCatchScope.)
The MicrosoftExtensions.c test file should not rely on -x objective-c++. Removed that from the RUN line, fixed obvious C++isms in the code, and moved some C++ tests into MicrosoftExtensions.cpp instead. As a drive-by, changed the line endings for MicrosoftExtensions.c to be LF instead of CRLF.
Alp Toker [Sun, 6 Jul 2014 06:24:00 +0000 (06:24 +0000)]
libclang: make darwin pthread hacks conditional on LLVM_ENABLE_THREADS
Although these aren't strictly related to LLVM's core threading, it's
reasonable to avoid pthread usage in clang when building with
LLVM_ENABLE_THREADS disabled.
CodeGen: add support for a few MSVC ARM intrinsics
This adds support for simple MSVC compatibility mode intrinsics. These
intrinsics are simple in that they are either directly passed through to the
annotated MSBuiltin intrinsic or they mirror existing GCC builtins.
This completes the infrastructure for the new MSBuiltin aliases in the
instruction definitions. These behave similar to the GCCBuiltin in that they
can be implicitly constructed without special handling unless needed.
With this change it is possible to annotate an LLVM intrinsic in the backend
instruction definitions and indicate it as a builtin in the Builtin*.def files
in clang via LANGBUILTIN. That will automatically pass through the instruction
much as a GCCBuiltin.
Note that there is no need for the special handling for ensuring that the
compatibility flag is enabled since the filtering on the LANGBUILTIN will
automatically prevent the intrinsic from bleeding into non-MS compatible
compiler invocations.
Robert Lytton [Thu, 3 Jul 2014 09:30:33 +0000 (09:30 +0000)]
Move the calling of emitTargetMD() later.
Summary:
Because a global created by GetOrCreateLLVMGlobal() is not finalised until later viz:
extern char a[];
char f(){ return a[5];}
char a[10];
Change MangledDeclNames to use a MapVector rather than a DenseMap so that the
Metadata is output in order of original declaration, so to make deterministic
and improve human readablity.
David Majnemer [Thu, 3 Jul 2014 05:51:27 +0000 (05:51 +0000)]
MS ABI: Get linkage of RTTI data correct
The Itanium rules are not appropriate for the MS ABI. RTTI data is
_never_ imported and thus is never available_externally. It is either
internal (if the type's linkage is internal) or linkonce_odr.
This also means that classes which inherit from dllimport'd bases force
their translation unit to duplicate the entirety of the RTTI data of
that base.
Interestingly, the complete object locator can never be referenced by
translation units which import the class.
Enable clang to continue to parse libstdc++4.6 and stlport after r210091.
r210091 made initialization checking more strict in c++11 mode. LWG2193 is
about changing standard libraries to still be valid under these new rules,
but older libstdc++ (e.g. libstdc++4.6 in -D_GLIBCXX_DEBUG=1 mode, or stlport)
do not implement that yet. So fall back to the C++03 semantics for container
classes in system headers below the std namespace.
Fix linkage bug that miscompiled variable templates instantiated from similarly named local types. In essence, this bug ensures that the x<Foo> specialization in function foo() defined as follows differs between two distinct translation units.
static int &foo() {
struct Foo { };
return x<Foo>;
}
This extends the target builtin support to allow language specific annotations
(i.e. LANGBUILTIN). This is to allow MSVC compatibility whilst retaining the
ability to have EABI targets use a __builtin_ prefix. This is merely to allow
uniformity in the EABI case where the unprefixed name is provided as an alias in
the header.
David Majnemer [Wed, 2 Jul 2014 17:26:04 +0000 (17:26 +0000)]
Update the MSVC Compatibility document
It hasn't been updated to reflect the progress we've made. We've fuzz
tested VFTables, VBTables, layout, and RTTI data. We support lambdas
that are compatible with their scheme.
[ASan] Print exact source location of global variables in error reports.
See https://code.google.com/p/address-sanitizer/issues/detail?id=299 for the
original feature request.
Introduce llvm.asan.globals metadata, which Clang (or any other frontend)
may use to report extra information about global variables to ASan
instrumentation pass in the backend. This metadata replaces
llvm.asan.dynamically_initialized_globals that was used to detect init-order
bugs. llvm.asan.globals contains the following data for each global:
1) source location (file/line/column info);
2) whether it is dynamically initialized;
3) whether it is blacklisted (shouldn't be instrumented).
Source location data is then emitted in the binary and can be picked up
by ASan runtime in case it needs to print error report involving some global.
For example:
0x... is located 4 bytes to the right of global variable 'C::array' defined in '/path/to/file:17:8' (0x...) of size 40
These source locations are printed even if the binary doesn't have any
debug info.
This is an ABI-breaking change. ASan initialization is renamed to
__asan_init_v4(). Pre-built libraries compiled with older Clang will not work
with the fresh runtime.
Simon Atanasyan [Wed, 2 Jul 2014 13:20:36 +0000 (13:20 +0000)]
[Driver][Mips] If ABI name is not provided deduce it from the target triple
not from the CPU name. This approach is closer to the method used by gcc driver.
Tim Northover [Wed, 2 Jul 2014 12:56:02 +0000 (12:56 +0000)]
ARM: add support for v8 ldaex/stlex builtins.
ARMv8 adds (to both AArch32 and AArch64) acquiring and releasing
variants of the exclusive operations, in line with the C++11 memory
model.
This adds support for two new intrinsics to expose them to C & C++
developers directly: __builtin_arm_ldaex and __builtin_arm_stlex, in
direct analogy with the versions with no implicit barrier.
Tim Northover [Wed, 2 Jul 2014 10:25:45 +0000 (10:25 +0000)]
X86: inline all atomic operations up to 128-bits.
The backend *can* cope with all of these now, so Clang should give it the
chance. On CPUs without cmpxchg16b (e.g. the original athlon64) LLVM can reform
the libcalls.
Richard Trieu [Wed, 2 Jul 2014 04:39:38 +0000 (04:39 +0000)]
Prevent Clang from crashing on template code.
Fixes PR20110, where Clang hits an assertion failure when it expects that the
sub-expression of a bit cast to pointer to also be a pointer, but gets a value
instead.
David Majnemer [Tue, 1 Jul 2014 22:24:56 +0000 (22:24 +0000)]
Driver: Handle /GR- in a compatible way with MSVC
There are slight differences between /GR- and -fno-rtti which made
mapping one to the other inappropriate.
-fno-rtti disables dynamic_cast, typeid, and does not emit RTTI related
information for the v-table.
/GR- does not generate complete object locators and thus will not
reference them in vftables. However, constructs like dynamic_cast and
typeid are permitted.
This should bring our implementation of RTTI up to semantic parity with
MSVC modulo bugs.
Win64: Disable uwtable until we fix .pdata emission in LLVM
LLVM r211399 started emitting .pdata for win64 by default.
Unfortunately, it produces invalid object files. I plan to fix that
Soon. For now, don't request unwind tables. This fixes the clang-cl
self-host on win64.
David Majnemer [Tue, 1 Jul 2014 20:30:31 +0000 (20:30 +0000)]
MS ABI: Reference MSVC RTTI from the VFTable
The pointer for a class's RTTI data comes right before the VFTable but
has no name. To be properly compatible with this, we do the following:
* Create a single GlobalVariable which holds the contents of the VFTable
_and_ the pointer to the RTTI data.
* Create a GlobalAlias, with appropriate linkage/visibility, that points
just after the RTTI data pointer. This ensures that the VFTable
symbol will always refer to VFTable data.
* Create a Comdat with a "Largest" SelectionKind and stick the private
GlobalVariable in it. By transitivity, the GlobalAlias will be a
member of the Comdat group. Using "Largest" ensures that foreign
definitions without an RTTI data pointer will _not_ be chosen in the
final linked image.
Whether or not we emit RTTI data depends on several things:
* The -fno-rtti flag implies that we should never not emit a pointer to
RTTI data before the VFTable.
* __declspec(dllimport) brings in the VFTable from a remote DLL. Use an
available_externally GlobalVariable to provide a local definition of
the VFTable. This means that we won't have any available_externally
definitions of things like complete object locators. This is
acceptable because they are never directly referenced.
To my knowledge, this completes the implementation of MSVC RTTI code
generation.
Further semantic work should be done to properly support /GR-.
This patch removes the dead code, and refines the
getEHResumeBlock() slightly.
The CleanupHackLevel was a hack to the old exception
handling intrinsics, which have several issues with function
inliner.
Since LLVM 3.0, the new landingpad and resume instructions
are added to LLVM IR. With the new exception handling
mechanism, most of the issues are fixed now. We should
always use these instructions to implement the exception
handling code nowadays, and we don't need the hack any more.
Besides, the `CleanupHackLevel` is a compile-time constant,
thus other cases have been considered as dead code for a while.
Simon Atanasyan [Tue, 1 Jul 2014 10:59:09 +0000 (10:59 +0000)]
[Driver][Mips] MIPS ABI names "32" and "64" used as arguments of the "-mabi"
command line option only. Internally we convert them to the "o32" and "n64"
respectively. So we do not need to refer them anywhere after that conversion.
Enable test/CodeGen/indirect-goto.c in 64b for local arrays
In 32b mode the reference count for block addresses
is not zero. This prevents inlining and constant
folding and causes the test to fail. Changing
the triple allows runnning the test in 64b mode.
The array in foo2 is now local instead of static until
at lower optimization levels the interprocedural constant
propagator is invoked before the global optimizer.
Alp Toker [Tue, 1 Jul 2014 03:19:50 +0000 (03:19 +0000)]
clang-interpreter: use LLVM interpreter if JIT is unavailable
Update the strategy in r212083 to try JIT first and otherwise fall back to the
interpreter. This gives the best of both worlds and still builds fine with no
targets enabled.
Alp Toker [Tue, 1 Jul 2014 02:41:55 +0000 (02:41 +0000)]
clang-interpreter: interpret instead of JITing
Fixes the build when no targets are selected, or no native target is built.
This also better matches up with the description/title of the example and
demonstrates how clang can be used to run C++ on constrained environments
without file IO or executable memory permissions (e.g. iOS apps).
A comment is added explaining how to extend the demo with JIT support as
needed.
Alexey Samsonov [Mon, 30 Jun 2014 20:27:16 +0000 (20:27 +0000)]
[UBSan] Don't link UBSan runtime into shared libraries.
It used to be a feature of UBSan (it could sanitize a standalone
shared object instead of the whole program), but now it causes
more problems, like PR20165.
Ben Langmuir [Mon, 30 Jun 2014 20:04:14 +0000 (20:04 +0000)]
Consider module depedencies when checking a preamble in libclang
Add module dependencies (header files, module map files) to the list of
files to check when deciding whether to rebuild a preamble. That fixes
using preambles with module imports so long as they are in
non-overridden files.
My intent is to use to unify the existing dependency collectors to the
new “DependencyCollectory” interface from this commit, starting with the
DependencyFileGenerator.