PR16752: 'mode' attribute for unusual targets doesn't work properly
Description:
Troubles could be happened due to some assumptions in handleModeAttr function (see SemaDeclAttr.cpp).
For example, it assumes that 32 bit integer is 'int', while it could be 16 bit only.
Instead of asking target: 'which type do you want to use for int32_t ?' it just hardcodes general opinion. That doesn't looks pretty correct.
Please consider the next solution:
1. In Basic/TargetInfo add getIntTypeByWidth and getRealTypeByWidth methods. Methods asks target for proper type for given bit width.
2. Fix handleModeAttr according to new methods in TargetInfo.
Fixes:
1st Commit (Done): Add new methods for TargetInfo:
getRealTypeByWidth and getIntTypeByWidth
for ASTContext names are almost same(invokes new methods from TargetInfo):
getIntTypeForBitwidth and getRealTypeForBitwidth
Separate popcnt and sse4.2 feature control somewhat to match gcc behavior.
Enabling sse4.2 will implicitly enable popcnt unless popcnt is explicitly disabled.
Disabling sse4.2 will not disable popcnt if popcnt is explicitly enabled.
Eli Friedman [Tue, 10 Sep 2013 03:05:56 +0000 (03:05 +0000)]
Make -Wunused warning rules more consistent.
This patch does a few different things.
This patch improves unused var diags for const vars: we no longer
unconditionally suppress diagnostics for const vars, instead only suppressing
the diagnostic when the declaration appears to be useful.
This patch also makes us more consistently use whether a variable/function
is declared in the main file to suppress diagnostics where appropriate.
Ignore calling conventions when checking function template specializations
Summary:
Calling conventions are inherited during decl merging. Before this
change, deduction would fail due to a type mismatch between the template
and the specialization. This change adjusts the CCs to match before
deduction, and lets the decl merging logic diagnose mismatch or inherit
the CC from the template.
This allows specializations of static member function templates in the
Microsoft C++ ABI.
Attribute tablegen now understands that attribute arguments can be optional. This allows for automated checking of the number of arguments expected vs number of arguments given for attributes. Greatly reduces the amount of manual checking required.
Modern ObjectiveC translator. Fix translation of
message sent to aggregate-valued methods. Fix
visibility of trampoline type used in translation
of such expressions. // rdar://14932320
Sean Silva [Mon, 9 Sep 2013 19:50:47 +0000 (19:50 +0000)]
[docs] End users should see just "Clang"
Half the internet has wildly incorrect ideas about what LLVM is (in
particular, many get the impression that LLVM is some magical
cross-platform runtime), so saying "LLVM" near "cross-compilation" in a
user-facing doc might provoke confusion.
Richard Smith [Mon, 9 Sep 2013 16:55:27 +0000 (16:55 +0000)]
C++ modules: if a class is defined in multiple modules (for instance, because
it is an implicit instantiation of a class template specialization), pick the
first-loaded definition to be the canonical definition, and merge all other
definitions into it.
This is still rather incomplete -- we need to extend every form of declaration
that can appear within a CXXRecordDecl to be redeclarable if it came from an
AST file (this includes fields, enumerators, ...).
Removing the endian attribute and updating associated test cases. This functionality was never completely implemented, and this is an improvement over silently eating the attribute.
David Tweed [Mon, 9 Sep 2013 09:55:07 +0000 (09:55 +0000)]
Commit 190296 missed out the tests; add them now. Note that it actually tests
"long long" which is currently technically only "reserved for future" use in OpenCL, but
since clang in OpenCL mode supports it we may as well test the modifications to
the settings made for that type.
David Tweed [Mon, 9 Sep 2013 09:17:24 +0000 (09:17 +0000)]
The OpenCL standard specifies the sizes and alignments of various types than other C-family
languages, as well as specifying errno is not set by the math functions. Make the
clang front-end set those appropriately when the OpenCL language option is set.
Richard Smith [Mon, 9 Sep 2013 07:34:56 +0000 (07:34 +0000)]
C++ modules: fix a bug where loading a declaration with some name would prevent
name lookup from lazily deserializing the other declarations with the same
name, by tracking a bit to indicate whether a name in a DeclContext might have
additional external results. This also allows lazier reconciling of the lookup
table if a module import adds decls to a pre-existing DC.
However, this exposes a pre-existing bug, which causes a regression in
test/Modules/decldef.mm: if we have a reference to a declaration, and a
later-imported module adds a redeclaration, nothing causes us to load that
redeclaration when we use or emit the reference (which can manifest as a
reference to an undefined inline function, a use of an incomplete type, and so
on). decldef.mm has been extended with an additional testcase which fails with
or without this change.
Daniel Jasper [Sun, 8 Sep 2013 14:07:57 +0000 (14:07 +0000)]
clang-format: Keep empty lines and format 1-line nested blocks.
Let clang-format consistently keep up to one empty line (configured via
FormatStyle::MaxEmptyLinesToKeep) in nested blocks, e.g. lambdas. Also,
actually format single statements in nested blocks.
Before:
DEBUG({ int i; });
DEBUG({
int i;
// an empty line here would just be removed.
int j;
});
Update the link to the current code coverage reports (the previous one has not been updated since february 2010) + remove the spec references, not updated since May 2010
David Majnemer [Sat, 7 Sep 2013 06:59:46 +0000 (06:59 +0000)]
AST: __uuidof should leak through templated types
Summary:
__uuidof on templated types should exmaine if any of its template
parameters have a uuid declspec. If exactly one does, then take it.
Otherwise, issue an appropriate error.
Fix missing source location in CXXTemporaryObjectExpr nodes.
For clarity, renamed (get/set)ParenRange as (get/set)ParenOrBraceRange
in CXXConstructExpr nodes.
Added testcase.
ObjectiveC migrator: When inferring a property,
preserve getter's attribute. Also, do not attach
an inferred NS_RETURNS_INNER_POINTER to the inferred
property (it is illegal).
Hal Finkel [Fri, 6 Sep 2013 23:45:10 +0000 (23:45 +0000)]
Reorder libm LIBBUILTIN definition groups
The groups of libm LIBBUILTIN definitions are reordered to match the order of
the corresponding __builtin_* definitions (which occur earlier in the
Builtins.def file).
Hal Finkel [Fri, 6 Sep 2013 23:23:32 +0000 (23:23 +0000)]
Add the missing "n" to libm LIBBUILTIN definitions
The libm math functions should be marked with the "n" (nothrow) flag so that
the corresponding IR function declarations are tagged with the nounwind
attribute (this has been true in C mode, but not in C++ mode).
The test case has been updated to run in C++ mode in addition to in C mode.
Richard Smith [Fri, 6 Sep 2013 22:30:28 +0000 (22:30 +0000)]
Remove error-prone 'list initialization' flag from an implicit conversion
sequence. All that matters here is whether we're doing the
std::initializer_list special case thing.
Hans Wennborg [Fri, 6 Sep 2013 20:26:25 +0000 (20:26 +0000)]
clang-cl: ignore /RTC options (PR17129)
I don't think Clang intends to implement this functionality.
ASan should be used instead. Since /RTC is often passed by default
from MSBuild, ignore the option to avoid bloating the output.
Hans Wennborg [Fri, 6 Sep 2013 16:48:57 +0000 (16:48 +0000)]
Remove unused method Job::AddCommand.
I was going to update the comment referring to PipedJob, which was removed
some time ago, but then it turned out that this method is not actually used
at all.
Jordan Rose [Fri, 6 Sep 2013 16:12:41 +0000 (16:12 +0000)]
[analyzer] SATestBuild: strip trailing newlines from command file.
When running a make-based command, SATestBuild tries to append a -jN flag
with an appropriate N to run the build in parallel. However, it failed
to take into account that each line read includes a trailing newline
(unless it is the last line of a file without a trailing newline), which
resulted in the "-jN" appearing on a line on its own.
Re-add logic to prevent breaking after an empty set of parentheses.
Basically it seems that calling a function without parameters is more
like navigating along the same object than it is a separate step of a
builder-type call.
We might need to extends this in future to allow "short" parameters that
e.g. are an index accessing a specific element.
Pavel Labath [Fri, 6 Sep 2013 08:12:48 +0000 (08:12 +0000)]
Avoid double edges when constructing CFGs
Summary:
If a noreturn destructor is executed while returning a value from a function,
the resulting CFG has had two edges to the exit block. This crashed the analyzer,
because it expects that blocks with no terminators have only one outgoing edge.
I added code to avoid creating the second edge in this case.
PS: The crashes did not manifest themselves always, as usually the
NoReturnFunctionChecker would stop program evaluation before the analyzer hit
the assertion, but in the case of lifetime extended temporaries, the checker
failed to do that (which is a separate bug in itself).
Daniel Jasper [Fri, 6 Sep 2013 07:54:20 +0000 (07:54 +0000)]
clang-format: Fix comment formatting bugs in nested blocks.
This fixes two issues:
1) The indent of a line comment was not adapted to the subsequent
statement as it would be outside of a nested block.
2) A missing DryRun flag caused actualy breaks to be inserted in
overly long comments while trying to come up with the best line
breaking decisions.
David Blaikie [Fri, 6 Sep 2013 06:45:04 +0000 (06:45 +0000)]
PR17046, PR17092: Debug Info assert-on-valid due to member loss when context creation recreates the item the context is created for
By removing the possibility of strange partial definitions with no
members that older GCC's produced for the otherwise unreferenced outer
types of referenced inner types, we can simplify debug info generation
and correct this bug. Newer (4.8.1 and ToT) GCC's don't produce this
quirky debug info, and instead produce the full definition for the outer
type (except in the case where that type is dynamic and its vtable is
not emitted in this TU).
During the creation of the context for a type, we may revisit that type
(due to the need to visit template parameters, among other things) and
used to end up visiting it first there. Then when we would reach the
original code attempting to define that type, we would lose debug info
by overwriting its members.
By avoiding the possibility of latent "defined with no members" types,
we can be sure than whenever we already have a type in a cache (either a
definition or declaration), we can just return that. In the case of a
full definition, our work is done. In the case of a partial definition,
we must already be in the process of completing it. And in the case of a
declaration, the completed/vtable/etc callbacks can handle converting it
to a definition.
Eli Friedman [Fri, 6 Sep 2013 03:13:09 +0000 (03:13 +0000)]
Add self-comparison warnings for fields.
This expands very slightly what -Wtautological-compare considers to be
tautological to include implicit accesses to C++ fields and ObjC ivars.
I don't want to turn this into a full expression-identity check, but
these additions seem pretty well-contained, and maintain the theme
of checking for "x == x".
Richard Smith [Fri, 6 Sep 2013 01:22:42 +0000 (01:22 +0000)]
When creating an implicit conversion sequence for a reference of type T from an
initializer list containing a single element of type T, be sure to mark the
sequence as a list conversion sequence so that it is known to be worse than an
implicit conversion sequence that initializes a std::initializer_list object.
Eli Friedman [Fri, 6 Sep 2013 01:13:30 +0000 (01:13 +0000)]
Reduce stack usage of TreeTransform.
Without this patch, TreeTransform::TransformExpr uses a ridiculous amount of
stack space (around 5000 bytes). Preventing inlining brings the stack usage
down to something sane.
On a testcase I have, on my computer, this allows changing -ftemplate-depth
from 210 to around 750 before we crash. I'm not sure I should commit the
testcase, though: I don't want to cause test failures on platforms with less
stack space available.
Eli Friedman [Thu, 5 Sep 2013 23:51:03 +0000 (23:51 +0000)]
Improve error for "override" + non-virtual func.
Consider something like the following:
struct X {
virtual void foo(float x);
};
struct Y : X {
void foo(double x) override;
};
The error is almost certainly that Y::foo() has the wrong signature,
rather than incorrect usage of the override keyword. This patch
adds an appropriate diagnostic for that case.
ObjectiveC migrator: tighten the rules for when
inferring NS_RETURNS_RETAINED, etc., return annotations.
Do not infer if these annotations are implicit
from the naming convention. Also add inference for
NS_CONSUMES_SELF annotation.
James Dennett [Thu, 5 Sep 2013 17:46:21 +0000 (17:46 +0000)]
Mark lambda closure classes as being implicitly-generated.
Summary: Closure classes for C++ lambdas are always compiler-generated. This one-line change calls setImplicit(true) on them at creation time, such that a default RecursiveASTVisitor (or any for which shouldVisitImplicitCode returns false) will skip them.
Hans Wennborg [Thu, 5 Sep 2013 17:05:56 +0000 (17:05 +0000)]
clang-cl: Use .obj as extension for unnamed object files (PR17095)
We already use .obj as extension when the user provides a stem file
name (via /Fo), but were failing in the most basic case when the file
name is based on the input file.
Handle zero-width and double-width characters in string literals and comments.
Summary:
Count column width instead of the number of code points. This also
includes correct handling of tabs inside string literals and comments (with an
exception of multiline string literals/comments, where tabs are present before
the first escaped newline).
Fix bug #17104 - Target info for GNU/kFreeBSD were missing.
As a result, Clang doesn't define the pre-processor macros that are expected
on this platform.
Add new methods for TargetInfo:
getRealTypeByWidth and getIntTypeByWidth
for ASTContext names are almost same(invokes new methods from TargetInfo):
getIntTypeForBitwidth and getRealTypeForBitwidth.
As first commit for PR16752 fix: 'mode' attribute for unusual targets doesn't work properly
Description:
Troubles could be happened due to some assumptions in handleModeAttr function (see SemaDeclAttr.cpp).
For example, it assumes that 32 bit integer is 'int', while it could be 16 bit only.
Instead of asking target: 'which type do you want to use for int32_t ?' it just hardcodes general opinion. That doesn't looks pretty correct.
Please consider the next solution:
1. In Basic/TargetInfo add getIntTypeByWidth and getRealTypeByWidth virtual methods. By default current behaviour could be implemented here.
2. Fix handleModeAttr according to new methods in TargetInfo.
This approach is implemented in the patch attached to this post.
Fixes:
1st Commit (Current): Add new methods for TargetInfo:
getRealTypeByWidth and getIntTypeByWidth
for ASTContext names are almost same(invokes new methods from TargetInfo):
getIntTypeForBitwidth and getRealTypeForBitwidth