Commit Graph

131 Commits

Author SHA1 Message Date
Alexander Musman 8e261be911 Fix assertion in inline assembler IR gen
Several inputs may not refer to one output constraint in inline assembler
insertions, clang was failing on assertion on such test case.

llvm-svn: 248158
2015-09-21 14:41:00 +00:00
Aaron Ballman 6924dcdf6f Add a new frontend warning for referencing members from the handler of a constructor or destructor function-try-block, which is UB in C++.
This corresponds to the CERT secure coding rule ERR53-CPP.

llvm-svn: 246548
2015-09-01 14:49:24 +00:00
Artem Belevich 5ef02c2db7 [CUDA] Check register names on appropriate side of cuda compilation only.
Differential Revision: http://reviews.llvm.org/D11950

llvm-svn: 246193
2015-08-27 19:54:21 +00:00
Reid Kleckner 14e96b4930 [ms-inline-asm] Add field access to MS inline asm identifier lookup
Now we can parse code like this:
  struct A {
    int field;
  };
  int f(A o) {
    __asm mov eax, o.field
  }

Fixes PR19117.

llvm-svn: 246088
2015-08-26 21:57:20 +00:00
Andrey Bokhanko d9eab9cc13 Additional fix for PR14269: Crash on vector elements / global register vars in inline assembler.
Compiler crashed when vector elements / global register vars were used in inline assembler with "m" restriction. This patch fixes this.

Differential Revision: http://reviews.llvm.org/D10476

llvm-svn: 243870
2015-08-03 10:38:10 +00:00
Alexey Bataev 91e5860fad [X86, inlineasm] Improve analysis of x,Y0,Yi,Ym,Yt,L,e,Z,s asm constraints (patch by Alexey Frolov)
Improve Sema checking of 9 existing inline asm constraints (‘x’, ‘Y*’, ‘L’, ‘e’, ‘Z’, ‘s’).
Differential Revision: http://reviews.llvm.org/D10536

llvm-svn: 242665
2015-07-20 12:08:00 +00:00
Sunil Srivastava 780e50187b Fixed 22941: Integer template parameter as immediate 'I' expectes an integer constant
Basically fixed premature testing of integer constraints during template parsing
Reviewed at http://reviews.llvm.org/D10452

llvm-svn: 242175
2015-07-14 18:08:50 +00:00
Alexander Musman eae29e247e Fix for PR14269: Clang crashes when a bit field is used as inline assembler
input / output with memory constraint.
One generally can't get address of a bit field, so the general solution is to
error on such cases. GCC does the same.

Patch by Andrey Bokhanko

Differential Revision: http://reviews.llvm.org/D10086

llvm-svn: 239153
2015-06-05 13:40:59 +00:00
Artem Belevich fa62ad4087 [cuda] Ignore "TLS unsupported by target" errors for host variables during device compilation.
During device-side CUDA compilation clang currently complains about
all TLS variables, regardless of whether they are __host__ or
__device__.

This patch suppresses "TLS unsupported" errors for host variables
during device compilation and for device variables during host
compilation.

Differential Revision: http://reviews.llvm.org/D9269

llvm-svn: 235907
2015-04-27 19:37:53 +00:00
Artem Belevich 5196fe7c19 Ignore device-side asm constraint errors while compiling CUDA code for host and vice versa.
Differential Revision: http://reviews.llvm.org/D8392

llvm-svn: 232747
2015-03-19 18:40:25 +00:00
Akira Hatanaka 96a36017f7 [inlineasm] Fix an incorrect warning about register constraint and modifier.
Previously, when the following piece of code was compiled, clang would
incorrectly warn that the size of "wide_two" does not match register size
specified by the constraint and modifier":

long wide_two = two;
asm ("%w0 %1" : "+r" (one), "+r"(wide_two));

This was caused by a miscalculation of ConstraintIdx in Sema::ActOnGCCAsmStmt.

This commit fixes PR21270 and rdar://problem/18668354.

llvm-svn: 228089
2015-02-04 00:27:13 +00:00
Weiming Zhao 71ac240620 Diagnose CXX 'this' pointer reference in funcs with naked attr
Clang asserts for this pointer reference in asms of naked functions.
This patch diagnoses if this pointer reference is used.

Differential Revision: http://reviews.llvm.org/D7329

llvm-svn: 228052
2015-02-03 22:35:58 +00:00
Joerg Sonnenberger a43872ccdd When reporting constraints that should be constant, the type doesn't
really help. Improve diagnostics.

llvm-svn: 226863
2015-01-22 21:01:00 +00:00
Saleem Abdulrasool a2823578e6 Sema: analyze I,J,K,M,N,O constraints
Add additional constraint checking for target specific behaviour for inline
assembly constraints.  We would previously silently let all arguments through
for these constraints.  In cases where the constraints were violated, we could
end up failing to select instructions and triggering assertions or worse,
silently ignoring instructions.

llvm-svn: 225244
2015-01-06 04:26:34 +00:00
David Majnemer 04b78412ad Sema: Permit array l-values in asm output operands
GCC permits array l-values in asm output operands even though they
aren't modifiable l-values.  We used to permit it but this behavior
regressed in r224916.

llvm-svn: 224918
2014-12-29 10:29:53 +00:00
David Majnemer 0f4d641005 Sema: Only permit permit modifiable l-values as asm output params
Functions are l-values in C++ but shouldn't be available as output
parameters in inline assembly.  Neither should overloaded function
l-values.

This fixes PR21949.

llvm-svn: 224916
2014-12-29 09:30:33 +00:00
David Majnemer c63fa612e4 Sema: Forbid inconsistent constraint alternatives
Verify that asm constraints have the same number of alternatives

llvm-svn: 224911
2014-12-29 04:09:59 +00:00
David Majnemer b3e96f700e Parse: Concatenated string literals should be verified in inline asm
While we would correctly handle asm("foo") and reject asm(L"bar"), we
weren't careful to handle cases where an ascii literal could be
concatenated with a wide literal.

This fixes PR21822.

llvm-svn: 223992
2014-12-11 01:00:48 +00:00
Ehsan Akhgari 4292443101 ms-inline-asm: Correctly mark MS inline ASM labels as used
Summary: This fixes PR21155.

Test Plan: The patch includes a test.

Reviewers: rnk

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D5619

llvm-svn: 219322
2014-10-08 17:28:34 +00:00
Hans Wennborg e9d240af44 Disallow using function parameters in extended asm inputs or outputs in naked functions (PR21178)
Clang won't emit any prologues for such functions, so it would assert trying to
codegen the parameter references.

This patch makes Clang check the extended asm inputs and outputs for
references to function parameters.

Differential Revision: http://reviews.llvm.org/D5640

llvm-svn: 219272
2014-10-08 01:58:02 +00:00
Ehsan Akhgari 31097581aa ms-inline-asm: Scope inline asm labels to functions
Summary:
This fixes PR20023.  In order to implement this scoping rule, we piggy
back on the existing LabelDecl machinery, by creating LabelDecl's that
will carry the "internal" name of the inline assembly label, which we
will rewrite the asm label to.

Reviewers: rnk

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D4589

llvm-svn: 218230
2014-09-22 02:21:54 +00:00
Akira Hatanaka 974131ea88 [X86, inlineasm] Check that the output size is correct for the given constraint.
llvm-svn: 218064
2014-09-18 18:17:18 +00:00
Nico Weber 728894340f Add -Wunused-local-typedef, a warning that finds unused local typedefs.
The warning warns on TypedefNameDecls -- typedefs and C++11 using aliases --
that are !isReferenced(). Since the isReferenced() bit on TypedefNameDecls
wasn't used for anything before this warning it wasn't always set correctly,
so this patch also adds a few missing MarkAnyDeclReferenced() calls in
various places for TypedefNameDecls.

This is made a bit complicated due to local typedefs possibly being used only
after their local scope has closed. Consider:

    template <class T>
    void template_fun(T t) {
      typename T::Foo s3foo;  // YYY
      (void)s3foo;
    }
    void template_fun_user() {
      struct Local {
        typedef int Foo;  // XXX
      } p;
      template_fun(p);
    }

Here the typedef in XXX is only used at end-of-translation unit, when YYY in
template_fun() gets instantiated. To handle this, typedefs that are unused when
their scope exits are added to a set of potentially unused typedefs, and that
set gets checked at end-of-TU. Typedefs that are still unused at that point then
get warned on. There's also serialization code for this set, so that the
warning works with precompiled headers and modules. For modules, the warning
is emitted when the module is built, for precompiled headers each time the
header gets used.

Finally, consider a function using C++14 auto return types to return a local
type defined in a header:

    auto f() {
      struct S { typedef int a; };
      return S();
    }

Here, the typedef escapes its local scope and could be used by only some
translation units including the header. To not warn on this, add a
RecursiveASTVisitor that marks all delcs on local types returned from auto
functions as referenced. (Except if it's a function with internal linkage, or
the decls are private and the local type has no friends -- in these cases, it
_is_ safe to warn.)

Several of the included testcases (most of the interesting ones) were provided
by Richard Smith.

(gcc's spelling -Wunused-local-typedefs is supported as an alias for this
warning.)

llvm-svn: 217298
2014-09-06 01:25:55 +00:00
Hans Wennborg 93dbeae0f7 Don't allow inline asm statements to reference parameters in naked functions
Differential Revision: http://reviews.llvm.org/D5183

llvm-svn: 217200
2014-09-04 22:16:48 +00:00
Akira Hatanaka 987f1864ca [AArch64, inline-asm] Improve diagnostic that is printed when the size of a
variable that has regiser constraint "r" is not 64-bit.

General register operands are output using 64-bit "x" register names, regardless
of the size of the variable, unless the asm operand is prefixed with the "%w"
modifier. This surprises and confuses many users who aren't familiar with
aarch64 inline assembly rules.

With this commit, a note and fixit hint are printed which tell the users that
they need modifier "%w" in order to output a "w" register instead of an "x"
register.

<rdar://problem/12764785>

llvm-svn: 216260
2014-08-22 06:05:21 +00:00
David Majnemer ade4bee761 CodeGen: Let arrays be inputs to inline asm
An array showing up in an inline assembly input is accepted in ICC and
GCC 4.8

This fixes PR20201.

Differential Revision: http://reviews.llvm.org/D4382

llvm-svn: 212954
2014-07-14 16:27:53 +00:00
Alp Toker 1039927808 Don't include llvm/MC/MCParser throughout all of Sema
Requires LLVM r210417.

llvm-svn: 210418
2014-06-08 05:11:37 +00:00
Nikola Smiljanic 03ff2596cb Refactoring. Remove Owned method from Sema.
llvm-svn: 209812
2014-05-29 14:05:12 +00:00
Nikola Smiljanic 01a7598561 Refactoring. Remove release and take methods from ActionResult. Rename takeAs to getAs.
llvm-svn: 209800
2014-05-29 10:55:11 +00:00
Craig Topper c3ec149bb2 [C++11] Use 'nullptr'. Sema edition.
llvm-svn: 209613
2014-05-26 06:22:03 +00:00
Nico Weber 9ef9ca470f Support field references to struct names and c++11 aliases from inline asm.
This is in addition to the existing support for typedefs.

llvm-svn: 208053
2014-05-06 03:13:27 +00:00
Alp Toker b6cc592ea3 Fix a bunch of mislayered clang/Lex includes from Sema
llvm-svn: 207896
2014-05-03 03:45:55 +00:00
Chad Rosier b9aff1edb3 [ms-inline asm] Don't diagnose an empty lookup for inline assmebly. This happen
for labels in inline assembly that aren't in the lookup tables.  E.g.,

  __asm {
   a:
   jmp a
  }

rdar://13983623

llvm-svn: 182659
2013-05-24 18:32:55 +00:00
Dmitri Gribenko ea2d5f818b Remove redundant variable
llvm-svn: 181574
2013-05-10 01:14:26 +00:00
John McCall f413f5ed44 Move parsing of identifiers in MS-style inline assembly into
the actual parser and support arbitrary id-expressions.

We're actually basically set up to do arbitrary expressions here
if we wanted to.

Assembly operands permit things like A::x to be written regardless
of language mode, which forces us to embellish the evaluation
context logic somewhat.  The logic here under template instantiation
is incorrect;  we need to preserve the fact that an expression was
unevaluated.  Of course, template instantiation in general is fishy
here because we have no way of delaying semantic analysis in the
MC parser.  It's all just fishy.

I've also fixed the serialization of MS asm statements.

This commit depends on an LLVM commit.

llvm-svn: 180976
2013-05-03 00:10:13 +00:00
Chad Rosier 7359d4793e [ms-inline asm] Set the OpDecl to the InlineAsmIdentifierInfo struct.
Part of rdar://13663589

llvm-svn: 180055
2013-04-22 22:05:00 +00:00
Chad Rosier b18a285525 [ms-inline asm] Refactor/clean up the SemaLookup interface. No functional
change indended.
Part of rdar://13663589

llvm-svn: 180027
2013-04-22 17:01:37 +00:00
Chad Rosier 7f2ab89774 [ms-inline asm] The parsing of C++ identifiers is a task of the front-end parser,
not the asm parser.  As such, begin moving the parsing logic in that direction.
This patch is just a temporary hack until the real frontend parser can be hooked
up.  Part of rdar://13663589

llvm-svn: 179882
2013-04-19 20:37:49 +00:00
Chad Rosier 384823dc32 Specify that we're parsing ms-style inline assembly.
llvm-svn: 179762
2013-04-18 15:45:31 +00:00
Chad Rosier c3aa20265a Use the ASYContext::getTypeSizeInChars API to cleanup some ugliness, per John
and Jordan's suggestion.  No functional change intendend.

llvm-svn: 178507
2013-04-01 22:02:05 +00:00
Chad Rosier 10230d4d6e Cleanup. No functional change intended.
llvm-svn: 178481
2013-04-01 17:58:03 +00:00
Bill Wendling b68b7571a9 Pass the diagnostic in for better error messages.
llvm-svn: 178120
2013-03-27 06:06:26 +00:00
Bill Wendling c4fc3a2ba5 Emit an error message instead of crashing when dereferencing an incomplete pointer type.
If the ASM statement is dereferencing an incomplete pointer type, issue an error
instead of crashing.
<rdar://problem/12700799>

llvm-svn: 177915
2013-03-25 21:09:49 +00:00
Bill Wendling b3b4a37138 Use RequireCompleteType() instead of isIncompleteType().
isIncompleteType() returns true or false for template types depending on whether
the type is instantiated yet. In this context, that's arbitrary. The better way
to check for a complete type is RequireCompleteType().

Thanks to Eli Friedman for noticing this!

<rdar://problem/12700799>

llvm-svn: 177768
2013-03-22 21:33:46 +00:00
Jim Grosbach 6f54f787b4 MCParser: Update method names per coding guidelines.
s/ParseMSInlineAsm/parseMSInlineAsm/

llvm-svn: 175680
2013-02-20 22:25:15 +00:00
Chad Rosier 282d675b28 [ms-inline asm] Add an error when trying to compile MS-style inline assembly
for an unsupported architecture.
rdar://13063988

llvm-svn: 173364
2013-01-24 20:24:34 +00:00
Chad Rosier 4edf11fcf0 [ms-inline asm] Extend the Sema interface to get the size and length of a
VarDecl.
Part of rdar://12576868

llvm-svn: 172742
2013-01-17 19:21:24 +00:00
Dmitri Gribenko f857950d39 Remove useless 'llvm::' qualifier from names like StringRef and others that are
brought into 'clang' namespace by clang/Basic/LLVM.h

llvm-svn: 172323
2013-01-12 19:30:44 +00:00
Chad Rosier 8a11f77cf3 [ms-inline asm] Extend the inline asm Sema lookup interface to determine if the
Decl is a VarDecl.
Part of rdar://12991541

llvm-svn: 172120
2013-01-10 22:10:16 +00:00
Chandler Carruth 3a02247dc9 Sort all of Clang's files under 'lib', and fix up the broken headers
uncovered.

This required manually correcting all of the incorrect main-module
headers I could find, and running the new llvm/utils/sort_includes.py
script over the files.

I also manually added quite a few missing headers that were uncovered by
shuffling the order or moving headers up to be main-module-headers.

llvm-svn: 169237
2012-12-04 09:13:33 +00:00