Re: [PATCH] D17491: Add performance check to flag function parameters of expensive to copy types that can be safely converted to const references.

2016-03-28 Thread Richard via cfe-commits
LegalizeAdulthood added a subscriber: LegalizeAdulthood.
LegalizeAdulthood added a comment.

Can you add something to the docs/ReleaseNotes.rst for this new check, please?


Repository:
  rL LLVM

http://reviews.llvm.org/D17491



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17482: [clang-tidy] Allow tests to verify changes made to header files

2016-03-28 Thread Richard via cfe-commits
LegalizeAdulthood added a comment.

Squeak


http://reviews.llvm.org/D17482



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18210: [analyzer] Fix an assertion fail in hash generation.

2016-03-30 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL264851: [analyzer] Fix an assertion fail in hash generation. 
(authored by xazax).

Changed prior to commit:
  http://reviews.llvm.org/D18210?vs=50819=52033#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18210

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -132,8 +132,11 @@
 
   StringRef Str = GetNthLineOfFile(SM.getBuffer(L.getFileID(), L),
L.getExpansionLineNumber());
-  unsigned col = Str.find_first_not_of(Whitespaces);
-  col++;
+  StringRef::size_type col = Str.find_first_not_of(Whitespaces);
+  if (col == StringRef::npos)
+col = 1; // The line only contains whitespace.
+  else
+col++;
   SourceLocation StartOfLine =
   SM.translateLineCol(SM.getFileID(L), L.getExpansionLineNumber(), col);
   llvm::MemoryBuffer *Buffer =


Index: cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -132,8 +132,11 @@
 
   StringRef Str = GetNthLineOfFile(SM.getBuffer(L.getFileID(), L),
L.getExpansionLineNumber());
-  unsigned col = Str.find_first_not_of(Whitespaces);
-  col++;
+  StringRef::size_type col = Str.find_first_not_of(Whitespaces);
+  if (col == StringRef::npos)
+col = 1; // The line only contains whitespace.
+  else
+col++;
   SourceLocation StartOfLine =
   SM.translateLineCol(SM.getFileID(L), L.getExpansionLineNumber(), col);
   llvm::MemoryBuffer *Buffer =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D7982: Add readability-duplicate-include check to clang-tidy

2016-03-29 Thread Richard via cfe-commits
LegalizeAdulthood added inline comments.


Comment at: clang-tidy/readability/DuplicateIncludeCheck.cpp:62
@@ +61,3 @@
+StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  if (!SM_.isInMainFile(HashLoc)) {
+return;

LegalizeAdulthood wrote:
> LegalizeAdulthood wrote:
> > alexfh wrote:
> > > LegalizeAdulthood wrote:
> > > > alexfh wrote:
> > > > > What's the reason to limit the check to the main file only? I think, 
> > > > > it should work on all headers as well. Also, sometimes it's fine to 
> > > > > have duplicate includes even without macro definitions in between, 
> > > > > e.g. when these #includes are in different namespaces.
> > > > > 
> > > > > I'd suggest using the same technique as in the IncludeOrderCheck: for 
> > > > > each file collect all preprocessor directives sorted by 
> > > > > SourceLocation. Then detect #include blocks (not necessarily the same 
> > > > > way as its done in the IncludeOrderCheck. Maybe use the presense of 
> > > > > any non-comment tokens between #includes as a boundary of blocks), 
> > > > > and detect duplicate includes in each block.
> > > > If I remove the `isInMainFile`, how do I ensure that I don't attempt to 
> > > > modify system headers?
> > > Using `SourceLocation::isInSystemHeader()`.
> > Thanks, I'll try that.  The next question that brings to mind is how do I 
> > distinguish between headers that I own and headers used from third party 
> > libraries?
> > 
> > For instance, suppose I run a check on a clang refactoring tool and it uses 
> > `isInSystemHeader` and starts flagging issues in the clang tooling library 
> > headers.
> > 
> > The `compile_commands.json` doesn't contain any information about headers 
> > in my project, only translation units in my build, so it doesn't know 
> > whether or not included headers belong to me or third-party libraries.
> For the benefit of others reading this, Alex pointed out to me the 
> `-header-filter` and `-system-headers` options to clang-tidy.  I think this 
> means I don't need any narrowing if `isExpansinInMainFile()` in any of my 
> matchers.  I will do some experimenting to verify that this doesn't introduce 
> regressions.
If I remove the `isInMainFile` and replace it with a check to 
`isInSystemHeader`, then all my tests fail.  I will have to investigate this 
further.


http://reviews.llvm.org/D7982



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18717: [Clang-tidy] Improve checks documentation consistency

2016-04-01 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL265205: [Clang-tidy] Improve checks documentation 
consistency. (authored by eugenezelenko).

Changed prior to commit:
  http://reviews.llvm.org/D18717?vs=52441=52451#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18717

Files:
  clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err52-cpp.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err58-cpp.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/cert-flp30-c.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-pro-bounds-constant-array-index.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/google-build-explicit-make-pair.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/google-build-namespaces.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/google-build-using-namespace.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/google-global-names-in-headers.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-braces-around-statements.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-casting.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-function-size.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/google-readability-todo.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-int.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-member-string-references.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-memset.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/google-runtime-operator.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-bool-pointer-implicit-conversion.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-new-delete-overloads.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-non-copyable-objects.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-static-assert.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-suspicious-semicolon.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-throw-by-value-catch-by-reference.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/misc-unused-parameters.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-loop-convert.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-pass-by-value.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-nullptr.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/performance-implicit-cast-in-loop.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-braces-around-statements.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/readability-function-size.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-identifier-naming.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/readability-named-parameter.rst

Index: clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err52-cpp.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err52-cpp.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/cert-err52-cpp.rst
@@ -3,7 +3,7 @@
 cert-err52-cpp
 ==
 
-This check flags all call expressions involving setjmp() and longjmp().
+This check flags all call expressions involving ``setjmp()`` and ``longjmp()``.
 
 This check corresponds to the CERT C++ Coding Standard rule
 `ERR52-CPP. Do not use setjmp() or longjmp()
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/readability-braces-around-statements.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/readability-braces-around-statements.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/readability-braces-around-statements.rst
@@ -3,6 +3,8 @@
 readability-braces-around-statements
 
 
+`google-readability-braces-around-statements` redirects here as an alias for
+this check.
 
 Checks that bodies of ``if`` statements and loops (``for``, ``range-for``,
 ``do-while``, and ``while``) are inside braces
@@ -22,8 +24,8 @@
 statement;
   }
 
-Additionally, one can define an option ``ShortStatementLines`` defining the
-minimal number of lines that the statement should have in order to trigger
+Additionally, one can define an option :option:`ShortStatementLines` defining
+the minimal number of lines that the statement should have in order to trigger
 this check.
 
 The number of lines is counted from the end of condition or initial keyword
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/misc-unused-parameters.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-unused-parameters.rst
+++ 

Re: [PATCH] D17482: [clang-tidy] Allow tests to verify changes made to header files

2016-04-04 Thread Richard via cfe-commits
LegalizeAdulthood added a comment.

As it stands currently, you can't commit a header with `CHECK-MESSAGES` and 
`CHECK-FIXES` lines and have them verified.

That's the whole point of this changeset.

Currently you have to do something very hacky in order to verify changes made 
to headers.


http://reviews.llvm.org/D17482



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17482: [clang-tidy] Allow tests to verify changes made to header files

2016-04-04 Thread Richard via cfe-commits
LegalizeAdulthood added a comment.

In http://reviews.llvm.org/D17482#390237, @alexfh wrote:

> My main concern is that this change makes the already complicated and 
> unobvious testing mechanism [...]


The complexity and obtuseness of the existing testing mechanism is unrelated to 
this changeset.  This changeset doesn't fundamentally change the testing 
mechanism.

> even more complicated and even less obvious for a very little (as I see it 
> now) benefit.


The benefit is that you would now have a consistent mechanism for verifying 
changes made to headers.

> The added functionality supports a very limited use case (a single header)


You have to start somewhere.  Currently there is no mechanism provided at all.  
Saying that this mechanism is not acceptable because it doesn't handle 
arbitrarily complex generalized checking is making the perfect the enemy of the 
good and isn't a reason for preventing this change from being accepted IMO.

> and it does it in a rather hacky way (the use of the new --header-filter flag 
> is not self-documenting and the overall behavior seems "magical" at the first 
> glance).


None of the mechanisms in the testing of these files is self-documenting.  If 
that is the criteria by which all changes are to be measured, then the entire 
existing system has to be thrown out.  Again, this feels like making the 
perfect the enemy of the good.  The behavior for validating header files is the 
same as the existing behavior for validating source files.  They are copied, 
filtered, processed and the processed results are analyzed.  Discrepencies are 
shown as diffs against the original source files.

> There's also an outstanding comment that you didn't seem to have addressed 
> yet.


Which specific comment are you referring to?  Because, just like this comment, 
there's a bunch of discussion in very general terms without specific complaints 
against specific pieces of code that are preventing it from being committed.

> In http://reviews.llvm.org/D17482#378685, @LegalizeAdulthood wrote:

> 

> > In the context of a clang-tidy check, what would be gained by verifying 
> > changes made to multiple headers that isn't already tested by verifying 
> > changes made to a single header?

> 


You haven't answered this question yet.  The existing test mechanism verifies 
only a single source file at a time; I see no reason why verifying a single 
header is such a great imposition of constraints that would prevent existing 
checks from being enhanced to verify their changes on header files.  However, 
should that arise in the future it is a relatively small change to add 
additional header processing to the script.  Again, let's not make the perfect 
the enemy of the good.  There is no reason we cannot improve the code in steps, 
on demand, as the need arises.  This is the essence of agile development.  
YAGNI 

> > At least two of the checks I've already added have complaints that they 
> > don't work on headers.

> 

> 

> That's because you used `isExpansionInMainFile`, which is just not needed 
> there


...and that was because I couldn't write an automated test against header files 
to verify the changes made there.  The whole point of THIS changeset was to 
give me a mechanism for verifying the fixes in a header so that I could address 
those issues in the bug database.

But instead of getting on with fixing it, I've spent 6 weeks waiting for this 
changeset to be reviewed and that discussion has prevented an advancement of 
functionality in the testing framework.

> > While this change was waiting to be reviewed, another check was added that 
> > made changes to headers but had no way to verify them.

> 

> 

> Which check do you mean? Does it need a special treatment of headers or is it 
> just able to make fixes in headers as most other checks?


I already quoted the check in question earlier in this thread; please review 
those messages.


http://reviews.llvm.org/D17482



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18509: clang-tidy: add_new_check.py stubs out release notes

2016-04-04 Thread Richard via cfe-commits
LegalizeAdulthood added a comment.

In http://reviews.llvm.org/D18509#388071, @hintonda wrote:

> With this change, won't you need to update 2 different repos: clang and 
> extra?  Is it possible to update both with a single Phabricator patch?


This is updating the release notes in the extra repository.  (The release notes 
are new to this repository; you may not have noticed them being added.)


http://reviews.llvm.org/D18509



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17955: [OpenCL] Fix pipe builtin bugs

2016-03-29 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL264825: [OpenCL] Fix pipe builtin bugs (authored by pxl).

Changed prior to commit:
  http://reviews.llvm.org/D17955?vs=51629=52021#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17955

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7776,7 +7776,7 @@
 def err_opencl_builtin_pipe_arg_num : Error<
   "invalid number of arguments to function: %0">;
 def err_opencl_builtin_pipe_invalid_arg : Error<
-  "invalid argument type to function %0 (expecting %1)">;
+  "invalid argument type to function %0 (expecting %1 having %2)">;
 def err_opencl_builtin_pipe_invalid_access_modifier : Error<
   "invalid pipe access modifier (expecting %0)">;
 
Index: cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
===
--- cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
+++ cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
@@ -5,46 +5,56 @@
   reserve_id_t rid;
 
   // read/write_pipe
+  read_pipe(p, );
+  read_pipe(p, ptr);
   read_pipe(tmp, p);// expected-error {{first argument to 'read_pipe' must be a pipe type}}
   read_pipe(p);   // expected-error {{invalid number of arguments to function: 'read_pipe'}}
-  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'reserve_id_t')}}
-  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'unsigned int')}}
-  read_pipe(p, tmp);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'int *')}}
+  read_pipe(p, rid, tmp, ptr);
+  read_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'reserve_id_t' having 'int')}}
+  read_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'unsigned int' having 'reserve_id_t')}}
+  read_pipe(p, tmp);   // expected-error {{invalid argument type to function 'read_pipe' (expecting 'int *' having 'int')}}
   write_pipe(p, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
   write_pipe(p, rid, tmp, ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}}
 
   // reserve_read/write_pipe
-  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_read_pipe' (expecting 'unsigned int')}}
+  reserve_read_pipe(p, tmp);
+  reserve_read_pipe(p, ptr);// expected-error{{invalid argument type to function 'reserve_read_pipe' (expecting 'unsigned int' having '__global int *')}}
   work_group_reserve_read_pipe(tmp, tmp);// expected-error{{first argument to 'work_group_reserve_read_pipe' must be a pipe type}}
   sub_group_reserve_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 
   // commit_read/write_pipe
+  commit_read_pipe(p, rid);
   commit_read_pipe(tmp, rid);// expected-error{{first argument to 'commit_read_pipe' must be a pipe type}}
-  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function 'work_group_commit_read_pipe' (expecting 'reserve_id_t')}}
+  work_group_commit_read_pipe(p, tmp);// expected-error{{invalid argument type to function 'work_group_commit_read_pipe' (expecting 'reserve_id_t' having 'int')}}
   sub_group_commit_write_pipe(p, tmp);// expected-error{{invalid pipe access modifier (expecting write_only)}}
 }
 
 void test2(write_only pipe int p, global int* ptr){
   int tmp;
   reserve_id_t rid;
 
   // read/write_pipe
+  write_pipe(p, );
+  write_pipe(p, ptr);
   write_pipe(tmp, p);// expected-error {{first argument to 'write_pipe' must be a pipe type}}
   write_pipe(p);   // expected-error {{invalid number of arguments to function: 'write_pipe'}}
-  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'reserve_id_t')}}
-  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'unsigned int')}}
-  write_pipe(p, tmp);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'int *')}}
+  write_pipe(p, rid, tmp, ptr);
+  write_pipe(p, tmp, tmp, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'reserve_id_t' having 'int')}}
+  write_pipe(p, rid, rid, ptr);   // expected-error {{invalid argument type to function 'write_pipe' (expecting 'unsigned int' having 'reserve_id_t')}}
+  write_pipe(p, tmp);   // expected-error 

Re: [PATCH] D17861: [OpenCL] Accept __attribute__((nosvm))

2016-03-31 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL265006: [OpenCL] Added nosvm attribute for OpenCL v2.0. 
(authored by stulova).

Changed prior to commit:
  http://reviews.llvm.org/D17861?vs=52077=52185#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17861

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaStmtAttr.cpp
  cfe/trunk/test/SemaOpenCL/nosvm.cl

Index: cfe/trunk/include/clang/Basic/AttrDocs.td
===
--- cfe/trunk/include/clang/Basic/AttrDocs.td
+++ cfe/trunk/include/clang/Basic/AttrDocs.td
@@ -1773,6 +1773,17 @@
   }];
 }
 
+def OpenCLNoSVMDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+OpenCL 2.0 supports the optional ``__attribute__((nosvm))`` qualifier for
+pointer variable. It informs the compiler that the pointer does not refer
+to a shared virtual memory region. See OpenCL v2.0 s6.7.2 for details.
+
+Since it is not widely used and has been removed from OpenCL 2.1, it is ignored
+by Clang.
+  }];
+}
 def NullabilityDocs : DocumentationCategory<"Nullability Attributes"> {
   let Content = [{
 Whether a particular pointer may be "null" is an important concern when working with pointers in the C family of languages. The various nullability attributes indicate whether a particular pointer can be null or not, which makes APIs more expressive and can help static analysis tools identify bugs involving null pointers. Clang supports several kinds of nullability attributes: the ``nonnull`` and ``returns_nonnull`` attributes indicate which function or method parameters and result types can never be null, while nullability type qualifiers indicate which pointer types can be null (``_Nullable``) or cannot be null (``_Nonnull``). 
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -239,6 +239,7 @@
 def Borland : LangOpt<"Borland">;
 def CUDA : LangOpt<"CUDA">;
 def COnly : LangOpt<"CPlusPlus", 1>;
+def OpenCL : LangOpt<"OpenCL">;
 
 // Defines targets for target-specific attributes. The list of strings should
 // specify architectures for which the target applies, based off the ArchType
@@ -719,6 +720,14 @@
   let Documentation = [OpenCLAddressSpaceGenericDocs];
 }
 
+def OpenCLNoSVM : Attr {
+  let Spellings = [GNU<"nosvm">];
+  let Subjects = SubjectList<[Var]>;
+  let Documentation = [OpenCLNoSVMDocs];
+  let LangOpts = [OpenCL];
+  let ASTNode = 0;
+}
+
 def Deprecated : InheritableAttr {
   let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
CXX11<"","deprecated", 201309>];
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2129,7 +2129,7 @@
 def err_attribute_requires_positive_integer : Error<
   "%0 attribute requires a positive integral compile time constant expression">;
 def err_attribute_requires_opencl_version : Error<
-  "%0 attribute requires OpenCL version %1 or above">;
+  "%0 attribute requires OpenCL version %1%select{| or above}2">;
 def warn_unsupported_target_attribute
 : Warning<"Ignoring unsupported '%0' in the target attribute string">,
 InGroup;
@@ -7775,6 +7775,9 @@
   "pointer to type %0 is invalid in OpenCL">;
 def err_opencl_type_can_only_be_used_as_function_parameter : Error <
   "type %0 can only be used as a function parameter in OpenCL">;
+def warn_opencl_attr_deprecated_ignored : Warning <
+  "%0 attribute is deprecated and ignored in OpenCL version %1">,
+  InGroup;
 
 // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
 def err_opencl_builtin_pipe_first_arg : Error<
Index: cfe/trunk/test/SemaOpenCL/nosvm.cl
===
--- cfe/trunk/test/SemaOpenCL/nosvm.cl
+++ cfe/trunk/test/SemaOpenCL/nosvm.cl
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -cl-std=CL2.0 -D CL20 %s
+// RUN: %clang_cc1 -verify -x c -D NOCL %s
+
+#ifndef NOCL
+kernel void f(__attribute__((nosvm)) global int* a);
+#ifndef CL20
+// expected-error@-2 {{'nosvm' attribute requires OpenCL version 2.0}}
+#else
+// expected-warning@-4 {{'nosvm' attribute is deprecated and ignored in OpenCL version 2.0}}
+#endif
+
+__attribute__((nosvm)) void g(); // expected-warning {{'nosvm' attribute only applies to variables}}
+
+#else
+void f(__attribute__((nosvm)) int* a); // expected-warning {{'nosvm' attribute ignored}}
+#endif
Index: cfe/trunk/lib/Sema/SemaStmtAttr.cpp
===
--- 

Re: [PATCH] D14286: ASTImporter: expressions, pt.1

2016-04-14 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266292: [ASTImporter] Implement some expression-related AST 
node import. (authored by dergachev).

Changed prior to commit:
  http://reviews.llvm.org/D14286?vs=53389=53692#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14286

Files:
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/unittests/AST/ASTImporterTest.cpp
  cfe/trunk/unittests/AST/CMakeLists.txt

Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -4278,6 +4278,8 @@
   friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
   // currently suitable for AST reading, too much
   // interdependencies.
+  friend class ASTNodeImporter;
+
   InjectedClassNameType(CXXRecordDecl *D, QualType TST)
 : Type(InjectedClassName, QualType(), /*Dependent=*/true,
/*InstantiationDependent=*/true,
Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -29,7 +29,7 @@
   public DeclVisitor,
   public StmtVisitor {
 ASTImporter 
-
+
   public:
 explicit ASTNodeImporter(ASTImporter ) : Importer(Importer) { }
 
@@ -64,11 +64,12 @@
 QualType VisitDecltypeType(const DecltypeType *T);
 QualType VisitUnaryTransformType(const UnaryTransformType *T);
 QualType VisitAutoType(const AutoType *T);
+QualType VisitInjectedClassNameType(const InjectedClassNameType *T);
 // FIXME: DependentDecltypeType
 QualType VisitRecordType(const RecordType *T);
 QualType VisitEnumType(const EnumType *T);
 QualType VisitAttributedType(const AttributedType *T);
-// FIXME: TemplateTypeParmType
+QualType VisitTemplateTypeParmType(const TemplateTypeParmType *T);
 // FIXME: SubstTemplateTypeParmType
 QualType VisitTemplateSpecializationType(const TemplateSpecializationType *T);
 QualType VisitElaboratedType(const ElaboratedType *T);
@@ -86,6 +87,10 @@
 void ImportDeclarationNameLoc(const DeclarationNameInfo ,
   DeclarationNameInfo& To);
 void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
+
+typedef DesignatedInitExpr::Designator Designator;
+Designator ImportDesignator(const Designator );
+
 
 /// \brief What we should import from the definition.
 enum ImportDefinitionKind { 
@@ -136,6 +141,7 @@
 Decl *VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
 Decl *VisitTypedefDecl(TypedefDecl *D);
 Decl *VisitTypeAliasDecl(TypeAliasDecl *D);
+Decl *VisitLabelDecl(LabelDecl *D);
 Decl *VisitEnumDecl(EnumDecl *D);
 Decl *VisitRecordDecl(RecordDecl *D);
 Decl *VisitEnumConstantDecl(EnumConstantDecl *D);
@@ -175,6 +181,7 @@
 DeclGroupRef ImportDeclGroup(DeclGroupRef DG);
 
 Stmt *VisitStmt(Stmt *S);
+Stmt *VisitGCCAsmStmt(GCCAsmStmt *S);
 Stmt *VisitDeclStmt(DeclStmt *S);
 Stmt *VisitNullStmt(NullStmt *S);
 Stmt *VisitCompoundStmt(CompoundStmt *S);
@@ -192,7 +199,6 @@
 Stmt *VisitContinueStmt(ContinueStmt *S);
 Stmt *VisitBreakStmt(BreakStmt *S);
 Stmt *VisitReturnStmt(ReturnStmt *S);
-// FIXME: GCCAsmStmt
 // FIXME: MSAsmStmt
 // FIXME: SEHExceptStmt
 // FIXME: SEHFinallyStmt
@@ -213,13 +219,29 @@
 
 // Importing expressions
 Expr *VisitExpr(Expr *E);
+Expr *VisitVAArgExpr(VAArgExpr *E);
+Expr *VisitGNUNullExpr(GNUNullExpr *E);
+Expr *VisitPredefinedExpr(PredefinedExpr *E);
 Expr *VisitDeclRefExpr(DeclRefExpr *E);
+Expr *VisitImplicitValueInitExpr(ImplicitValueInitExpr *ILE);
+Expr *VisitDesignatedInitExpr(DesignatedInitExpr *E);
+Expr *VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E);
 Expr *VisitIntegerLiteral(IntegerLiteral *E);
+Expr *VisitFloatingLiteral(FloatingLiteral *E);
 Expr *VisitCharacterLiteral(CharacterLiteral *E);
+Expr *VisitStringLiteral(StringLiteral *E);
+Expr *VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
+Expr *VisitAtomicExpr(AtomicExpr *E);
+Expr *VisitAddrLabelExpr(AddrLabelExpr *E);
 Expr *VisitParenExpr(ParenExpr *E);
+Expr *VisitParenListExpr(ParenListExpr *E);
+Expr *VisitStmtExpr(StmtExpr *E);
 Expr *VisitUnaryOperator(UnaryOperator *E);
 Expr *VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E);
 Expr *VisitBinaryOperator(BinaryOperator *E);
+Expr *VisitConditionalOperator(ConditionalOperator *E);
+Expr *VisitBinaryConditionalOperator(BinaryConditionalOperator *E);
+Expr *VisitOpaqueValueExpr(OpaqueValueExpr *E);
 Expr 

Re: [PATCH] D19056: [MSVC] Fix check for wchar_t type in case of -fno-wchar

2016-04-14 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266287: [MSVC] Fix check for wchar_t type in case of 
-fno-wchar (authored by dpolukhin).

Changed prior to commit:
  http://reviews.llvm.org/D19056?vs=53542=53681#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19056

Files:
  cfe/trunk/lib/Sema/SemaExprCXX.cpp
  cfe/trunk/test/SemaCXX/no-wchar.cpp

Index: cfe/trunk/test/SemaCXX/no-wchar.cpp
===
--- cfe/trunk/test/SemaCXX/no-wchar.cpp
+++ cfe/trunk/test/SemaCXX/no-wchar.cpp
@@ -7,3 +7,24 @@
 void bar() {
   foo(L"wide string literal");
 }
+
+void foo1(wchar_t * t = L"");
+// expected-warning@-1 {{conversion from string literal to 'wchar_t *' (aka 
'unsigned short *') is deprecated}}
+
+short *a = L"";
+// expected-error@-1 {{cannot initialize a variable of type 'short *' with an 
lvalue of type 'const unsigned short [1]'}}
+char *b = L"";
+// expected-error@-1 {{cannot initialize a variable of type 'char *' with an 
lvalue of type 'const unsigned short [1]'}}
+
+// NOTE: MSVC allows deprecated conversion in conditional expression if at 
least
+// one of the operand is a string literal but Clang doesn't allow it.
+wchar_t *c = true ? L"a" : L"";
+// expected-error@-1 {{cannot initialize a variable of type 'wchar_t *' (aka 
'unsigned short *') with}}
+
+const wchar_t *d1 = 0;
+const wchar_t *d2 = 0;
+wchar_t *d = true ? d1 : d2;
+// expected-error@-1 {{cannot initialize a variable of type 'wchar_t *' (aka 
'unsigned short *') with}}
+
+wchar_t* e = (const wchar_t*)L"";
+// expected-error@-1 {{cannot initialize a variable of type 'wchar_t *' (aka 
'unsigned short *') with an rvalue of type 'const wchar_t *' (aka 'const 
unsigned short *')}}
Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -3040,7 +3040,8 @@
   return (ToPointeeType->getKind() == BuiltinType::Char_U ||
   ToPointeeType->getKind() == BuiltinType::Char_S);
 case StringLiteral::Wide:
-  return ToPointeeType->isWideCharType();
+  return Context.typesAreCompatible(Context.getWideCharType(),
+QualType(ToPointeeType, 0));
   }
 }
   }


Index: cfe/trunk/test/SemaCXX/no-wchar.cpp
===
--- cfe/trunk/test/SemaCXX/no-wchar.cpp
+++ cfe/trunk/test/SemaCXX/no-wchar.cpp
@@ -7,3 +7,24 @@
 void bar() {
   foo(L"wide string literal");
 }
+
+void foo1(wchar_t * t = L"");
+// expected-warning@-1 {{conversion from string literal to 'wchar_t *' (aka 'unsigned short *') is deprecated}}
+
+short *a = L"";
+// expected-error@-1 {{cannot initialize a variable of type 'short *' with an lvalue of type 'const unsigned short [1]'}}
+char *b = L"";
+// expected-error@-1 {{cannot initialize a variable of type 'char *' with an lvalue of type 'const unsigned short [1]'}}
+
+// NOTE: MSVC allows deprecated conversion in conditional expression if at least
+// one of the operand is a string literal but Clang doesn't allow it.
+wchar_t *c = true ? L"a" : L"";
+// expected-error@-1 {{cannot initialize a variable of type 'wchar_t *' (aka 'unsigned short *') with}}
+
+const wchar_t *d1 = 0;
+const wchar_t *d2 = 0;
+wchar_t *d = true ? d1 : d2;
+// expected-error@-1 {{cannot initialize a variable of type 'wchar_t *' (aka 'unsigned short *') with}}
+
+wchar_t* e = (const wchar_t*)L"";
+// expected-error@-1 {{cannot initialize a variable of type 'wchar_t *' (aka 'unsigned short *') with an rvalue of type 'const wchar_t *' (aka 'const unsigned short *')}}
Index: cfe/trunk/lib/Sema/SemaExprCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp
@@ -3040,7 +3040,8 @@
   return (ToPointeeType->getKind() == BuiltinType::Char_U ||
   ToPointeeType->getKind() == BuiltinType::Char_S);
 case StringLiteral::Wide:
-  return ToPointeeType->isWideCharType();
+  return Context.typesAreCompatible(Context.getWideCharType(),
+QualType(ToPointeeType, 0));
   }
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19057: [analyzer] Let TK_PreserveContents span across the whole base region.

2016-04-25 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL267413: [analyzer] Let TK_PreserveContents span across the 
whole base region. (authored by dergachev).

Changed prior to commit:
  http://reviews.llvm.org/D19057?vs=53551=54852#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19057

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
  cfe/trunk/test/Analysis/call-invalidation.cpp
  cfe/trunk/test/Analysis/malloc.c

Index: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -177,7 +177,7 @@
 // below for efficiency.
 if (PreserveArgs.count(Idx))
   if (const MemRegion *MR = getArgSVal(Idx).getAsRegion())
-ETraits.setTrait(MR->StripCasts(),
+ETraits.setTrait(MR->getBaseRegion(),
 RegionAndSymbolInvalidationTraits::TK_PreserveContents);
 // TODO: Factor this out + handle the lower level const pointers.
 
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -920,7 +920,7 @@
 // Invalidate and escape only indirect regions accessible through the source
 // buffer.
 if (IsSourceBuffer) {
-  ITraits.setTrait(R,
+  ITraits.setTrait(R->getBaseRegion(),
RegionAndSymbolInvalidationTraits::TK_PreserveContents);
   ITraits.setTrait(R, RegionAndSymbolInvalidationTraits::TK_SuppressEscape);
   CausesPointerEscape = true;
Index: cfe/trunk/test/Analysis/malloc.c
===
--- cfe/trunk/test/Analysis/malloc.c
+++ cfe/trunk/test/Analysis/malloc.c
@@ -1750,6 +1750,19 @@
   fake_rb_tree_insert_node(rbt, data); // no warning
 }
 
+struct IntAndPtr {
+  int x;
+  int *p;
+};
+
+void constEscape(const void *ptr);
+
+void testConstEscapeThroughAnotherField() {
+  struct IntAndPtr s;
+  s.p = malloc(sizeof(int));
+  constEscape(&(s.x)); // could free s->p!
+} // no-warning
+
 // 
 // False negatives.
 
@@ -1769,3 +1782,9 @@
   // FIXME: This is a leak: if we think a system function won't free p, it
   // won't free (p-1) either.
 }
+
+void testMallocIntoMalloc() {
+  StructWithPtr *s = malloc(sizeof(StructWithPtr));
+  s->memP = malloc(sizeof(int));
+  free(s);
+} // FIXME: should warn here
Index: cfe/trunk/test/Analysis/call-invalidation.cpp
===
--- cfe/trunk/test/Analysis/call-invalidation.cpp
+++ cfe/trunk/test/Analysis/call-invalidation.cpp
@@ -118,3 +118,50 @@
 }
 
 
+struct PlainStruct {
+  int x, y;
+  mutable int z;
+};
+
+PlainStruct glob;
+
+void useAnything(void *);
+void useAnythingConst(const void *);
+
+void testInvalidationThroughBaseRegionPointer() {
+  PlainStruct s1;
+  s1.x = 1;
+  s1.z = 1;
+  clang_analyzer_eval(s1.x == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(s1.z == 1); // expected-warning{{TRUE}}
+  // Not only passing a structure pointer through const pointer parameter,
+  // but also passing a field pointer through const pointer parameter
+  // should preserve the contents of the structure.
+  useAnythingConst(&(s1.y));
+  clang_analyzer_eval(s1.x == 1); // expected-warning{{TRUE}}
+  // FIXME: Should say "UNKNOWN", because it is not uncommon to
+  // modify a mutable member variable through const pointer.
+  clang_analyzer_eval(s1.z == 1); // expected-warning{{TRUE}}
+  useAnything(&(s1.y));
+  clang_analyzer_eval(s1.x == 1); // expected-warning{{UNKNOWN}}
+}
+
+
+void useFirstConstSecondNonConst(const void *x, void *y);
+void useFirstNonConstSecondConst(void *x, const void *y);
+
+void testMixedConstNonConstCalls() {
+  PlainStruct s2;
+  s2.x = 1;
+  useFirstConstSecondNonConst(&(s2.x), &(s2.y));
+  clang_analyzer_eval(s2.x == 1); // expected-warning{{UNKNOWN}}
+  s2.x = 1;
+  useFirstNonConstSecondConst(&(s2.x), &(s2.y));
+  clang_analyzer_eval(s2.x == 1); // expected-warning{{UNKNOWN}}
+  s2.y = 1;
+  useFirstConstSecondNonConst(&(s2.x), &(s2.y));
+  clang_analyzer_eval(s2.y == 1); // expected-warning{{UNKNOWN}}
+  s2.y = 1;
+  useFirstNonConstSecondConst(&(s2.x), &(s2.y));
+  clang_analyzer_eval(s2.y == 1); // expected-warning{{UNKNOWN}}
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19361: [MS] Improved implementation of MS stack pragmas (vtordisp, *_seg)

2016-04-29 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268029: Recommit "[MS] Improved implementation of stack 
pragmas (vtordisp, *_seg)" (authored by dzobnin).

Changed prior to commit:
  http://reviews.llvm.org/D19361?vs=54484=55568#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19361

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Parse/ParsePragma.cpp
  cfe/trunk/lib/Parse/ParseStmt.cpp
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/lib/Sema/SemaAttr.cpp
  cfe/trunk/test/CodeGenCXX/sections.cpp
  cfe/trunk/test/SemaCXX/pragma-vtordisp.cpp

Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -327,40 +327,21 @@
   LangOptions::PragmaMSPointersToMembersKind
   MSPointerToMemberRepresentationMethod;
 
-  enum PragmaVtorDispKind {
-PVDK_Push,  ///< #pragma vtordisp(push, mode)
-PVDK_Set,   ///< #pragma vtordisp(mode)
-PVDK_Pop,   ///< #pragma vtordisp(pop)
-PVDK_Reset  ///< #pragma vtordisp()
-  };
-
-  enum PragmaMsStackAction {
-PSK_Reset,// #pragma ()
-PSK_Set,  // #pragma ("name")
-PSK_Push, // #pragma (push[, id])
-PSK_Push_Set, // #pragma (push[, id], "name")
-PSK_Pop,  // #pragma (pop[, id])
-PSK_Pop_Set,  // #pragma (pop[, id], "name")
-  };
-
-  /// \brief Whether to insert vtordisps prior to virtual bases in the Microsoft
-  /// C++ ABI.  Possible values are 0, 1, and 2, which mean:
-  ///
-  /// 0: Suppress all vtordisps
-  /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial
-  ///structors
-  /// 2: Always insert vtordisps to support RTTI on partially constructed
-  ///objects
-  ///
-  /// The stack always has at least one element in it.
-  SmallVector VtorDispModeStack;
-
   /// Stack of active SEH __finally scopes.  Can be empty.
   SmallVector CurrentSEHFinally;
 
   /// \brief Source location for newly created implicit MSInheritanceAttrs
   SourceLocation ImplicitMSInheritanceAttrLoc;
 
+  enum PragmaMsStackAction {
+PSK_Reset = 0x0,// #pragma ()
+PSK_Set   = 0x1,// #pragma (value)
+PSK_Push  = 0x2,// #pragma (push[, id])
+PSK_Pop   = 0x4,// #pragma (pop[, id])
+PSK_Push_Set  = PSK_Push | PSK_Set, // #pragma (push[, id], value)
+PSK_Pop_Set   = PSK_Pop | PSK_Set,  // #pragma (pop[, id], value)
+  };
+
   template
   struct PragmaStack {
 struct Slot {
@@ -377,18 +358,66 @@
  PragmaMsStackAction Action,
  llvm::StringRef StackSlotLabel,
  ValueType Value);
-explicit PragmaStack(const ValueType )
-  : CurrentValue(Value) {}
+
+// MSVC seems to add artificial slots to #pragma stacks on entering a C++
+// method body to restore the stacks on exit, so it works like this:
+//
+//   struct S {
+// #pragma (push, InternalPragmaSlot, )
+// void Method {}
+// #pragma (pop, InternalPragmaSlot)
+//   };
+//
+// It works even with #pragma vtordisp, although MSVC doesn't support
+//   #pragma vtordisp(push [, id], n)
+// syntax.
+//
+// Push / pop a named sentinel slot.
+void SentinelAction(PragmaMsStackAction Action, StringRef Label) {
+  assert((Action == PSK_Push || Action == PSK_Pop) &&
+ "Can only push / pop #pragma stack sentinels!");
+  Act(CurrentPragmaLocation, Action, Label, CurrentValue);
+}
+
+// Constructors.
+explicit PragmaStack(const ValueType )
+: DefaultValue(Default), CurrentValue(Default) {}
+
 SmallVector Stack;
+ValueType DefaultValue; // Value used for PSK_Reset action.
 ValueType CurrentValue;
 SourceLocation CurrentPragmaLocation;
   };
   // FIXME: We should serialize / deserialize these if they occur in a PCH (but
   // we shouldn't do so if they're in a module).
+
+  /// \brief Whether to insert vtordisps prior to virtual bases in the Microsoft
+  /// C++ ABI.  Possible values are 0, 1, and 2, which mean:
+  ///
+  /// 0: Suppress all vtordisps
+  /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial
+  ///structors
+  /// 2: Always insert vtordisps to support RTTI on partially constructed
+  ///objects
+  PragmaStack VtorDispStack;
   PragmaStack DataSegStack;
   PragmaStack BSSSegStack;
   PragmaStack ConstSegStack;
   PragmaStack CodeSegStack;
+  // TODO: Change implementation of #pragma pack to use PragmaStack<> approach.
+
+  // RAII object to push / pop sentinel slots for all MS #pragma stacks.
+  // Actions should be performed only if we enter / exit a C++ method body.
+  class PragmaStackSentinelRAII {
+  public:
+PragmaStackSentinelRAII(Sema , StringRef SlotLabel, bool ShouldAct);
+

Re: [PATCH] D19717: [find-all-symbols] Fix racy yaml file writing.

2016-04-29 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268021: [find-all-symbols] Fix racy yaml file writing. 
(authored by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D19717?vs=9=55562#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19717

Files:
  clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
  clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
  
clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp

Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
===
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
@@ -12,6 +12,7 @@
 
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 #include 
@@ -87,9 +88,9 @@
   bool operator<(const SymbolInfo ) const;
 };
 
-/// \brief Write SymbolInfos to a single file (YAML format).
-bool WriteSymboInfosToFile(llvm::StringRef FilePath,
-   const std::set );
+/// \brief Write SymbolInfos to a stream (YAML format).
+bool WriteSymbolInfosToStream(llvm::raw_ostream ,
+  const std::set );
 
 /// \brief Read SymbolInfos from a YAML document.
 std::vector ReadSymbolInfosFromYAML(llvm::StringRef Yaml);
Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
===
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
@@ -97,16 +97,11 @@
  std::tie(Symbol.Name, Symbol.FilePath, Symbol.LineNumber);
 }
 
-bool WriteSymboInfosToFile(llvm::StringRef FilePath,
-   const std::set ) {
-  int FD = 0;
-  if (llvm::sys::fs::openFileForWrite(FilePath, FD, llvm::sys::fs::F_None))
-return false;
-  llvm::raw_fd_ostream OS(FD, true);
+bool WriteSymbolInfosToStream(llvm::raw_ostream ,
+  const std::set ) {
   llvm::yaml::Output yout(OS);
   for (auto Symbol : Symbols)
 yout << Symbol;
-  OS.close();
   return true;
 }
 
Index: 
clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
===
--- 
clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
+++ 
clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
@@ -59,10 +59,13 @@
 
   void Write(const std::string ) {
 for (const auto  : Symbols) {
-  SmallString<256> FilePath(Dir);
-  llvm::sys::path::append(
-  FilePath, llvm::sys::path::filename(Symbol.first) + ".yaml");
-  WriteSymboInfosToFile(FilePath, Symbol.second);
+  int FD;
+  SmallString<128> ResultPath;
+  llvm::sys::fs::createUniqueFile(
+  Dir + "/" + llvm::sys::path::filename(Symbol.first) + "-%%.yaml",
+  FD, ResultPath);
+  llvm::raw_fd_ostream OS(FD, /*shouldClose=*/true);
+  WriteSymbolInfosToStream(OS, Symbol.second);
 }
   }
 
@@ -90,7 +93,13 @@
   UniqueSymbols.insert(Symbol);
   }
 
-  WriteSymboInfosToFile(OutputFile, UniqueSymbols);
+  llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_None);
+  if (EC) {
+llvm::errs() << "Cann't open '" << OutputFile << "': " << EC.message()
+ << '\n';
+return false;
+  }
+  WriteSymbolInfosToStream(OS, UniqueSymbols);
   return true;
 }
 


Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
===
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.h
@@ -12,6 +12,7 @@
 
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 #include 
@@ -87,9 +88,9 @@
   bool operator<(const SymbolInfo ) const;
 };
 
-/// \brief Write SymbolInfos to a single file (YAML format).
-bool WriteSymboInfosToFile(llvm::StringRef FilePath,
-   const std::set );
+/// \brief Write SymbolInfos to a stream (YAML format).
+bool WriteSymbolInfosToStream(llvm::raw_ostream ,
+  const std::set );
 
 /// \brief Read SymbolInfos from a YAML document.
 std::vector ReadSymbolInfosFromYAML(llvm::StringRef Yaml);
Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
===
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/SymbolInfo.cpp
@@ -97,16 +97,11 @@
  std::tie(Symbol.Name, Symbol.FilePath, 

Re: [PATCH] D19720: [find-all-symbols] Parallelize the merge step.

2016-04-29 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268037: [find-all-symbols] Parallelize the merge step. 
(authored by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D19720?vs=55577=55589#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19720

Files:
  
clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp

Index: 
clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
===
--- 
clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
+++ 
clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
@@ -14,8 +14,9 @@
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Path.h"
-
+#include "llvm/Support/ThreadPool.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -76,26 +77,38 @@
 bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile) {
   std::error_code EC;
   std::set UniqueSymbols;
+  std::mutex SymbolMutex;
+  auto AddSymbols = [&](ArrayRef Symbols) {
+// Synchronize set accesses.
+std::unique_lock LockGuard(SymbolMutex);
+UniqueSymbols.insert(Symbols.begin(), Symbols.end());
+  };
+
   // Load all symbol files in MergeDir.
-  for (llvm::sys::fs::directory_iterator Dir(MergeDir, EC), DirEnd;
-   Dir != DirEnd && !EC; Dir.increment(EC)) {
-int ReadFD = 0;
-if (llvm::sys::fs::openFileForRead(Dir->path(), ReadFD)) {
-  llvm::errs() << "Cann't open " << Dir->path() << "\n";
-  continue;
+  {
+llvm::ThreadPool Pool;
+for (llvm::sys::fs::directory_iterator Dir(MergeDir, EC), DirEnd;
+ Dir != DirEnd && !EC; Dir.increment(EC)) {
+  // Parse YAML files in parallel.
+  Pool.async(
+  [](std::string Path) {
+auto Buffer = llvm::MemoryBuffer::getFile(Path);
+if (!Buffer) {
+  llvm::errs() << "Can't open " << Path << "\n";
+  return;
+}
+std::vector Symbols =
+ReadSymbolInfosFromYAML(Buffer.get()->getBuffer());
+// FIXME: Merge without creating such a heavy contention point.
+AddSymbols(Symbols);
+  },
+  Dir->path());
 }
-auto Buffer = llvm::MemoryBuffer::getOpenFile(ReadFD, Dir->path(), -1);
-if (!Buffer)
-  continue;
-std::vector Symbols =
-ReadSymbolInfosFromYAML(Buffer.get()->getBuffer());
-for (const auto  : Symbols)
-  UniqueSymbols.insert(Symbol);
   }
 
   llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_None);
   if (EC) {
-llvm::errs() << "Cann't open '" << OutputFile << "': " << EC.message()
+llvm::errs() << "Can't open '" << OutputFile << "': " << EC.message()
  << '\n';
 return false;
   }


Index: clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
===
--- clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
+++ clang-tools-extra/trunk/include-fixer/find-all-symbols/tool/FindAllSymbolsMain.cpp
@@ -14,8 +14,9 @@
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Path.h"
-
+#include "llvm/Support/ThreadPool.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -76,26 +77,38 @@
 bool Merge(llvm::StringRef MergeDir, llvm::StringRef OutputFile) {
   std::error_code EC;
   std::set UniqueSymbols;
+  std::mutex SymbolMutex;
+  auto AddSymbols = [&](ArrayRef Symbols) {
+// Synchronize set accesses.
+std::unique_lock LockGuard(SymbolMutex);
+UniqueSymbols.insert(Symbols.begin(), Symbols.end());
+  };
+
   // Load all symbol files in MergeDir.
-  for (llvm::sys::fs::directory_iterator Dir(MergeDir, EC), DirEnd;
-   Dir != DirEnd && !EC; Dir.increment(EC)) {
-int ReadFD = 0;
-if (llvm::sys::fs::openFileForRead(Dir->path(), ReadFD)) {
-  llvm::errs() << "Cann't open " << Dir->path() << "\n";
-  continue;
+  {
+llvm::ThreadPool Pool;
+for (llvm::sys::fs::directory_iterator Dir(MergeDir, EC), DirEnd;
+ Dir != DirEnd && !EC; Dir.increment(EC)) {
+  // Parse YAML files in parallel.
+  Pool.async(
+  [](std::string Path) {
+auto Buffer = llvm::MemoryBuffer::getFile(Path);
+if (!Buffer) {
+  llvm::errs() << "Can't open " << Path << "\n";
+  return;
+}
+std::vector Symbols =
+ReadSymbolInfosFromYAML(Buffer.get()->getBuffer());
+// FIXME: Merge without creating such a heavy contention point.
+AddSymbols(Symbols);
+  },
+  Dir->path());
 }
-auto Buffer = llvm::MemoryBuffer::getOpenFile(ReadFD, Dir->path(), -1);
-if (!Buffer)
-  continue;
-std::vector Symbols =
-

Re: [PATCH] D19477: [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-26 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL267534: [MSVC] PR27337: allow static_cast from private base 
to derived for WTL (authored by dpolukhin).

Changed prior to commit:
  http://reviews.llvm.org/D19477?vs=54829=54975#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19477

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaCast.cpp
  cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5764,6 +5764,9 @@
   "cannot cast %0 to %1 via virtual base %2">;
 def err_downcast_from_inaccessible_base : Error<
   "cannot cast %select{private|protected}2 base class %1 to %0">;
+def ext_ms_downcast_from_inaccessible_base : ExtWarn<
+  "casting from %select{private|protected}2 base class %1 to derived class %0 
is a Microsoft extension">,
+  InGroup;
 def err_upcast_to_inaccessible_base : Error<
   "cannot cast %0 to its %select{private|protected}2 base class %1">;
 def err_bad_dynamic_cast_not_ref_or_ptr : Error<
Index: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
===
--- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
+++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s
+
+// Minimal reproducer.
+class A {};
+class B : A {}; // expected-note 2 {{implicitly declared private here}}
+
+B* foo(A* p) {
+  return static_cast(p);
+#ifdef NO_MS_COMPATIBILITY
+  // expected-error@-2 {{cannot cast private base class 'A' to 'B'}}
+#else
+  // expected-warning@-4 {{casting from private base class 'A' to derived 
class 'B' is a Microsoft extension}}
+#endif
+}
+
+A* bar(B* p) {
+  return static_cast(p); // expected-error {{cannot cast 'B' to its 
private base class 'A'}}
+}
+
+// from atlframe.h
+template 
+class CUpdateUI {
+public:
+  CUpdateUI() {
+T* pT = static_cast(this);
+#ifdef NO_MS_COMPATIBILITY
+// expected-error@-2 {{cannot cast private base class}}
+#else
+// expected-warning@-4 {{casting from private base class 
'CUpdateUI' to derived class 'CMDIFrame' is a Microsoft extension}}
+#endif
+  }
+};
+
+// from sample WTL/MDIDocVw (mainfrm.h
+class CMDIFrame : CUpdateUI {};
+// expected-note@-1 {{implicitly declared private here}}
+// expected-note@-2 {{in instantiation of member function}}
+
+CMDIFrame wndMain;
Index: cfe/trunk/lib/Sema/SemaCast.cpp
===
--- cfe/trunk/lib/Sema/SemaCast.cpp
+++ cfe/trunk/lib/Sema/SemaCast.cpp
@@ -1344,10 +1344,11 @@
   }
 
   if (!CStyle) {
-switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
-  SrcType, DestType,
-  Paths.front(),
-diag::err_downcast_from_inaccessible_base)) {
+unsigned Diag = Self.getLangOpts().MSVCCompat
+? diag::ext_ms_downcast_from_inaccessible_base
+: diag::err_downcast_from_inaccessible_base;
+switch (Self.CheckBaseClassAccess(OpRange.getBegin(), SrcType, DestType,
+  Paths.front(), Diag)) {
 case Sema::AR_accessible:
 case Sema::AR_delayed: // be optimistic
 case Sema::AR_dependent:   // be optimistic


Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5764,6 +5764,9 @@
   "cannot cast %0 to %1 via virtual base %2">;
 def err_downcast_from_inaccessible_base : Error<
   "cannot cast %select{private|protected}2 base class %1 to %0">;
+def ext_ms_downcast_from_inaccessible_base : ExtWarn<
+  "casting from %select{private|protected}2 base class %1 to derived class %0 is a Microsoft extension">,
+  InGroup;
 def err_upcast_to_inaccessible_base : Error<
   "cannot cast %0 to its %select{private|protected}2 base class %1">;
 def err_bad_dynamic_cast_not_ref_or_ptr : Error<
Index: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
===
--- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
+++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s
+// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s
+
+// Minimal reproducer.
+class A {};
+class B : A {}; // expected-note 2 {{implicitly declared private here}}
+
+B* foo(A* p) {
+  return static_cast(p);
+#ifdef NO_MS_COMPATIBILITY
+  // expected-error@-2 {{cannot cast private 

Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-04-26 Thread Krystyna via cfe-commits
krystyna updated this revision to Diff 54974.
krystyna marked an inline comment as done.

Repository:
  rL LLVM

http://reviews.llvm.org/D18919

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseUsingCheck.cpp
  clang-tidy/modernize/UseUsingCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-using.rst
  test/clang-tidy/modernize-use-using.cpp

Index: test/clang-tidy/modernize-use-using.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-using.cpp
@@ -0,0 +1,83 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t
+
+
+typedef int Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Type = int;
+
+typedef long LL;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using LL = long;
+
+typedef int Bla;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Bla = int;
+
+typedef Bla Bla2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Bla2 = Bla;
+
+typedef void (*type)(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using type = void (*)(int);
+
+typedef void (*type2)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using type2 = void (*)();
+
+class Class {
+typedef long long Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef [modernize-use-using]
+	// CHECK-FIXES: using Type = long long;
+};
+
+typedef void (Class::* MyPtrType)(Bla) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using MyPtrType = void (Class::*)(Bla) const;
+
+class Iterable {
+public:
+	class Iterator {};
+};
+
+template
+class Test {
+typedef typename T::iterator Iter;
+	// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef [modernize-use-using]
+	// CHECK-FIXES: using Iter = typename T::iterator;
+};
+
+using balba = long long;
+
+union A {};
+
+typedef void (A::*PtrType)(int, int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using PtrType = void (A::*)(int, int) const;
+
+typedef Class some_class;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using some_class = Class;
+
+typedef Class Cclass;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Cclass = Class;
+typedef Cclass cclass2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using cclass2 = Cclass;
+
+class cclass {
+
+};
+
+typedef void (cclass::* MyPtrType3)(Bla);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla);
+
+using my_class = int;
+
+typedef Test another;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using another = Test;
+
+
Index: docs/clang-tidy/checks/modernize-use-using.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-using.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - modernize-use-using
+
+modernize-use-using
+===
+
+Use C++11's ``using`` instead of ``typedef``.
+
+Before:
+
+.. code:: c++
+
+  typedef int variable;
+
+  class Class{};
+  typedef void (Class::* MyPtrType)() const;
+
+After:
+
+.. code:: c++
+
+  using varible = int;
+
+  class Class{};
+  using MyPtrType = void (Class::*)() const;
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -85,6 +85,7 @@
modernize-use-default
modernize-use-nullptr
modernize-use-override
+   modernize-use-using
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
Index: clang-tidy/modernize/UseUsingCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseUsingCheck.h
@@ -0,0 +1,35 @@
+//===--- UseUsingCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef 

Re: [PATCH] D19003: Set C99 as default C Standard for PS4 target

2016-04-27 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL267772: Set the default C standard to C99 when targeting the 
PS4. (authored by ssrivastava).

Changed prior to commit:
  http://reviews.llvm.org/D19003?vs=54956=55299#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19003

Files:
  cfe/trunk/include/clang/Frontend/CompilerInvocation.h
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/FixIt/fixit-errors.c
  cfe/trunk/test/Preprocessor/init.c
  cfe/trunk/test/Sema/attr-deprecated.c
  cfe/trunk/test/Sema/nullability.c
  cfe/trunk/test/SemaObjC/objcbridge-attribute-arc.m

Index: cfe/trunk/include/clang/Frontend/CompilerInvocation.h
===
--- cfe/trunk/include/clang/Frontend/CompilerInvocation.h
+++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h
@@ -153,8 +153,10 @@
   ///
   /// \param Opts - The LangOptions object to set up.
   /// \param IK - The input language.
+  /// \param T - The target triple.
   /// \param LangStd - The input language standard.
   static void setLangDefaults(LangOptions , InputKind IK,
+   const llvm::Triple ,
LangStandard::Kind LangStd = LangStandard::lang_unspecified);
   
   /// \brief Retrieve a module hash string that is suitable for uniquely 
Index: cfe/trunk/test/Preprocessor/init.c
===
--- cfe/trunk/test/Preprocessor/init.c
+++ cfe/trunk/test/Preprocessor/init.c
@@ -88,7 +88,6 @@
 // COMMON:#define __ORDER_LITTLE_ENDIAN__ 1234
 // COMMON:#define __ORDER_PDP_ENDIAN__ 3412
 // COMMON:#define __STDC_HOSTED__ 1
-// COMMON:#define __STDC_VERSION__ 201112L
 // COMMON:#define __STDC__ 1
 // COMMON:#define __VERSION__ {{.*}}
 // COMMON:#define __clang__ 1
@@ -98,7 +97,13 @@
 // COMMON:#define __clang_version__ {{.*}}
 // COMMON:#define __llvm__ 1
 //
+// RUN: %clang_cc1 -E -dM -triple=x86_64-pc-win32 < /dev/null | FileCheck -match-full-lines -check-prefix C-DEFAULT %s
+// RUN: %clang_cc1 -E -dM -triple=x86_64-pc-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix C-DEFAULT %s
+// RUN: %clang_cc1 -E -dM -triple=x86_64-apple-darwin < /dev/null | FileCheck -match-full-lines -check-prefix C-DEFAULT %s
+// RUN: %clang_cc1 -E -dM -triple=armv7a-apple-darwin < /dev/null | FileCheck -match-full-lines -check-prefix C-DEFAULT %s
 // 
+// C-DEFAULT:#define __STDC_VERSION__ 201112L
+//
 // RUN: %clang_cc1 -ffreestanding -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix FREESTANDING %s
 // FREESTANDING:#define __STDC_HOSTED__ 0
 //
@@ -8361,6 +8366,7 @@
 // PS4:#define __SSE2__ 1
 // PS4:#define __SSE_MATH__ 1
 // PS4:#define __SSE__ 1
+// PS4:#define __STDC_VERSION__ 199901L
 // PS4:#define __UINTMAX_TYPE__ long unsigned int
 // PS4:#define __USER_LABEL_PREFIX__
 // PS4:#define __WCHAR_MAX__ 65535
Index: cfe/trunk/test/Sema/attr-deprecated.c
===
--- cfe/trunk/test/Sema/attr-deprecated.c
+++ cfe/trunk/test/Sema/attr-deprecated.c
@@ -122,5 +122,10 @@
 };
 
 typedef int test23_ty __attribute((deprecated));
+// Redefining a typedef is a C11 feature.
+#if __STDC_VERSION__ <= 199901L
+// expected-note@-3 {{'test23_ty' has been explicitly marked deprecated here}}
+#else
 typedef int test23_ty; // expected-note {{'test23_ty' has been explicitly marked deprecated here}}
+#endif
 test23_ty test23_v; // expected-warning {{'test23_ty' is deprecated}}
Index: cfe/trunk/test/Sema/nullability.c
===
--- cfe/trunk/test/Sema/nullability.c
+++ cfe/trunk/test/Sema/nullability.c
@@ -8,7 +8,11 @@
 typedef int * int_ptr;
 
 // Parse nullability type specifiers.
-typedef int * _Nonnull nonnull_int_ptr; // expected-note{{'_Nonnull' specified here}}
+// This note requires C11.
+#if __STDC_VERSION__ > 199901L
+// expected-note@+2{{'_Nonnull' specified here}}
+#endif
+typedef int * _Nonnull nonnull_int_ptr;
 typedef int * _Nullable nullable_int_ptr;
 typedef int * _Null_unspecified null_unspecified_int_ptr;
 
@@ -23,9 +27,14 @@
 typedef nonnull_int_ptr _Nonnull redundant_okay_1;
 
 // Conflicting nullability specifiers via a typedef are not.
+// Some of these errors require C11.
+#if __STDC_VERSION__ > 199901L
 typedef nonnull_int_ptr _Nullable conflicting_2; // expected-error{{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}}
+#endif
 typedef nonnull_int_ptr nonnull_int_ptr_typedef;
+#if __STDC_VERSION__ > 199901L
 typedef nonnull_int_ptr_typedef _Nullable conflicting_2; // expected-error{{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}}
+#endif
 typedef nonnull_int_ptr_typedef nonnull_int_ptr_typedef_typedef;
 typedef nonnull_int_ptr_typedef_typedef _Null_unspecified conflicting_3; // expected-error{{nullability specifier '_Null_unspecified' conflicts with existing specifier 

Re: [PATCH] D19693: [Clang][Darwin] Define __ARM_DWARF_EH__ for WatchABI

2016-04-29 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268078: [Clang][Darwin] Define __ARM_DWARF_EH__ for WatchABI 
(authored by cbieneman).

Changed prior to commit:
  http://reviews.llvm.org/D19693?vs=55626=55627#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19693

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/Preprocessor/arm-target-features.c

Index: cfe/trunk/test/Preprocessor/arm-target-features.c
===
--- cfe/trunk/test/Preprocessor/arm-target-features.c
+++ cfe/trunk/test/Preprocessor/arm-target-features.c
@@ -217,6 +217,7 @@
 // ARMV7K:#define __ARM_ARCH 7
 // ARMV7K:#define __ARM_ARCH_EXT_IDIV__ 1
 // ARMV7K:#define __ARM_ARCH_PROFILE 'A'
+// ARMV7K:#define __ARM_DWARF_EH__ 1
 // ARMV7K:#define __ARM_FEATURE_DSP 1
 // ARMV7K:#define __ARM_FP 0xE
 // ARMV7K:#define __ARM_PCS_VFP 1
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -208,6 +208,10 @@
   if (Triple.isOSDarwin())
 Builder.defineMacro("__MACH__");
 
+  // The Watch ABI uses Dwarf EH.
+  if(Triple.isWatchABI())
+Builder.defineMacro("__ARM_DWARF_EH__");
+
   PlatformMinVersion = VersionTuple(Maj, Min, Rev);
 }
 


Index: cfe/trunk/test/Preprocessor/arm-target-features.c
===
--- cfe/trunk/test/Preprocessor/arm-target-features.c
+++ cfe/trunk/test/Preprocessor/arm-target-features.c
@@ -217,6 +217,7 @@
 // ARMV7K:#define __ARM_ARCH 7
 // ARMV7K:#define __ARM_ARCH_EXT_IDIV__ 1
 // ARMV7K:#define __ARM_ARCH_PROFILE 'A'
+// ARMV7K:#define __ARM_DWARF_EH__ 1
 // ARMV7K:#define __ARM_FEATURE_DSP 1
 // ARMV7K:#define __ARM_FP 0xE
 // ARMV7K:#define __ARM_PCS_VFP 1
Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -208,6 +208,10 @@
   if (Triple.isOSDarwin())
 Builder.defineMacro("__MACH__");
 
+  // The Watch ABI uses Dwarf EH.
+  if(Triple.isWatchABI())
+Builder.defineMacro("__ARM_DWARF_EH__");
+
   PlatformMinVersion = VersionTuple(Maj, Min, Rev);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19727: [MS] Improved implementation #pragma pack (MS pragmas, part 2)

2016-04-29 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268085: [MS] Make #pragma pack use PragmaStack<> class. 
(authored by dzobnin).

Changed prior to commit:
  http://reviews.llvm.org/D19727?vs=55598=55634#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19727

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Parse/ParsePragma.cpp
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/lib/Sema/SemaAttr.cpp

Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -317,10 +317,6 @@
   /// This is used as part of a hack to omit that class from ADL results.
   DeclarationName VAListTagName;
 
-  /// PackContext - Manages the stack for \#pragma pack. An alignment
-  /// of 0 indicates default alignment.
-  void *PackContext; // Really a "PragmaPackStack*"
-
   bool MSStructPragmaOn; // True when \#pragma ms_struct on
 
   /// \brief Controls member pointer representation format under the MS ABI.
@@ -338,6 +334,7 @@
 PSK_Set   = 0x1,// #pragma (value)
 PSK_Push  = 0x2,// #pragma (push[, id])
 PSK_Pop   = 0x4,// #pragma (pop[, id])
+PSK_Show  = 0x8,// #pragma (show) -- only for "pack"!
 PSK_Push_Set  = PSK_Push | PSK_Set, // #pragma (push[, id], value)
 PSK_Pop_Set   = PSK_Pop | PSK_Set,  // #pragma (pop[, id], value)
   };
@@ -400,11 +397,15 @@
   /// 2: Always insert vtordisps to support RTTI on partially constructed
   ///objects
   PragmaStack VtorDispStack;
+  // #pragma pack.
+  // Sentinel to represent when the stack is set to mac68k alignment.
+  static const unsigned kMac68kAlignmentSentinel = ~0U;
+  PragmaStack PackStack;
+  // Segment #pragmas.
   PragmaStack DataSegStack;
   PragmaStack BSSSegStack;
   PragmaStack ConstSegStack;
   PragmaStack CodeSegStack;
-  // TODO: Change implementation of #pragma pack to use PragmaStack<> approach.
 
   // RAII object to push / pop sentinel slots for all MS #pragma stacks.
   // Actions should be performed only if we enter / exit a C++ method body.
@@ -7658,20 +7659,9 @@
   void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
SourceLocation PragmaLoc);
 
-  enum PragmaPackKind {
-PPK_Default, // #pragma pack([n])
-PPK_Show,// #pragma pack(show), only supported by MSVC.
-PPK_Push,// #pragma pack(push, [identifier], [n])
-PPK_Pop  // #pragma pack(pop, [identifier], [n])
-  };
-
   /// ActOnPragmaPack - Called on well formed \#pragma pack(...).
-  void ActOnPragmaPack(PragmaPackKind Kind,
-   IdentifierInfo *Name,
-   Expr *Alignment,
-   SourceLocation PragmaLoc,
-   SourceLocation LParenLoc,
-   SourceLocation RParenLoc);
+  void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action,
+   StringRef SlotLabel, Expr *Alignment);
 
   /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off].
   void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
Index: cfe/trunk/lib/Sema/Sema.cpp
===
--- cfe/trunk/lib/Sema/Sema.cpp
+++ cfe/trunk/lib/Sema/Sema.cpp
@@ -79,12 +79,13 @@
 Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()),
 CollectStats(false), CodeCompleter(CodeCompleter),
 CurContext(nullptr), OriginalLexicalContext(nullptr),
-PackContext(nullptr), MSStructPragmaOn(false),
+MSStructPragmaOn(false),
 MSPointerToMemberRepresentationMethod(
 LangOpts.getMSPointerToMemberRepresentationMethod()),
 VtorDispStack(MSVtorDispAttr::Mode(LangOpts.VtorDispMode)),
-DataSegStack(nullptr), BSSSegStack(nullptr), ConstSegStack(nullptr),
-CodeSegStack(nullptr), CurInitSeg(nullptr), VisContext(nullptr),
+PackStack(0), DataSegStack(nullptr), BSSSegStack(nullptr),
+ConstSegStack(nullptr), CodeSegStack(nullptr), CurInitSeg(nullptr),
+VisContext(nullptr),
 IsBuildingRecoveryCallExpr(false),
 ExprNeedsCleanups(false), LateTemplateParser(nullptr),
 LateTemplateParserCleanup(nullptr),
@@ -252,7 +253,6 @@
 
 Sema::~Sema() {
   llvm::DeleteContainerSeconds(LateParsedTemplateMap);
-  if (PackContext) FreePackedContext();
   if (VisContext) FreeVisContext();
   // Kill all the active scopes.
   for (unsigned I = 1, E = FunctionScopes.size(); I != E; ++I)
Index: cfe/trunk/lib/Sema/SemaAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaAttr.cpp
+++ cfe/trunk/lib/Sema/SemaAttr.cpp
@@ -25,86 +25,6 @@
 // Pragma 'pack' and 'options align'
 //===--===//
 
-namespace {
-  struct PackStackEntry {
-// We just use a sentinel to represent when the 

Re: [PATCH] D16298: Improve test coverage of -Wdouble-promotion

2016-04-29 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268075: Improve test coverage of -Wdouble-promotion 
(authored by rlougher).

Changed prior to commit:
  http://reviews.llvm.org/D16298?vs=45195=55625#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D16298

Files:
  cfe/trunk/test/Sema/warn-double-promotion.c

Index: cfe/trunk/test/Sema/warn-double-promotion.c
===
--- cfe/trunk/test/Sema/warn-double-promotion.c
+++ cfe/trunk/test/Sema/warn-double-promotion.c
@@ -24,11 +24,51 @@
   return d;  //expected-warning{{implicit conversion increases floating-point 
precision: 'double' to 'long double'}}
 }
 
-void Convert(float f, double d, long double ld) {
+void Assignment(float f, double d, long double ld) {
   d = f;  //expected-warning{{implicit conversion increases floating-point 
precision: 'float' to 'double'}}
   ld = f; //expected-warning{{implicit conversion increases floating-point 
precision: 'float' to 'long double'}}
   ld = d; //expected-warning{{implicit conversion increases floating-point 
precision: 'double' to 'long double'}}
   f = d;
   f = ld;
   d = ld;
 }
+
+extern void DoubleParameter(double);
+extern void LongDoubleParameter(long double);
+
+void ArgumentPassing(float f, double d) {
+  DoubleParameter(f); // expected-warning{{implicit conversion increases 
floating-point precision: 'float' to 'double'}}
+  LongDoubleParameter(f); // expected-warning{{implicit conversion increases 
floating-point precision: 'float' to 'long double'}}
+  LongDoubleParameter(d); // expected-warning{{implicit conversion increases 
floating-point precision: 'double' to 'long double'}}
+}
+
+void BinaryOperator(float f, double d, long double ld) {
+  f = f * d; // expected-warning{{implicit conversion increases floating-point 
precision: 'float' to 'double'}}
+  f = d * f; // expected-warning{{implicit conversion increases floating-point 
precision: 'float' to 'double'}}
+  f = f * ld; // expected-warning{{implicit conversion increases 
floating-point precision: 'float' to 'long double'}}
+  f = ld * f; // expected-warning{{implicit conversion increases 
floating-point precision: 'float' to 'long double'}}
+  d = d * ld; // expected-warning{{implicit conversion increases 
floating-point precision: 'double' to 'long double'}}
+  d = ld * d; // expected-warning{{implicit conversion increases 
floating-point precision: 'double' to 'long double'}}
+}
+
+void MultiplicationAssignment(float f, double d, long double ld) {
+  d *= f; // expected-warning{{implicit conversion increases floating-point 
precision: 'float' to 'double'}}
+  ld *= f; // expected-warning{{implicit conversion increases floating-point 
precision: 'float' to 'long double'}}
+  ld *= d; // expected-warning{{implicit conversion increases floating-point 
precision: 'double' to 'long double'}}
+
+  // FIXME: These cases should produce warnings as above.
+  f *= d;
+  f *= ld;
+  d *= ld;
+}
+
+// FIXME: As with a binary operator, the operands to the conditional operator 
are
+// converted to a common type and should produce a warning.
+void ConditionalOperator(float f, double d, long double ld, int i) {
+  f = i ? f : d;
+  f = i ? d : f;
+  f = i ? f : ld;
+  f = i ? ld : f;
+  d = i ? d : ld;
+  d = i ? ld : d;
+}


Index: cfe/trunk/test/Sema/warn-double-promotion.c
===
--- cfe/trunk/test/Sema/warn-double-promotion.c
+++ cfe/trunk/test/Sema/warn-double-promotion.c
@@ -24,11 +24,51 @@
   return d;  //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}}
 }
 
-void Convert(float f, double d, long double ld) {
+void Assignment(float f, double d, long double ld) {
   d = f;  //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}}
   ld = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}}
   ld = d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}}
   f = d;
   f = ld;
   d = ld;
 }
+
+extern void DoubleParameter(double);
+extern void LongDoubleParameter(long double);
+
+void ArgumentPassing(float f, double d) {
+  DoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}}
+  LongDoubleParameter(f); // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}}
+  LongDoubleParameter(d); // expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}}
+}
+
+void BinaryOperator(float f, double d, long double ld) {
+  f = f * d; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}}
+  f = d * f; // expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}}
+  f = f * 

Re: [PATCH] D20401: [Lexer] Don't merge macro args from different macro files

2016-05-19 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL270160: [Lexer] Don't merge macro args from different macro 
files (authored by vedantk).

Changed prior to commit:
  http://reviews.llvm.org/D20401?vs=57810=57880#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20401

Files:
  cfe/trunk/lib/Lex/TokenLexer.cpp
  cfe/trunk/test/CoverageMapping/Inputs/macros.h
  cfe/trunk/test/CoverageMapping/include-macros.c
  cfe/trunk/unittests/Lex/LexerTest.cpp

Index: cfe/trunk/test/CoverageMapping/Inputs/macros.h
===
--- cfe/trunk/test/CoverageMapping/Inputs/macros.h
+++ cfe/trunk/test/CoverageMapping/Inputs/macros.h
@@ -0,0 +1,13 @@
+// Assorted macros to help test #include behavior across file boundaries.
+
+#define helper1 0
+
+void helper2(const char *, ...);
+
+#define M1(a, ...) helper2(a, ##__VA_ARGS__);
+
+// Note: M2 stresses vararg macro functions with macro arguments. The spelling
+// locations of the args used to be set to the expansion site, leading to
+// crashes (region LineEnd < LineStart). The regression test requires M2's line
+// number to be greater than the line number containing the expansion.
+#define M2(a, ...) M1(a, helper1, ##__VA_ARGS__);
Index: cfe/trunk/test/CoverageMapping/include-macros.c
===
--- cfe/trunk/test/CoverageMapping/include-macros.c
+++ cfe/trunk/test/CoverageMapping/include-macros.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name include-macros.c %s | FileCheck %s
+
+#include "Inputs/macros.h"
+
+void f1() {
+  M2("a", "b");
+}
+
+// CHECK-LABEL: f1:
+// CHECK-NEXT:   File 0, 5:11 -> 7:2 = #0
+// CHECK-NEXT:   Expansion,File 0, 6:3 -> 6:5 = #0 (Expanded file = 1)
+// CHECK-NEXT:   File 1, 13:20 -> 13:50 = #0
+// CHECK-NEXT:   Expansion,File 1, 13:20 -> 13:22 = #0 (Expanded file = 2)
+// CHECK-NEXT:   File 2, 7:20 -> 7:46 = #0
+// CHECK-NEXT:   Expansion,File 2, 7:33 -> 7:44 = #0 (Expanded file = 3)
+// CHECK-NEXT:   File 3, 13:26 -> 13:34 = #0
+// CHECK-NEXT:   Expansion,File 3, 13:26 -> 13:33 = #0 (Expanded file = 4)
+// CHECK-NEXT:   File 4, 3:17 -> 3:18 = #0
Index: cfe/trunk/lib/Lex/TokenLexer.cpp
===
--- cfe/trunk/lib/Lex/TokenLexer.cpp
+++ cfe/trunk/lib/Lex/TokenLexer.cpp
@@ -787,6 +787,9 @@
 if (CurLoc.isFileID() != NextLoc.isFileID())
   break; // Token from different kind of FileID.
 
+if (CurLoc.isMacroID() && !SM.isWrittenInSameFile(CurLoc, NextLoc))
+  break; // Token from a different macro.
+
 int RelOffs;
 if (!SM.isInSameSLocAddrSpace(CurLoc, NextLoc, ))
   break; // Token from different local/loaded location.
Index: cfe/trunk/unittests/Lex/LexerTest.cpp
===
--- cfe/trunk/unittests/Lex/LexerTest.cpp
+++ cfe/trunk/unittests/Lex/LexerTest.cpp
@@ -58,8 +58,7 @@
 Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
   }
 
-  std::vector CheckLex(StringRef Source,
-  ArrayRef ExpectedTokens) {
+  std::vector Lex(StringRef Source) {
 std::unique_ptr Buf =
 llvm::MemoryBuffer::getMemBuffer(Source);
 SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
@@ -82,6 +81,12 @@
   toks.push_back(tok);
 }
 
+return toks;
+  }
+
+  std::vector CheckLex(StringRef Source,
+  ArrayRef ExpectedTokens) {
+auto toks = Lex(Source);
 EXPECT_EQ(ExpectedTokens.size(), toks.size());
 for (unsigned i = 0, e = ExpectedTokens.size(); i != e; ++i) {
   EXPECT_EQ(ExpectedTokens[i], toks[i].getKind());
@@ -358,4 +363,21 @@
   EXPECT_EQ("N", Lexer::getImmediateMacroName(idLoc4, SourceMgr, LangOpts));
 }
 
+TEST_F(LexerTest, DontMergeMacroArgsFromDifferentMacroFiles) {
+  std::vector toks =
+  Lex("#define helper1 0\n"
+  "void helper2(const char *, ...);\n"
+  "#define M1(a, ...) helper2(a, ##__VA_ARGS__)\n"
+  "#define M2(a, ...) M1(a, helper1, ##__VA_ARGS__)\n"
+  "void f1() { M2(\"a\", \"b\"); }");
+
+  // Check the file corresponding to the "helper1" macro arg in M2.
+  //
+  // The lexer used to report its size as 31, meaning that the end of the
+  // expansion would be on the *next line* (just past `M2("a", "b")`). Make
+  // sure that we get the correct end location (the comma after "helper1").
+  SourceLocation helper1ArgLoc = toks[20].getLocation();
+  EXPECT_EQ(SourceMgr.getFileIDSize(SourceMgr.getFileID(helper1ArgLoc)), 8U);
+}
+
 } // anonymous namespace
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20521: [Clang][AVX512][Builtin] adding missing intrinsics for vpmultishiftqb{128|256|512} instruction set

2016-05-23 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL270441: [clang][AVX512][Builtin] adding missing intrinsics 
for… (authored by mzuckerm).

Changed prior to commit:
  http://reviews.llvm.org/D20521?vs=58086=58098#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20521

Files:
  cfe/trunk/include/clang/Basic/BuiltinsX86.def
  cfe/trunk/lib/Headers/avx512vbmiintrin.h
  cfe/trunk/lib/Headers/avx512vbmivlintrin.h
  cfe/trunk/test/CodeGen/avx512vbmi-builtins.c
  cfe/trunk/test/CodeGen/avx512vbmivl-builtin.c

Index: cfe/trunk/include/clang/Basic/BuiltinsX86.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def
@@ -2276,6 +2276,9 @@
 TARGET_BUILTIN(__builtin_ia32_cvtusi2sd64, "V2dV2dULLiIi","","avx512f")
 TARGET_BUILTIN(__builtin_ia32_cvtusi2ss32, "V4fV4fUiIi","","avx512f")
 TARGET_BUILTIN(__builtin_ia32_cvtusi2ss64, "V4fV4fULLiIi","","avx512f")
+TARGET_BUILTIN(__builtin_ia32_vpmultishiftqb512_mask, "V64cV64cV64cV64cULLi","","avx512vbmi")
+TARGET_BUILTIN(__builtin_ia32_vpmultishiftqb128_mask, "V16cV16cV16cV16cUs","","avx512vbmi,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_vpmultishiftqb256_mask, "V32cV32cV32cV32cUi","","avx512vbmi,avx512vl")
 
 // MONITORX/MWAITX
 TARGET_BUILTIN(__builtin_ia32_monitorx, "vv*UiUi", "", "mwaitx")
Index: cfe/trunk/test/CodeGen/avx512vbmivl-builtin.c
===
--- cfe/trunk/test/CodeGen/avx512vbmivl-builtin.c
+++ cfe/trunk/test/CodeGen/avx512vbmivl-builtin.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-feature avx512vbmi -target-feature avx512vl -target-feature avx2 -emit-llvm -o - -Werror | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-feature +avx512vbmi -target-feature +avx512vl -target-feature +avx512bw -emit-llvm -o - -Werror | FileCheck %s
 
 // Don't include mm_malloc.h, it's system specific.
 #define __MM_MALLOC_H
@@ -85,6 +85,43 @@
 
 __m256i test_mm256_maskz_permutex2var_epi8(__mmask32 __U, __m256i __A, __m256i __I, __m256i __B) {
   // CHECK-LABEL: @test_mm256_maskz_permutex2var_epi8
-  // CHECK: @llvm.x86.avx512.mask.vpermt2var.qi.256
+  // CHECK: @llvm.x86.avx512.maskz.vpermt2var.qi.256
   return _mm256_maskz_permutex2var_epi8(__U, __A, __I, __B); 
-}
\ No newline at end of file
+}
+
+__m128i test_mm_mask_multishift_epi64_epi8(__m128i __W, __mmask16 __M, __m128i __X, __m128i __Y) {
+  // CHECK-LABEL: @test_mm_mask_multishift_epi64_epi8
+  // CHECK: @llvm.x86.avx512.mask.pmultishift.qb.128
+  return _mm_mask_multishift_epi64_epi8(__W, __M, __X, __Y); 
+}
+
+__m128i test_mm_maskz_multishift_epi64_epi8(__mmask16 __M, __m128i __X, __m128i __Y) {
+  // CHECK-LABEL: @test_mm_maskz_multishift_epi64_epi8
+  // CHECK: @llvm.x86.avx512.mask.pmultishift.qb.128
+  return _mm_maskz_multishift_epi64_epi8(__M, __X, __Y); 
+}
+
+__m128i test_mm_multishift_epi64_epi8(__m128i __X, __m128i __Y) {
+  // CHECK-LABEL: @test_mm_multishift_epi64_epi8
+  // CHECK: @llvm.x86.avx512.mask.pmultishift.qb.128
+  return _mm_multishift_epi64_epi8(__X, __Y); 
+}
+
+__m256i test_mm256_mask_multishift_epi64_epi8(__m256i __W, __mmask32 __M, __m256i __X, __m256i __Y) {
+  // CHECK-LABEL: @test_mm256_mask_multishift_epi64_epi8
+  // CHECK: @llvm.x86.avx512.mask.pmultishift.qb.256
+  return _mm256_mask_multishift_epi64_epi8(__W, __M, __X, __Y); 
+}
+
+__m256i test_mm256_maskz_multishift_epi64_epi8(__mmask32 __M, __m256i __X, __m256i __Y) {
+  // CHECK-LABEL: @test_mm256_maskz_multishift_epi64_epi8
+  // CHECK: @llvm.x86.avx512.mask.pmultishift.qb.256
+  return _mm256_maskz_multishift_epi64_epi8(__M, __X, __Y); 
+}
+
+__m256i test_mm256_multishift_epi64_epi8(__m256i __X, __m256i __Y) {
+  // CHECK-LABEL: @test_mm256_multishift_epi64_epi8
+  // CHECK: @llvm.x86.avx512.mask.pmultishift.qb.256
+  return _mm256_multishift_epi64_epi8(__X, __Y); 
+}
+
Index: cfe/trunk/test/CodeGen/avx512vbmi-builtins.c
===
--- cfe/trunk/test/CodeGen/avx512vbmi-builtins.c
+++ cfe/trunk/test/CodeGen/avx512vbmi-builtins.c
@@ -46,3 +46,21 @@
   // CHECK: @llvm.x86.avx512.mask.permvar.qi.512
   return _mm512_mask_permutexvar_epi8(__W, __M, __A, __B); 
 }
+
+__m512i test_mm512_mask_multishift_epi64_epi8(__m512i __W, __mmask64 __M, __m512i __X, __m512i __Y) {
+  // CHECK-LABEL: @test_mm512_mask_multishift_epi64_epi8
+  // CHECK: @llvm.x86.avx512.mask.pmultishift.qb.512
+  return _mm512_mask_multishift_epi64_epi8(__W, __M, __X, __Y); 
+}
+
+__m512i test_mm512_maskz_multishift_epi64_epi8(__mmask64 __M, __m512i __X, __m512i __Y) {
+  // CHECK-LABEL: @test_mm512_maskz_multishift_epi64_epi8
+  // CHECK: @llvm.x86.avx512.mask.pmultishift.qb.512
+  return _mm512_maskz_multishift_epi64_epi8(__M, __X, __Y); 
+}
+
+__m512i test_mm512_multishift_epi64_epi8(__m512i __X, __m512i __Y) {
+  // CHECK-LABEL: 

Re: [PATCH] D20089: Adding a TargetParser for AArch64

2016-05-24 Thread jojo.ma via cfe-commits
jojo updated this revision to Diff 58381.
jojo added a comment.

1.include/llvm/Support/TargetParser.h

  Move move the declaration of getArchFeatures to a more reasonable place.
  Remove unnecessary parameter for getDefaultCPU.

2.lib/Support/TargetParser.cpp

  Make adjustments according to TargetParser.h.


Repository:
  rL LLVM

http://reviews.llvm.org/D20089

Files:
  include/llvm/Support/AArch64TargetParser.def
  include/llvm/Support/ARMTargetParser.def
  include/llvm/Support/TargetParser.h
  lib/Support/TargetParser.cpp

Index: lib/Support/TargetParser.cpp
===
--- lib/Support/TargetParser.cpp
+++ lib/Support/TargetParser.cpp
@@ -21,6 +21,7 @@
 
 using namespace llvm;
 using namespace ARM;
+using namespace AArch64;
 
 namespace {
 
@@ -75,6 +76,11 @@
   {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH,   \
sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR},
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64ARCHNames[] = {
+#define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT)   \
+  {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH,   \
+   sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR},
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 // List of Arch Extension names.
@@ -91,6 +97,10 @@
 #define ARM_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
   { NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE },
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64ARCHExtNames[] = {
+#define AARCH64_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
+  { NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE },
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 // List of HWDiv names (use getHWDivSynonym) and which architectural
@@ -124,6 +134,10 @@
 #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
   { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT },
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64CPUNames[] = {
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+  { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT },
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 } // namespace
@@ -369,6 +383,153 @@
   return "generic";
 }
 
+StringRef llvm::AArch64::getFPUName(unsigned FPUKind) {
+  return ARM::getFPUName(FPUKind);
+}
+
+unsigned llvm::AArch64::getFPUVersion(unsigned FPUKind) {
+  return ARM::getFPUVersion(FPUKind);
+}
+
+unsigned llvm::AArch64::getFPUNeonSupportLevel(unsigned FPUKind) {
+  return ARM::getFPUNeonSupportLevel( FPUKind);
+}
+
+unsigned llvm::AArch64::getFPURestriction(unsigned FPUKind) {
+  return ARM::getFPURestriction(FPUKind);
+}
+
+unsigned llvm::AArch64::getDefaultFPU(StringRef CPU, unsigned ArchKind) {
+  if (CPU == "generic")
+return AArch64ARCHNames[ArchKind].DefaultFPU;
+
+  return StringSwitch(CPU)
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+.Case(NAME, DEFAULT_FPU)
+#include "llvm/Support/AArch64TargetParser.def"
+.Default(ARM::FK_INVALID);
+}
+
+unsigned llvm::AArch64::getDefaultExtensions(StringRef CPU, unsigned ArchKind) {
+  if (CPU == "generic")
+return AArch64ARCHNames[ArchKind].ArchBaseExtensions;
+
+  return StringSwitch(CPU)
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+.Case(NAME, AArch64ARCHNames[ID].ArchBaseExtensions | DEFAULT_EXT)
+#include "llvm/Support/AArch64TargetParser.def"
+.Default(AArch64::AEK_INVALID);
+}
+
+bool llvm::AArch64::getExtensionFeatures(unsigned Extensions,
+ std::vector ) {
+
+  if (Extensions == AArch64::AEK_INVALID)
+return false;
+
+  if (Extensions & AArch64::AEK_FP)
+Features.push_back("+fp-armv8");
+  if (Extensions & AArch64::AEK_SIMD)
+Features.push_back("+neon");
+  if (Extensions & AArch64::AEK_CRC)
+Features.push_back("+crc");
+  if (Extensions & AArch64::AEK_CRYPTO)
+Features.push_back("+crypto");
+  if (Extensions & AArch64::AEK_FP16)
+Features.push_back("+fullfp16");
+  if (Extensions & AArch64::AEK_PROFILE)
+Features.push_back("+spe");
+
+  return true;
+}
+
+bool llvm::AArch64::getFPUFeatures(unsigned FPUKind,
+   std::vector ) {
+  return ARM::getFPUFeatures(FPUKind, Features);
+}
+
+bool llvm::AArch64::getArchFeatures(unsigned ArchKind,
+ std::vector ) {
+  if (ArchKind == ARM::AK_INVALID || ArchKind >= ARM::AK_LAST)
+return false;
+
+  if (ArchKind == ARM::AK_ARMV8_1A)
+Features.push_back("+v8.1a");
+  if (ArchKind == ARM::AK_ARMV8_2A)
+Features.push_back("+v8.2a");
+
+  return true;
+}
+
+StringRef llvm::AArch64::getArchName(unsigned ArchKind) {
+  if (ArchKind >= ARM::AK_LAST)
+return StringRef();
+  return AArch64ARCHNames[ArchKind].getName();
+}
+
+StringRef llvm::AArch64::getCPUAttr(unsigned ArchKind) {
+  if (ArchKind == ARM::AK_INVALID || ArchKind 

Re: [PATCH] D20089: Adding a TargetParser for AArch64

2016-05-24 Thread jojo.ma via cfe-commits
jojo added inline comments.


Comment at: include/llvm/Support/TargetParser.h:173
@@ +172,3 @@
+StringRef getArchName(unsigned ArchKind);
+bool getArchFeatures(unsigned ArchKind, std::vector );
+unsigned getArchAttr(unsigned ArchKind);

rengolin wrote:
> Nitpick, move this declaration with the others that use 
That would be more reasonable.


Comment at: include/llvm/Support/TargetParser.h:184
@@ +183,3 @@
+unsigned  getDefaultExtensions(StringRef CPU, unsigned ArchKind);
+StringRef getDefaultCPU(StringRef Arch, std::vector );
+

rengolin wrote:
> You don't need the  any more. Same of the implementation in the cpp 
> file.
Sorry, I missed it.


Repository:
  rL LLVM

http://reviews.llvm.org/D20089



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20394: Fix cdp intrinsic

2016-05-19 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL270058: [ARM] Fix cdp intrinsic (authored by rsingh).

Changed prior to commit:
  http://reviews.llvm.org/D20394?vs=57698=5#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20394

Files:
  cfe/trunk/include/clang/Basic/BuiltinsARM.def
  cfe/trunk/test/CodeGen/builtins-arm.c
  cfe/trunk/test/Sema/builtins-arm.c

Index: cfe/trunk/include/clang/Basic/BuiltinsARM.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsARM.def
+++ cfe/trunk/include/clang/Basic/BuiltinsARM.def
@@ -52,8 +52,8 @@
 BUILTIN(__builtin_arm_mcr2, "vUIiUIiUiUIiUIiUIi", "")
 BUILTIN(__builtin_arm_mrc, "UiUIiUIiUIiUIiUIi", "")
 BUILTIN(__builtin_arm_mrc2, "UiUIiUIiUIiUIiUIi", "")
-BUILTIN(__builtin_arm_cdp, "vUiUiUiUiUiUi", "")
-BUILTIN(__builtin_arm_cdp2, "vUiUiUiUiUiUi", "")
+BUILTIN(__builtin_arm_cdp, "vUIiUIiUIiUIiUIiUIi", "")
+BUILTIN(__builtin_arm_cdp2, "vUIiUIiUIiUIiUIiUIi", "")
 BUILTIN(__builtin_arm_mcrr, "vUIiUIiUiUiUIi", "")
 BUILTIN(__builtin_arm_mcrr2, "vUIiUIiUiUiUIi", "")
 
Index: cfe/trunk/test/CodeGen/builtins-arm.c
===
--- cfe/trunk/test/CodeGen/builtins-arm.c
+++ cfe/trunk/test/CodeGen/builtins-arm.c
@@ -84,6 +84,20 @@
 // CHECK: call {{.*}} @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 0)
 }
 
+void cdp() {
+  // CHECK: define void @cdp()
+  // CHECK: call void @llvm.arm.cdp(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6)
+  // CHECK-NEXT: ret void
+  __builtin_arm_cdp(1, 2, 3, 4, 5, 6);
+}
+
+void cdp2() {
+  // CHECK: define void @cdp2()
+  // CHECK: call void @llvm.arm.cdp2(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6)
+  // CHECK-NEXT: ret void
+  __builtin_arm_cdp2(1, 2, 3, 4, 5, 6);
+}
+
 unsigned mrc() {
   // CHECK: define i32 @mrc()
   // CHECK: [[R:%.*]] = call i32 @llvm.arm.mrc(i32 15, i32 0, i32 13, i32 0, 
i32 3)
Index: cfe/trunk/test/Sema/builtins-arm.c
===
--- cfe/trunk/test/Sema/builtins-arm.c
+++ cfe/trunk/test/Sema/builtins-arm.c
@@ -48,6 +48,18 @@
 }
 
 void test6(int a, int b, int c) {
+  __builtin_arm_cdp(a, 2, 3, 4, 5, 6); // expected-error {{argument to 
'__builtin_arm_cdp' must be a constant integer}}
+  __builtin_arm_cdp(1, a, 3, 4, 5, 6); // expected-error {{argument to 
'__builtin_arm_cdp' must be a constant integer}}
+  __builtin_arm_cdp(1, 2, a, 4, 5, 6); // expected-error {{argument to 
'__builtin_arm_cdp' must be a constant integer}}
+  __builtin_arm_cdp(1, 2, 3, a, 5, 6); // expected-error {{argument to 
'__builtin_arm_cdp' must be a constant integer}}
+  __builtin_arm_cdp(1, 2, 3, 4, 5, a); // expected-error {{argument to 
'__builtin_arm_cdp' must be a constant integer}}
+
+  __builtin_arm_cdp2(a, 2, 3, 4, 5, 6); // expected-error {{argument to 
'__builtin_arm_cdp2' must be a constant integer}}
+  __builtin_arm_cdp2(1, a, 3, 4, 5, 6); // expected-error {{argument to 
'__builtin_arm_cdp2' must be a constant integer}}
+  __builtin_arm_cdp2(1, 2, a, 4, 5, 6); // expected-error {{argument to 
'__builtin_arm_cdp2' must be a constant integer}}
+  __builtin_arm_cdp2(1, 2, 3, a, 5, 6); // expected-error {{argument to 
'__builtin_arm_cdp2' must be a constant integer}}
+  __builtin_arm_cdp2(1, 2, 3, 4, 5, a); // expected-error {{argument to 
'__builtin_arm_cdp2' must be a constant integer}}
+
   __builtin_arm_mrc( a, 0, 13, 0, 3); // expected-error {{argument to 
'__builtin_arm_mrc' must be a constant integer}}
   __builtin_arm_mrc(15, a, 13, 0, 3); // expected-error {{argument to 
'__builtin_arm_mrc' must be a constant integer}}
   __builtin_arm_mrc(15, 0,  a, 0, 3); // expected-error {{argument to 
'__builtin_arm_mrc' must be a constant integer}}


Index: cfe/trunk/include/clang/Basic/BuiltinsARM.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsARM.def
+++ cfe/trunk/include/clang/Basic/BuiltinsARM.def
@@ -52,8 +52,8 @@
 BUILTIN(__builtin_arm_mcr2, "vUIiUIiUiUIiUIiUIi", "")
 BUILTIN(__builtin_arm_mrc, "UiUIiUIiUIiUIiUIi", "")
 BUILTIN(__builtin_arm_mrc2, "UiUIiUIiUIiUIiUIi", "")
-BUILTIN(__builtin_arm_cdp, "vUiUiUiUiUiUi", "")
-BUILTIN(__builtin_arm_cdp2, "vUiUiUiUiUiUi", "")
+BUILTIN(__builtin_arm_cdp, "vUIiUIiUIiUIiUIiUIi", "")
+BUILTIN(__builtin_arm_cdp2, "vUIiUIiUIiUIiUIiUIi", "")
 BUILTIN(__builtin_arm_mcrr, "vUIiUIiUiUiUIi", "")
 BUILTIN(__builtin_arm_mcrr2, "vUIiUIiUiUiUIi", "")
 
Index: cfe/trunk/test/CodeGen/builtins-arm.c
===
--- cfe/trunk/test/CodeGen/builtins-arm.c
+++ cfe/trunk/test/CodeGen/builtins-arm.c
@@ -84,6 +84,20 @@
 // CHECK: call {{.*}} @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 0)
 }
 
+void cdp() {
+  // CHECK: define void @cdp()
+  // CHECK: call void @llvm.arm.cdp(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6)
+  // CHECK-NEXT: ret void
+  __builtin_arm_cdp(1, 2, 3, 4, 5, 

Re: [PATCH] D20243: [PCH] Disable inclusion of timestamps when generating pch files on windows.

2016-05-18 Thread Cameron via cfe-commits
cameron314 added a subscriber: cameron314.
cameron314 added a comment.

I've seen rare cases where parses using the PCH files were yielding completely 
invalid data, almost as if they were corrupted. I wonder now if this could be 
the cause. (We're on Windows too.)


http://reviews.llvm.org/D20243



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20089: Adding a TargetParser for AArch64

2016-05-19 Thread jojo.ma via cfe-commits
jojo added inline comments.


Comment at: lib/Support/TargetParser.cpp:441
@@ +440,3 @@
+  if (Extensions & AArch64::AEK_PROFILE)
+Features.push_back("+spe");
+

bsmith wrote:
> For ARM there is a table that defines these extensions and how they map to 
> backend features, it would be good to do this in a similar manner.
There is a similar one for aarch64.But only in the context of switch-case,they 
can be map to backend features by table look-up. eg,getArchExtName().
We need to judge the value of "Extensions" by means of bit operations here.It 
is not possible to use the table.


Comment at: lib/Support/TargetParser.cpp:770
@@ +769,3 @@
+  if (A.ID == ARM::AK_ARMV8_2A)
+Features.push_back("+v8.2a");
+  return A.ID;

bsmith wrote:
> Why do we need to add these features explicitly, can't we just pass through 
> the correct triple?
Sometimes people do not give a complete and standardized triple, which leads to 
the obtaining of these features by triple impossible.
It maybe safer to add these features by "-march".


Repository:
  rL LLVM

http://reviews.llvm.org/D20089



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20424: [include-fixer] Make search handle fully qualified names correctly.

2016-05-19 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL270055: [include-fixer] Make search handle fully qualified 
names correctly. (authored by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D20424?vs=57766=57772#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20424

Files:
  clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
  clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp

Index: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
===
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
@@ -103,6 +103,12 @@
   // too.
   EXPECT_EQ("#include \n\nstring foo;\n",
 runIncludeFixer("string foo;\n"));
+
+  // Fully qualified name.
+  EXPECT_EQ("#include \n\n::std::string foo;\n",
+runIncludeFixer("::std::string foo;\n"));
+  // Should not match std::string.
+  EXPECT_EQ("::string foo;\n", runIncludeFixer("::string foo;\n"));
 }
 
 TEST(IncludeFixer, IncompleteType) {
Index: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
===
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
@@ -24,6 +24,12 @@
   llvm::SmallVector Names;
   Identifier.split(Names, "::");
 
+  bool IsFullyQualified = false;
+  if (Identifier.startswith("::")) {
+Names.erase(Names.begin()); // Drop first (empty) element.
+IsFullyQualified = true;
+  }
+
   // As long as we don't find a result keep stripping name parts from the end.
   // This is to support nested classes which aren't recorded in the database.
   // Eventually we will either hit a class (namespaces aren't in the database
@@ -61,6 +67,11 @@
   }
 }
 
+// If the name was qualified we only want to add results if we 
evaluated
+// all contexts.
+if (IsFullyQualified)
+  IsMatched &= (SymbolContext == Symbol.getContexts().end());
+
 // FIXME: Support full match. At this point, we only find symbols in
 // database which end with the same contexts with the identifier.
 if (IsMatched && IdentiferContext == Names.rend()) {


Index: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
===
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
@@ -103,6 +103,12 @@
   // too.
   EXPECT_EQ("#include \n\nstring foo;\n",
 runIncludeFixer("string foo;\n"));
+
+  // Fully qualified name.
+  EXPECT_EQ("#include \n\n::std::string foo;\n",
+runIncludeFixer("::std::string foo;\n"));
+  // Should not match std::string.
+  EXPECT_EQ("::string foo;\n", runIncludeFixer("::string foo;\n"));
 }
 
 TEST(IncludeFixer, IncompleteType) {
Index: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
===
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
@@ -24,6 +24,12 @@
   llvm::SmallVector Names;
   Identifier.split(Names, "::");
 
+  bool IsFullyQualified = false;
+  if (Identifier.startswith("::")) {
+Names.erase(Names.begin()); // Drop first (empty) element.
+IsFullyQualified = true;
+  }
+
   // As long as we don't find a result keep stripping name parts from the end.
   // This is to support nested classes which aren't recorded in the database.
   // Eventually we will either hit a class (namespaces aren't in the database
@@ -61,6 +67,11 @@
   }
 }
 
+// If the name was qualified we only want to add results if we evaluated
+// all contexts.
+if (IsFullyQualified)
+  IsMatched &= (SymbolContext == Symbol.getContexts().end());
+
 // FIXME: Support full match. At this point, we only find symbols in
 // database which end with the same contexts with the identifier.
 if (IsMatched && IdentiferContext == Names.rend()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20514: [Clang][AVX512][BUILTIN]adding missing intrinsics for movdaq instruction set

2016-05-23 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL270401: [Clang][AVX512][BUILTIN]adding missing intrinsics 
for movdaq instruction set (authored by mzuckerm).

Changed prior to commit:
  http://reviews.llvm.org/D20514?vs=58050=58074#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20514

Files:
  cfe/trunk/include/clang/Basic/BuiltinsX86.def
  cfe/trunk/lib/Headers/avx512fintrin.h
  cfe/trunk/lib/Headers/avx512vlintrin.h
  cfe/trunk/test/CodeGen/avx512f-builtins.c
  cfe/trunk/test/CodeGen/avx512vl-builtins.c

Index: cfe/trunk/lib/Headers/avx512fintrin.h
===
--- cfe/trunk/lib/Headers/avx512fintrin.h
+++ cfe/trunk/lib/Headers/avx512fintrin.h
@@ -4926,6 +4926,23 @@
 }
 
 static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_mask_mov_epi32 (__m512i __W, __mmask16 __U, __m512i __A)
+{
+  return (__m512i) __builtin_ia32_movdqa32_512_mask ((__v16si) __A,
+ (__v16si) __W,
+ (__mmask16) __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
+_mm512_maskz_mov_epi32 (__mmask16 __U, __m512i __A)
+{
+  return (__m512i) __builtin_ia32_movdqa32_512_mask ((__v16si) __A,
+ (__v16si)
+ _mm512_setzero_si512 (),
+ (__mmask16) __U);
+}
+
+static __inline__ __m512i __DEFAULT_FN_ATTRS
 _mm512_mask_mov_epi64 (__m512i __W, __mmask8 __U, __m512i __A)
 {
   return (__m512i) __builtin_ia32_movdqa64_512_mask ((__v8di) __A,
Index: cfe/trunk/lib/Headers/avx512vlintrin.h
===
--- cfe/trunk/lib/Headers/avx512vlintrin.h
+++ cfe/trunk/lib/Headers/avx512vlintrin.h
@@ -5834,7 +5834,78 @@
   (__mmask8) __U);
 }
 
+static __inline__ __m128i __DEFAULT_FN_ATTRS
+_mm_mask_mov_epi32 (__m128i __W, __mmask8 __U, __m128i __A)
+{
+  return (__m128i) __builtin_ia32_movdqa32_128_mask ((__v4si) __A,
+ (__v4si) __W,
+ (__mmask8) __U);
+}
+
+static __inline__ __m128i __DEFAULT_FN_ATTRS
+_mm_maskz_mov_epi32 (__mmask8 __U, __m128i __A)
+{
+  return (__m128i) __builtin_ia32_movdqa32_128_mask ((__v4si) __A,
+ (__v4si)
+ _mm_setzero_si128 (),
+ (__mmask8) __U);
+}
+
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS
+_mm256_mask_mov_epi32 (__m256i __W, __mmask8 __U, __m256i __A)
+{
+  return (__m256i) __builtin_ia32_movdqa32_256_mask ((__v8si) __A,
+ (__v8si) __W,
+ (__mmask8) __U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS
+_mm256_maskz_mov_epi32 (__mmask8 __U, __m256i __A)
+{
+  return (__m256i) __builtin_ia32_movdqa32_256_mask ((__v8si) __A,
+ (__v8si)
+ _mm256_setzero_si256 (),
+ (__mmask8) __U);
+}
 
+static __inline__ __m128i __DEFAULT_FN_ATTRS
+_mm_mask_load_epi32 (__m128i __W, __mmask8 __U, void const *__P)
+{
+  return (__m128i) __builtin_ia32_movdqa32load128_mask ((__v4si *) __P,
+  (__v4si) __W,
+  (__mmask8)
+  __U);
+}
+
+static __inline__ __m128i __DEFAULT_FN_ATTRS
+_mm_maskz_load_epi32 (__mmask8 __U, void const *__P)
+{
+  return (__m128i) __builtin_ia32_movdqa32load128_mask ((__v4si *) __P,
+  (__v4si)
+  _mm_setzero_si128 (),
+  (__mmask8)
+  __U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS
+_mm256_mask_load_epi32 (__m256i __W, __mmask8 __U, void const *__P)
+{
+  return (__m256i) __builtin_ia32_movdqa32load256_mask ((__v8si *) __P,
+  (__v8si) __W,
+  (__mmask8)
+  __U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS
+_mm256_maskz_load_epi32 (__mmask8 __U, void const *__P)
+{
+  return (__m256i) __builtin_ia32_movdqa32load256_mask ((__v8si *) __P,
+  (__v8si)
+  _mm256_setzero_si256 (),
+  (__mmask8)
+  __U);
+}
 
 static __inline__ void __DEFAULT_FN_ATTRS
 _mm_mask_store_epi32 (void *__P, __mmask8 __U, __m128i __A)
Index: cfe/trunk/include/clang/Basic/BuiltinsX86.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def
@@ -1723,6 +1723,11 @@
 TARGET_BUILTIN(__builtin_ia32_psrlw256_mask, "V16sV16sV8sV16sUs","","avx512bw,avx512vl")
 TARGET_BUILTIN(__builtin_ia32_psrlwi128_mask, "V8sV8sIiV8sUc","","avx512bw,avx512vl")
 TARGET_BUILTIN(__builtin_ia32_psrlwi256_mask, "V16sV16sIiV16sUs","","avx512bw,avx512vl")
+TARGET_BUILTIN(__builtin_ia32_movdqa32_128_mask, "V4iV4iV4iUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_movdqa32_256_mask, "V8iV8iV8iUc","","avx512vl")
+TARGET_BUILTIN(__builtin_ia32_movdqa32_512_mask, "V16iV16iV16iUs","","avx512f")
+TARGET_BUILTIN(__builtin_ia32_movdqa32load128_mask, "V4iV4i*V4iUc","","avx512f")
+TARGET_BUILTIN(__builtin_ia32_movdqa32load256_mask, "V8iV8i*V8iUc","","avx512f")
 

Re: [PATCH] D20089: Adding a TargetParser for AArch64

2016-05-23 Thread jojo.ma via cfe-commits
jojo added a comment.

> There is an awful lot of duplication/passing through to another class in 
> this, it strikes me that this whole thing could benefit from some level of 
> inheritance. I think it would be good to have a base class that defines the 
> interface and have both ARM/AArch64 (and any other architectures that want to 
> use this in the future) implement this interface. That way all of this code 
> can be called generically from clang/wherever.


Dear Bradley,

Thank you very much for such good advice.
Making the TargetParser into class-base design will need  large changes.I think 
it maybe better to do that in a steady way.
So we can do it step by step.Just make a similar one for aarch64 at first,then 
make both of them into class.
what's your opinion?


Repository:
  rL LLVM

http://reviews.llvm.org/D20089



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20089: Adding a TargetParser for AArch64

2016-05-23 Thread jojo.ma via cfe-commits
jojo removed rL LLVM as the repository for this revision.
jojo changed the visibility of this Differential Revision from "All Users" to 
"Public (No Login Required)".
jojo updated this revision to Diff 58071.
jojo added a comment.

1.unsigned llvm::AArch64::getArchAttr(unsigned ArchKind)

  Correct the error according to the inline comment.

2.unsigned llvm::AArch64::parseArch(StringRef Arch, std::vector 
)

  Adjust arch check logic


http://reviews.llvm.org/D20089

Files:
  include/llvm/Support/AArch64TargetParser.def
  include/llvm/Support/ARMTargetParser.def
  include/llvm/Support/TargetParser.h
  lib/Support/TargetParser.cpp

Index: lib/Support/TargetParser.cpp
===
--- lib/Support/TargetParser.cpp
+++ lib/Support/TargetParser.cpp
@@ -21,6 +21,7 @@
 
 using namespace llvm;
 using namespace ARM;
+using namespace AArch64;
 
 namespace {
 
@@ -75,6 +76,11 @@
   {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH,   \
sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR},
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64ARCHNames[] = {
+#define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT)   \
+  {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH,   \
+   sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR},
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 // List of Arch Extension names.
@@ -91,6 +97,10 @@
 #define ARM_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
   { NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE },
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64ARCHExtNames[] = {
+#define AARCH64_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
+  { NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE },
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 // List of HWDiv names (use getHWDivSynonym) and which architectural
@@ -124,6 +134,10 @@
 #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
   { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT },
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64CPUNames[] = {
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+  { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT },
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 } // namespace
@@ -369,6 +383,134 @@
   return "generic";
 }
 
+StringRef llvm::AArch64::getFPUName(unsigned FPUKind) {
+  return ARM::getFPUName(FPUKind);
+}
+
+unsigned llvm::AArch64::getFPUVersion(unsigned FPUKind) {
+  return ARM::getFPUVersion(FPUKind);
+}
+
+unsigned llvm::AArch64::getFPUNeonSupportLevel(unsigned FPUKind) {
+  return ARM::getFPUNeonSupportLevel( FPUKind);
+}
+
+unsigned llvm::AArch64::getFPURestriction(unsigned FPUKind) {
+  return ARM::getFPURestriction(FPUKind);
+}
+
+unsigned llvm::AArch64::getDefaultFPU(StringRef CPU, unsigned ArchKind) {
+  if (CPU == "generic")
+return AArch64ARCHNames[ArchKind].DefaultFPU;
+
+  return StringSwitch(CPU)
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+.Case(NAME, DEFAULT_FPU)
+#include "llvm/Support/AArch64TargetParser.def"
+.Default(ARM::FK_INVALID);
+}
+
+unsigned llvm::AArch64::getDefaultExtensions(StringRef CPU, unsigned ArchKind) {
+  if (CPU == "generic")
+return AArch64ARCHNames[ArchKind].ArchBaseExtensions;
+
+  return StringSwitch(CPU)
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+.Case(NAME, AArch64ARCHNames[ID].ArchBaseExtensions | DEFAULT_EXT)
+#include "llvm/Support/AArch64TargetParser.def"
+.Default(AArch64::AEK_INVALID);
+}
+
+bool llvm::AArch64::getExtensionFeatures(unsigned Extensions,
+ std::vector ) {
+
+  if (Extensions == AArch64::AEK_INVALID)
+return false;
+
+  if (Extensions & AArch64::AEK_FP)
+Features.push_back("+fp-armv8");
+  if (Extensions & AArch64::AEK_SIMD)
+Features.push_back("+neon");
+  if (Extensions & AArch64::AEK_CRC)
+Features.push_back("+crc");
+  if (Extensions & AArch64::AEK_CRYPTO)
+Features.push_back("+crypto");
+  if (Extensions & AArch64::AEK_FP16)
+Features.push_back("+fullfp16");
+  if (Extensions & AArch64::AEK_PROFILE)
+Features.push_back("+spe");
+
+  return true;
+}
+
+bool llvm::AArch64::getFPUFeatures(unsigned FPUKind,
+   std::vector ) {
+  return ARM::getFPUFeatures(FPUKind, Features);
+}
+
+StringRef llvm::AArch64::getArchName(unsigned ArchKind) {
+  if (ArchKind >= ARM::AK_LAST)
+return StringRef();
+  return AArch64ARCHNames[ArchKind].getName();
+}
+
+StringRef llvm::AArch64::getCPUAttr(unsigned ArchKind) {
+  if (ArchKind == ARM::AK_INVALID || ArchKind >= ARM::AK_LAST)
+return StringRef();
+  return AArch64ARCHNames[ArchKind].getCPUAttr();
+}
+
+StringRef llvm::AArch64::getSubArch(unsigned ArchKind) {
+  if (ArchKind == ARM::AK_INVALID || ArchKind >= ARM::AK_LAST)
+return StringRef();
+  return 

Re: [PATCH] D20088: Using AArch64TargetParser in clang

2016-05-23 Thread jojo.ma via cfe-commits
jojo removed rL LLVM as the repository for this revision.
jojo changed the visibility of this Differential Revision from "All Users" to 
"Public (No Login Required)".
jojo updated this revision to Diff 58072.
jojo added a comment.

Remove checkARMArchValid & checkAArch64ArchValid logic.


http://reviews.llvm.org/D20088

Files:
  lib/Basic/Targets.cpp
  lib/Driver/Tools.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -,22 +,9 @@
   text.split(Split, StringRef("+"), -1, false);
 
   for (StringRef Feature : Split) {
-const char *result = llvm::StringSwitch(Feature)
- .Case("fp", "+fp-armv8")
- .Case("simd", "+neon")
- .Case("crc", "+crc")
- .Case("crypto", "+crypto")
- .Case("fp16", "+fullfp16")
- .Case("profile", "+spe")
- .Case("nofp", "-fp-armv8")
- .Case("nosimd", "-neon")
- .Case("nocrc", "-crc")
- .Case("nocrypto", "-crypto")
- .Case("nofp16", "-fullfp16")
- .Case("noprofile", "-spe")
- .Default(nullptr);
-if (result)
-  Features.push_back(result);
+const char *FeatureName = llvm::AArch64::getArchExtFeature(Feature);
+if (FeatureName)
+  Features.push_back(FeatureName);
 else if (Feature == "neon" || Feature == "noneon")
   D.Diag(diag::err_drv_no_neon_modifier);
 else
@@ -2252,20 +2239,16 @@
   std::vector ) {
   std::pair Split = Mcpu.split("+");
   CPU = Split.first;
-  if (CPU == "cortex-a53" || CPU == "cortex-a57" ||
-  CPU == "cortex-a72" || CPU == "cortex-a35" || CPU == "exynos-m1" ||
-  CPU == "kryo") {
-Features.push_back("+neon");
-Features.push_back("+crc");
-Features.push_back("+crypto");
-  } else if (CPU == "cyclone") {
-Features.push_back("+neon");
-Features.push_back("+crypto");
-  } else if (CPU == "generic") {
+
+  if (CPU == "generic") {
 Features.push_back("+neon");
   } else {
-return false;
-  }
+unsigned ArchKind = llvm::AArch64::parseCPUArch(CPU);
+unsigned Extersion = llvm::AArch64::getDefaultExtensions(CPU,ArchKind);
+
+if (!llvm::AArch64::getExtensionFeatures(Extersion,Features))
+  return false;
+   }
 
   if (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features))
 return false;
@@ -2280,17 +2263,8 @@
   std::string MarchLowerCase = March.lower();
   std::pair Split = StringRef(MarchLowerCase).split("+");
 
-  if (Split.first == "armv8-a" || Split.first == "armv8a") {
-// ok, no additional features.
-  } else if (Split.first == "armv8.1-a" || Split.first == "armv8.1a") {
-Features.push_back("+v8.1a");
-  } else if (Split.first == "armv8.2-a" || Split.first == "armv8.2a" ) {
-Features.push_back("+v8.2a");
-  } else {
-return false;
-  }
-
-  if (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features))
+  if (llvm::AArch64::parseArch(Split.first, Features) == llvm::ARM::AK_INVALID ||
+	  (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features)))
 return false;
 
   return true;
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -5647,14 +5647,10 @@
   }
 
   bool setCPU(const std::string ) override {
-bool CPUKnown = llvm::StringSwitch(Name)
-.Case("generic", true)
-.Cases("cortex-a53", "cortex-a57", "cortex-a72",
-   "cortex-a35", "exynos-m1", true)
-.Case("cyclone", true)
-.Case("kryo", true)
-.Default(false);
-return CPUKnown;
+if (Name == "generic" || llvm::AArch64::parseCPUArch(Name) != llvm::ARM::AK_INVALID)
+  return true;
+
+return false;
   }
 
   void getTargetDefines(const LangOptions ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18360: Add AIX Target/ToolChain to Clang Driver

2016-05-23 Thread WuZhao via cfe-commits
WuZhao added a subscriber: WuZhao.
WuZhao added a comment.

Hi , I find one mistake in the lib/Basic/Targets.cpp. On my AIX 7.1 machine 
/usr/include/sys/inttypes.h, 64 bits wchar_t is unsigned int, not signed int.

  #ifndef _WCHAR_T
  #define _WCHAR_T
  #ifdef __64BIT__
  typedef unsigned intwchar_t;
  #else
  typedef unsigned short  wchar_t;
  #endif
  #endif /* _WCHAR_T */

So, the code should be

  if (this->PointerWidth == 64) {
this->WCharType = this->UnsignedInt;
  } else {
this->WCharType = this->UnsignedShort;
  }


http://reviews.llvm.org/D18360



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20088: Using AArch64TargetParser in clang

2016-05-23 Thread jojo.ma via cfe-commits
jojo added inline comments.


Comment at: lib/Driver/Tools.cpp:707
@@ -696,3 +706,3 @@
   std::string MArch = arm::getARMArch(ArchName, Triple);
-  if (llvm::ARM::parseArch(MArch) == llvm::ARM::AK_INVALID ||
+  if (!checkARMArchValid(MArch) || llvm::ARM::parseArch(MArch) == 
llvm::ARM::AK_INVALID ||
   (Split.second.size() && !DecodeARMFeatures(D, Split.second, Features)))

bsmith wrote:
> Why do we need the call to checkARMArchValid here? Isn't is sufficient that 
> parseArch returns a valid architecture?
Let the TargetParser return correct result.Remove this in the next patchset.


Comment at: lib/Driver/Tools.cpp:2280
@@ -2276,12 +2279,3 @@
 
-  if (Split.first == "armv8-a" || Split.first == "armv8a") {
-// ok, no additional features.
-  } else if (Split.first == "armv8.1-a" || Split.first == "armv8.1a") {
-Features.push_back("+v8.1a");
-  } else if (Split.first == "armv8.2-a" || Split.first == "armv8.2a" ) {
-Features.push_back("+v8.2a");
-  } else {
-return false;
-  }
-
-  if (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features))
+  if (!checkAArch64ArchValid(Split.first) || 
llvm::AArch64::parseArch(Split.first, Features) == llvm::ARM::AK_INVALID ||
+ (Split.second.size() && !DecodeAArch64Features(D, Split.second, 
Features)))

bsmith wrote:
> Same here, why do we need checkAArch64ArchValid?
Same as above.


Repository:
  rL LLVM

http://reviews.llvm.org/D20088



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20089: Adding a TargetParser for AArch64

2016-05-24 Thread jojo.ma via cfe-commits
jojo added inline comments.


Comment at: include/llvm/Support/AArch64TargetParser.def:20
@@ +19,3 @@
+AARCH64_ARCH("armv8-a", AK_ARMV8A, "8-A", "v8", ARMBuildAttrs::CPUArch::v8_A,
+  FK_CRYPTO_NEON_FP_ARMV8, (AArch64::AEK_CRC | AArch64::AEK_CRYPTO | 
AArch64::AEK_FP | AArch64::AEK_SIMD | AArch64::AEK_FP16 | AArch64::AEK_PROFILE))
+AARCH64_ARCH("armv8.1-a", AK_ARMV8_1A, "8.1-A", "v8.1a", 
ARMBuildAttrs::CPUArch::v8_A,

rengolin wrote:
> Please, format this file to 80-columns.
I neglected this.Format it in the update.


Comment at: include/llvm/Support/AArch64TargetParser.def:31
@@ +30,3 @@
+// FIXME: This would be nicer were it tablegen
+AARCH64_ARCH_EXT_NAME("invalid",  AArch64::AEK_INVALID,  nullptr,  nullptr)
+AARCH64_ARCH_EXT_NAME("none", AArch64::AEK_NONE, nullptr,  nullptr)

rengolin wrote:
> Same comment as the ARM def file, wrapping with "namespace AArch64 { }".
Looks like the namespace is not supported in the def file. I tried this in the 
early time.


Comment at: include/llvm/Support/ARMTargetParser.def:48
@@ -47,3 +47,3 @@
 ARM_ARCH("invalid", AK_INVALID, nullptr, nullptr,
-  ARMBuildAttrs::CPUArch::Pre_v4, FK_NONE, AEK_NONE)
+  ARMBuildAttrs::CPUArch::Pre_v4, FK_NONE, ARM::AEK_NONE)
 ARM_ARCH("armv2", AK_ARMV2, "2", "v2", ARMBuildAttrs::CPUArch::Pre_v4,

rengolin wrote:
> This is the "ARM" def file, maybe wrap with "namespace ARM { }"?
Same as "AArch64" def file.


Comment at: include/llvm/Support/TargetParser.h:144
@@ +143,3 @@
+
+namespace AArch64 {
+

rengolin wrote:
> Please, add a FIXME line here, saying this really should be made into a 
> class, to use ARM's methods from inheritance.
Well,yes.Done it in the update.


Comment at: lib/Support/TargetParser.cpp:764
@@ +763,3 @@
+  Arch = getCanonicalArchName(Arch);
+  if (!Arch.startswith("v8"))
+return ARM::AK_INVALID;

rengolin wrote:
> Maybe a better check here would be:
> 
> if (checkArchVersion(Arch) < 8)
> return ARM::AK_INVALID;
Good advice.Put the check in a method alone.


Comment at: lib/Support/TargetParser.cpp:770
@@ +769,3 @@
+if (A.getName().endswith(Syn)) {
+  if (A.ID == ARM::AK_ARMV8_1A)
+Features.push_back("+v8.1a");

rengolin wrote:
> I don't like mixing Features with parseArch. Maybe we could do two different 
> methods and get callers to use both when needed, just like with ARM.
> 
> parseArch needs to be dead simple.
Yes.Moving this to another method "getArchFeatures".


http://reviews.llvm.org/D20089



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20089: Adding a TargetParser for AArch64

2016-05-24 Thread jojo.ma via cfe-commits
jojo set the repository for this revision to rL LLVM.
jojo changed the visibility of this Differential Revision from "Public (No 
Login Required)" to "All Users".
jojo updated this revision to Diff 58205.
jojo added a comment.

1.include/llvm/Support/AArch64TargetParser.def

  Format this file.

2.include/llvm/Support/TargetParser.h

  Add FIXME and the definition of  two methods

3.lib/Support/TargetParser.cpp

  Adjust "llvm::AArch64::parseArch" logic.


Repository:
  rL LLVM

http://reviews.llvm.org/D20089

Files:
  include/llvm/Support/AArch64TargetParser.def
  include/llvm/Support/ARMTargetParser.def
  include/llvm/Support/TargetParser.h
  lib/Support/TargetParser.cpp

Index: lib/Support/TargetParser.cpp
===
--- lib/Support/TargetParser.cpp
+++ lib/Support/TargetParser.cpp
@@ -21,6 +21,7 @@
 
 using namespace llvm;
 using namespace ARM;
+using namespace AArch64;
 
 namespace {
 
@@ -75,6 +76,11 @@
   {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH,   \
sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR},
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64ARCHNames[] = {
+#define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT)   \
+  {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH,   \
+   sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR},
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 // List of Arch Extension names.
@@ -91,6 +97,10 @@
 #define ARM_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
   { NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE },
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64ARCHExtNames[] = {
+#define AARCH64_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
+  { NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE },
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 // List of HWDiv names (use getHWDivSynonym) and which architectural
@@ -124,6 +134,10 @@
 #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
   { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT },
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64CPUNames[] = {
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+  { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT },
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 } // namespace
@@ -369,6 +383,153 @@
   return "generic";
 }
 
+StringRef llvm::AArch64::getFPUName(unsigned FPUKind) {
+  return ARM::getFPUName(FPUKind);
+}
+
+unsigned llvm::AArch64::getFPUVersion(unsigned FPUKind) {
+  return ARM::getFPUVersion(FPUKind);
+}
+
+unsigned llvm::AArch64::getFPUNeonSupportLevel(unsigned FPUKind) {
+  return ARM::getFPUNeonSupportLevel( FPUKind);
+}
+
+unsigned llvm::AArch64::getFPURestriction(unsigned FPUKind) {
+  return ARM::getFPURestriction(FPUKind);
+}
+
+unsigned llvm::AArch64::getDefaultFPU(StringRef CPU, unsigned ArchKind) {
+  if (CPU == "generic")
+return AArch64ARCHNames[ArchKind].DefaultFPU;
+
+  return StringSwitch(CPU)
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+.Case(NAME, DEFAULT_FPU)
+#include "llvm/Support/AArch64TargetParser.def"
+.Default(ARM::FK_INVALID);
+}
+
+unsigned llvm::AArch64::getDefaultExtensions(StringRef CPU, unsigned ArchKind) {
+  if (CPU == "generic")
+return AArch64ARCHNames[ArchKind].ArchBaseExtensions;
+
+  return StringSwitch(CPU)
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+.Case(NAME, AArch64ARCHNames[ID].ArchBaseExtensions | DEFAULT_EXT)
+#include "llvm/Support/AArch64TargetParser.def"
+.Default(AArch64::AEK_INVALID);
+}
+
+bool llvm::AArch64::getExtensionFeatures(unsigned Extensions,
+ std::vector ) {
+
+  if (Extensions == AArch64::AEK_INVALID)
+return false;
+
+  if (Extensions & AArch64::AEK_FP)
+Features.push_back("+fp-armv8");
+  if (Extensions & AArch64::AEK_SIMD)
+Features.push_back("+neon");
+  if (Extensions & AArch64::AEK_CRC)
+Features.push_back("+crc");
+  if (Extensions & AArch64::AEK_CRYPTO)
+Features.push_back("+crypto");
+  if (Extensions & AArch64::AEK_FP16)
+Features.push_back("+fullfp16");
+  if (Extensions & AArch64::AEK_PROFILE)
+Features.push_back("+spe");
+
+  return true;
+}
+
+bool llvm::AArch64::getFPUFeatures(unsigned FPUKind,
+   std::vector ) {
+  return ARM::getFPUFeatures(FPUKind, Features);
+}
+
+StringRef llvm::AArch64::getArchName(unsigned ArchKind) {
+  if (ArchKind >= ARM::AK_LAST)
+return StringRef();
+  return AArch64ARCHNames[ArchKind].getName();
+}
+
+bool llvm::AArch64::getArchFeatures(unsigned ArchKind,
+ std::vector ) {
+  if (ArchKind == ARM::AK_INVALID || ArchKind >= ARM::AK_LAST)
+return false;
+
+  if (ArchKind == ARM::AK_ARMV8_1A)
+Features.push_back("+v8.1a");
+  if (ArchKind == ARM::AK_ARMV8_2A)
+

Re: [PATCH] D20422: [MSVC2015] dllexport for defaulted special class members

2016-05-24 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL270535: [MSVC2015] dllexport for defaulted special class 
members (authored by dpolukhin).

Changed prior to commit:
  http://reviews.llvm.org/D20422?vs=58088=58197#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20422

Files:
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/test/CodeGenCXX/dllexport-members.cpp
  cfe/trunk/test/CodeGenCXX/dllexport.cpp

Index: cfe/trunk/test/CodeGenCXX/dllexport.cpp
===
--- cfe/trunk/test/CodeGenCXX/dllexport.cpp
+++ cfe/trunk/test/CodeGenCXX/dllexport.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-optzns -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2015 %s
-// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-optzns -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2013 %s
+// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-optzns -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2015 -check-prefix=M32MSVC2015 %s
+// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-optzns -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2013 -check-prefix=M32MSVC2013 %s
 
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2015 %s
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2013 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2015 -check-prefix=M64MSVC2015 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2013 -check-prefix=M64MSVC2013 %s
 
 // RUN: %clang_cc1 -triple i686-windows-gnu-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G32 %s
 // RUN: %clang_cc1 -triple x86_64-windows-gnu  -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G64 %s
@@ -561,7 +561,7 @@
 
   // Explicitly defaulted copy constructur:
   T(const T&) = default;
-  // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.T* @"\01??0T@@QAE@ABU0@@Z"
+  // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.T* @"\01??0T@@QAE@ABU0@@Z"
 
   void a() {}
   // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?a@T@@QAEXXZ"
@@ -647,9 +647,34 @@
 
 struct __declspec(dllexport) DefaultedCtorsDtors {
   DefaultedCtorsDtors() = default;
-  // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.DefaultedCtorsDtors* @"\01??0DefaultedCtorsDtors@@QAE@XZ"
+  // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.DefaultedCtorsDtors* @"\01??0DefaultedCtorsDtors@@QAE@XZ"
   ~DefaultedCtorsDtors() = default;
-  // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??1DefaultedCtorsDtors@@QAE@XZ"
+  // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??1DefaultedCtorsDtors@@QAE@XZ"
+};
+
+// Export defaulted member function definitions declared inside class.
+struct __declspec(dllexport) ExportDefaultedInclassDefs {
+  ExportDefaultedInclassDefs() = default;
+  // M32VS2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
+  // M64VS2013-DAG: define weak_odr dllexport%struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
+  // M32VS2015-NOT: define weak_odr dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
+  // M64VS2015-NOT: define weak_odr dllexport

Re: [PATCH] D20088: Using AArch64TargetParser in clang

2016-05-24 Thread jojo.ma via cfe-commits
jojo set the repository for this revision to rL LLVM.
jojo changed the visibility of this Differential Revision from "Public (No 
Login Required)" to "All Users".
jojo updated this revision to Diff 58210.
jojo added a comment.

Adjust "getAArch64ArchFeaturesFromMarch" logic.In file lib/Driver/Tools.cpp.


Repository:
  rL LLVM

http://reviews.llvm.org/D20088

Files:
  lib/Basic/Targets.cpp
  lib/Driver/Tools.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2223,22 +2223,9 @@
   text.split(Split, StringRef("+"), -1, false);
 
   for (StringRef Feature : Split) {
-const char *result = llvm::StringSwitch(Feature)
- .Case("fp", "+fp-armv8")
- .Case("simd", "+neon")
- .Case("crc", "+crc")
- .Case("crypto", "+crypto")
- .Case("fp16", "+fullfp16")
- .Case("profile", "+spe")
- .Case("nofp", "-fp-armv8")
- .Case("nosimd", "-neon")
- .Case("nocrc", "-crc")
- .Case("nocrypto", "-crypto")
- .Case("nofp16", "-fullfp16")
- .Case("noprofile", "-spe")
- .Default(nullptr);
-if (result)
-  Features.push_back(result);
+const char *FeatureName = llvm::AArch64::getArchExtFeature(Feature);
+if (FeatureName)
+  Features.push_back(FeatureName);
 else if (Feature == "neon" || Feature == "noneon")
   D.Diag(diag::err_drv_no_neon_modifier);
 else
@@ -2253,20 +2240,16 @@
   std::vector ) {
   std::pair Split = Mcpu.split("+");
   CPU = Split.first;
-  if (CPU == "cortex-a53" || CPU == "cortex-a57" ||
-  CPU == "cortex-a72" || CPU == "cortex-a35" || CPU == "exynos-m1" ||
-  CPU == "kryo") {
-Features.push_back("+neon");
-Features.push_back("+crc");
-Features.push_back("+crypto");
-  } else if (CPU == "cyclone") {
-Features.push_back("+neon");
-Features.push_back("+crypto");
-  } else if (CPU == "generic") {
+
+  if (CPU == "generic") {
 Features.push_back("+neon");
   } else {
-return false;
-  }
+unsigned ArchKind = llvm::AArch64::parseCPUArch(CPU);
+unsigned Extersion = llvm::AArch64::getDefaultExtensions(CPU,ArchKind);
+
+if (!llvm::AArch64::getExtensionFeatures(Extersion,Features))
+  return false;
+   }
 
   if (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features))
 return false;
@@ -2278,20 +2261,13 @@
 getAArch64ArchFeaturesFromMarch(const Driver , StringRef March,
 const ArgList ,
 std::vector ) {
+  unsigned ArchKind;
   std::string MarchLowerCase = March.lower();
   std::pair Split = StringRef(MarchLowerCase).split("+");
 
-  if (Split.first == "armv8-a" || Split.first == "armv8a") {
-// ok, no additional features.
-  } else if (Split.first == "armv8.1-a" || Split.first == "armv8.1a") {
-Features.push_back("+v8.1a");
-  } else if (Split.first == "armv8.2-a" || Split.first == "armv8.2a" ) {
-Features.push_back("+v8.2a");
-  } else {
-return false;
-  }
-
-  if (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features))
+  ArchKind = llvm::AArch64::parseArch(Split.first);
+  if (ArchKind == llvm::ARM::AK_INVALID || !llvm::AArch64::getArchFeatures(ArchKind, Features) ||
+	  (Split.second.size() && !DecodeAArch64Features(D, Split.second, Features)))
 return false;
 
   return true;
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -5665,14 +5665,10 @@
   }
 
   bool setCPU(const std::string ) override {
-bool CPUKnown = llvm::StringSwitch(Name)
-.Case("generic", true)
-.Cases("cortex-a53", "cortex-a57", "cortex-a72",
-   "cortex-a35", "exynos-m1", true)
-.Case("cyclone", true)
-.Case("kryo", true)
-.Default(false);
-return CPUKnown;
+if (Name == "generic" || llvm::AArch64::parseCPUArch(Name) != llvm::ARM::AK_INVALID)
+  return true;
+
+return false;
   }
 
   void getTargetDefines(const LangOptions ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20089: Adding a TargetParser for AArch64

2016-05-24 Thread jojo.ma via cfe-commits
jojo added a comment.

> While I agree with Bradley that the repetition is not pretty, I think it will 
> expose all issues to make a class design simple and straightforward, once we 
> get all the sharp edges out. But we need to know what are the difficulties on 
> Clang, llc and the back-ends, and make sure that the architectural part of 
> the change is correct, before we that.


A class based design *will* change how every TargetParser method is being 
called now, and will touch a large number of files with mechanical changes, 
including in the ARM side, unrelated to the addition of AArch64.

Yes.It will be a big project really,especially for me.I need to have a 
considerable understanding of the front-end, back-end, and the arm 
architecture, if I'm going to do it.

> After my failed attempt at getting a class design across, I'd rather 
> introduce functionality first, then design better, than the other way round. 
> But I think they should be separated commits based on their intents and 
> merits alone.


Totally agree.And that's exactly what I think.I think we can take class design 
as a low priority task.Maybe we could put it in our backlog list.


Repository:
  rL LLVM

http://reviews.llvm.org/D20089



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20338: [PCH] Fixed overridden files always invalidating preamble even when unchanged

2016-05-24 Thread Cameron via cfe-commits
cameron314 added a comment.

I'm not sure how to test this (originally I found this bug by stepping through 
with a debugger) -- is there a way to determine if an ASTUnit used a PCH for 
the preamble or not? I'd call the `getMainBufferWithPrecompiledPreamble` method 
manually but it's private.


Repository:
  rL LLVM

http://reviews.llvm.org/D20338



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] arc-repeated-use-of-weak should not warn about IBOutlet properties

2016-05-24 Thread Manman via cfe-commits

> On May 23, 2016, at 8:15 PM, Bob Wilson  wrote:
> 
> Revision r211132 was supposed to disable -Warc-repeated-use-of-weak for 
> Objective-C properties marked with the IBOutlet attribute. Those properties 
> are supposed to be weak but they are only accessed from the main thread so 
> there is no risk of asynchronous updates setting them to nil. That 
> combination makes -Warc-repeated-use-of-weak very noisy. The previous change 
> only handled one kind of access to weak IBOutlet properties. Instead of 
> trying to add checks for all the different kinds of property accesses, this 
> patch removes the previous special case check and adds a check at the point 
> where the diagnostic is reported.

The approach looks good to me in general. 
> diff --git lib/Sema/AnalysisBasedWarnings.cpp 
> lib/Sema/AnalysisBasedWarnings.cpp
> index 3f2c41b..eb45315 100644
> --- lib/Sema/AnalysisBasedWarnings.cpp
> +++ lib/Sema/AnalysisBasedWarnings.cpp
> @@ -1334,6 +1334,12 @@ static void diagnoseRepeatedUseOfWeak(Sema ,
>  else
>llvm_unreachable("Unexpected weak object kind!");
>  
> +// Do not warn about IBOutlet weak property receivers being set to null
> +// since they are typically only used from the main thread.
> +if (const ObjCPropertyDecl *Prop = dyn_cast(D))
> +  if (Prop->hasAttr())
> +continue;
> +
>  // Show the first time the object was read.
>  S.Diag(FirstRead->getLocStart(), DiagKind)
><< int(ObjectKind) << D << int(FunctionKind)

Should we guard the call to diagnoseRepeatedUseOfWeak, instead of checking the 
decl inside a loop in diagnoseRepeatedUseOfWeak?

  if (S.getLangOpts().ObjCWeak &&
  !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, D->getLocStart()))
diagnoseRepeatedUseOfWeak(S, fscope, D, AC.getParentMap());
—> check IBOutlet here?

> diff --git lib/Sema/SemaPseudoObject.cpp lib/Sema/SemaPseudoObject.cpp
> index 62c823b..c93d800 100644
> --- lib/Sema/SemaPseudoObject.cpp
> +++ lib/Sema/SemaPseudoObject.cpp
> @@ -578,7 +578,7 @@ bool ObjCPropertyOpBuilder::isWeakProperty() const {
>if (RefExpr->isExplicitProperty()) {
>  const ObjCPropertyDecl *Prop = RefExpr->getExplicitProperty();
>  if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak)
> -  return !Prop->hasAttr();
> +  return true;
>  
>  T = Prop->getType();
>} else if (Getter) {

I wonder if this change is necessary to make the testing case pass, or is it 
introduced for clarity, to better reflect the function name isWeakProperty?

Thanks,
Manman

> rdar://problem/21366461
> 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20094: [include-fixer] Add basic documentation.

2016-05-11 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269167: [include-fixer] Add basic documentation. (authored 
by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D20094?vs=56856=56867#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20094

Files:
  clang-tools-extra/trunk/docs/include-fixer.rst
  clang-tools-extra/trunk/docs/index.rst

Index: clang-tools-extra/trunk/docs/index.rst
===
--- clang-tools-extra/trunk/docs/index.rst
+++ clang-tools-extra/trunk/docs/index.rst
@@ -21,6 +21,7 @@
:maxdepth: 2
 
clang-tidy/index
+   include-fixer
modularize
pp-trace
 
Index: clang-tools-extra/trunk/docs/include-fixer.rst
===
--- clang-tools-extra/trunk/docs/include-fixer.rst
+++ clang-tools-extra/trunk/docs/include-fixer.rst
@@ -0,0 +1,71 @@
+===
+Clang-Include-Fixer
+===
+
+.. contents::
+
+One of the major nuisances of C++ compared to other languages is the manual
+management of ``#include`` directives in any file.
+:program:`clang-include-fixer` addresses one aspect of this problem by 
providing
+an automated way of adding ``#include`` directives for missing symbols in one
+translation unit.
+
+Setup
+=
+
+To use :program:`clang-include-fixer` two databases are required. Both can be
+generated with existing tools.
+
+- Compilation database. Contains the compiler commands for any given file in a
+  project and can be generated by CMake, see `How To Setup Tooling For LLVM`_.
+- Xrefs database. Contains all symbol information in a project to match a given
+  identifier to a header file.
+
+Ideally both databases (``compile_commands.json`` and
+``find_all_symbols_db.yaml``) are linked into the root of the source tree they
+correspond to. Then the :program:`clang-include-fixer` can automatically pick
+them up if called with a source file from that tree. Note that by default
+``compile_commands.json`` as generated by CMake does not include header files,
+so only implementation files can be handled by tools.
+
+.. _How To Setup Tooling For LLVM: 
http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
+
+Creating an Xrefs Database From a Compilation Database
+--
+
+The include fixer contains :program:`find-all-symbols`, a tool to create a
+symbol database in YAML format from a compilation database by parsing all
+source files listed in it. The following list of commands shows how to set up a
+database for LLVM, any project built by CMake should follow similar steps.
+
+.. code-block:: console
+
+  $ cd path/to/llvm-build
+  $ ls compile_commands.json # Make sure compile_commands.json exists.
+compile_commands.json
+  $ 
path/to/llvm/source/tools/clang/tools/extra/include-fixer/find-all-symbols/tool/run-find-all-symbols.py
+... wait as clang indexes the code base ...
+  $ ln -s $PWD/find_all_symbols_db.yaml path/to/llvm/source/ # Link database 
into the source tree.
+  $ ln -s $PWD/compile_commands.json path/to/llvm/source/ # Also link 
compilation database if it's not there already.
+  $ cd path/to/llvm/source
+  $ clang-include-fixer -db=yaml path/to/file/with/missing/include.cpp
+Added #include "foo.h"
+
+How it Works
+
+
+To get the most information out of clang at parse time,
+:program:`clang-include-fixer` runs in tandem with the parse and receives
+callbacks from Clang's semantic analysis. In particular it reuses the existing
+support for typo corrections. Whenever Clang tries to correct a potential typo
+it emits a callback to the include fixer which then looks for a corresponding
+file. At this point rich lookup information is still available, which is not
+available in the AST at a later stage.
+
+The identifier that should be typo corrected is then sent to the database, if a
+header file is returned it is added as an include directive at the top of the
+file.
+
+Currently :program:`clang-include-fixer` only inserts a single include at a
+time to avoid getting caught in follow-up errors. If multiple `#include`
+additions are desired the program can be rerun until a fix-point is reached.


Index: clang-tools-extra/trunk/docs/index.rst
===
--- clang-tools-extra/trunk/docs/index.rst
+++ clang-tools-extra/trunk/docs/index.rst
@@ -21,6 +21,7 @@
:maxdepth: 2
 
clang-tidy/index
+   include-fixer
modularize
pp-trace
 
Index: clang-tools-extra/trunk/docs/include-fixer.rst
===
--- clang-tools-extra/trunk/docs/include-fixer.rst
+++ clang-tools-extra/trunk/docs/include-fixer.rst
@@ -0,0 +1,71 @@
+===
+Clang-Include-Fixer
+===
+
+.. contents::
+
+One of the major nuisances of C++ compared to other languages is the manual
+management of 

[PATCH] D20129: [libclang] Properly expose linkage spec cursors

2016-05-10 Thread Cameron via cfe-commits
cameron314 created this revision.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.

All the groundwork for `CXCursor_LinkageSpec` already existed, but because of a 
missing case in a switch, cursors of that type were never actually created for 
linkage specifications in the AST. This patch fixes that.

I remember seeing another patch that fixed this a long time ago (that I found 
after fixing it myself), but it was never committed (it was just forgotten, if 
I recall correctly).

http://reviews.llvm.org/D20129

Files:
  lib/Sema/SemaCodeComplete.cpp

Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3052,7 +3052,10 @@
 case Decl::UnresolvedUsingValue:
 case Decl::UnresolvedUsingTypename: 
   return CXCursor_UsingDeclaration;
-  
+
+case Decl::LinkageSpec:
+  return CXCursor_LinkageSpec;
+
 case Decl::ObjCPropertyImpl:
   switch (cast(D)->getPropertyImplementation()) {
   case ObjCPropertyImplDecl::Dynamic:


Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3052,7 +3052,10 @@
 case Decl::UnresolvedUsingValue:
 case Decl::UnresolvedUsingTypename: 
   return CXCursor_UsingDeclaration;
-  
+
+case Decl::LinkageSpec:
+  return CXCursor_LinkageSpec;
+
 case Decl::ObjCPropertyImpl:
   switch (cast(D)->getPropertyImplementation()) {
   case ObjCPropertyImplDecl::Dynamic:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20127: [libclang] Expose cursors for alias/weak attributes

2016-05-10 Thread Cameron via cfe-commits
cameron314 created this revision.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.

This patch introduces `CXCursor_AliasAttr`/`CXCursor_WeakAttr` and 
`clang_getAliasTargetSpelling()` for inspecting alias attributes via libclang.

http://reviews.llvm.org/D20127

Files:
  include/clang-c/Index.h
  tools/libclang/CIndex.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -61,6 +61,8 @@
 case attr::Visibility: return CXCursor_VisibilityAttr;
 case attr::DLLExport: return CXCursor_DLLExport;
 case attr::DLLImport: return CXCursor_DLLImport;
+case attr::Weak: return CXCursor_WeakAttr;
+case attr::Alias: return CXCursor_AliasAttr;
   }
 
   return CXCursor_UnexposedAttr;
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -4698,6 +4698,10 @@
 return cxstring::createRef("attribute(dllexport)");
   case CXCursor_DLLImport:
 return cxstring::createRef("attribute(dllimport)");
+  case CXCursor_WeakAttr:
+return cxstring::createRef("attribute(weak)");
+  case CXCursor_AliasAttr:
+return cxstring::createRef("attribute(alias)");
   case CXCursor_PreprocessingDirective:
 return cxstring::createRef("preprocessing directive");
   case CXCursor_MacroDefinition:
@@ -5861,6 +5865,16 @@
   return clang_getNullRange();
 }
 
+CXString clang_getAliasTargetSpelling(CXCursor C) {
+  if (C.kind != CXCursor_AliasAttr)
+return cxstring::createEmpty();
+
+  const AliasAttr *A =
+cast(cxcursor::getCursorAttr(C));
+
+  return cxstring::createDup(A->getAliasee());
+}
+
 void clang_enableStackTraces(void) {
   llvm::sys::PrintStackTraceOnErrorSignal();
 }
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -2338,7 +2338,9 @@
   CXCursor_VisibilityAttr= 417,
   CXCursor_DLLExport = 418,
   CXCursor_DLLImport = 419,
-  CXCursor_LastAttr  = CXCursor_DLLImport,
+  CXCursor_WeakAttr  = 420,
+  CXCursor_AliasAttr = 421,
+  CXCursor_LastAttr  = CXCursor_AliasAttr,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective= 500,
@@ -3589,6 +3591,12 @@
 CINDEX_LINKAGE CXType clang_getIBOutletCollectionType(CXCursor);
 
 /**
+ * \brief For cursors representing an alias attribute,
+ *  this function returns the aliased symbol name as written.
+ */
+CINDEX_LINKAGE CXString clang_getAliasTargetSpelling(CXCursor);
+
+/**
  * @}
  */
 


Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -61,6 +61,8 @@
 case attr::Visibility: return CXCursor_VisibilityAttr;
 case attr::DLLExport: return CXCursor_DLLExport;
 case attr::DLLImport: return CXCursor_DLLImport;
+case attr::Weak: return CXCursor_WeakAttr;
+case attr::Alias: return CXCursor_AliasAttr;
   }
 
   return CXCursor_UnexposedAttr;
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -4698,6 +4698,10 @@
 return cxstring::createRef("attribute(dllexport)");
   case CXCursor_DLLImport:
 return cxstring::createRef("attribute(dllimport)");
+  case CXCursor_WeakAttr:
+return cxstring::createRef("attribute(weak)");
+  case CXCursor_AliasAttr:
+return cxstring::createRef("attribute(alias)");
   case CXCursor_PreprocessingDirective:
 return cxstring::createRef("preprocessing directive");
   case CXCursor_MacroDefinition:
@@ -5861,6 +5865,16 @@
   return clang_getNullRange();
 }
 
+CXString clang_getAliasTargetSpelling(CXCursor C) {
+  if (C.kind != CXCursor_AliasAttr)
+return cxstring::createEmpty();
+
+  const AliasAttr *A =
+cast(cxcursor::getCursorAttr(C));
+
+  return cxstring::createDup(A->getAliasee());
+}
+
 void clang_enableStackTraces(void) {
   llvm::sys::PrintStackTraceOnErrorSignal();
 }
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -2338,7 +2338,9 @@
   CXCursor_VisibilityAttr= 417,
   CXCursor_DLLExport = 418,
   CXCursor_DLLImport = 419,
-  CXCursor_LastAttr  = CXCursor_DLLImport,
+  CXCursor_WeakAttr  = 420,
+  CXCursor_AliasAttr = 421,
+  CXCursor_LastAttr  = CXCursor_AliasAttr,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective= 500,
@@ -3589,6 +3591,12 @@
 CINDEX_LINKAGE 

[PATCH] D20124: [PCH] Serialize skipped preprocessor ranges

2016-05-10 Thread Cameron via cfe-commits
cameron314 created this revision.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.
cameron314 set the repository for this revision to rL LLVM.

This fixes, for example, libclang's `clang_getAllSkippedRanges` returning zero 
ranges after reparsing a translation unit.

Repository:
  rL LLVM

http://reviews.llvm.org/D20124

Files:
  include/clang/Lex/PreprocessingRecord.h
  include/clang/Serialization/ASTBitCodes.h
  include/clang/Serialization/ASTReader.h
  include/clang/Serialization/Module.h
  lib/Lex/PreprocessingRecord.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/Module.cpp

Index: lib/Serialization/Module.cpp
===
--- lib/Serialization/Module.cpp
+++ lib/Serialization/Module.cpp
@@ -31,6 +31,8 @@
 LocalNumMacros(0), MacroOffsets(nullptr),
 BasePreprocessedEntityID(0),
 PreprocessedEntityOffsets(nullptr), NumPreprocessedEntities(0),
+BasePreprocessedSkippedRangeID(0),
+PreprocessedSkippedRangeOffsets(nullptr), NumPreprocessedSkippedRanges(0),
 LocalNumHeaderFileInfos(0), 
 HeaderFileInfoTableData(nullptr), HeaderFileInfoTable(nullptr),
 LocalNumSubmodules(0), BaseSubmoduleID(0),
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -953,6 +953,7 @@
   RECORD(UNUSED_FILESCOPED_DECLS);
   RECORD(PPD_ENTITIES_OFFSETS);
   RECORD(VTABLE_USES);
+  RECORD(PPD_SKIPPED_RANGES);
   RECORD(REFERENCED_SELECTOR_POOL);
   RECORD(TU_UPDATE_LEXICAL);
   RECORD(SEMA_DECL_REFS);
@@ -2408,6 +2409,26 @@
 Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record,
   bytes(PreprocessedEntityOffsets));
   }
+
+  // Write the skipped region table for the preprocessing record.
+  const std::vector  = PPRec.getSkippedRanges();
+  if (SkippedRanges.size() > 0) {
+std::vector SerializedSkippedRanges;
+SerializedSkippedRanges.reserve(SkippedRanges.size());
+for (auto const& Range : SkippedRanges)
+  SerializedSkippedRanges.emplace_back(Range);
+
+using namespace llvm;
+BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
+Abbrev->Add(BitCodeAbbrevOp(PPD_SKIPPED_RANGES));
+Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
+unsigned PPESkippedRangeAbbrev = Stream.EmitAbbrev(Abbrev);
+
+Record.clear();
+Record.push_back(PPD_SKIPPED_RANGES);
+Stream.EmitRecordWithBlob(PPESkippedRangeAbbrev, Record,
+  bytes(SerializedSkippedRanges));
+  }
 }
 
 unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) {
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -3020,6 +3020,24 @@
 
   break;
 }
+
+case PPD_SKIPPED_RANGES: {
+  F.PreprocessedSkippedRangeOffsets = (const PPSkippedRange*)Blob.data();
+  assert(Blob.size() % sizeof(PPSkippedRange) == 0);
+  F.NumPreprocessedSkippedRanges = Blob.size() / sizeof(PPSkippedRange);
+
+  if (!PP.getPreprocessingRecord())
+PP.createPreprocessingRecord();
+  if (!PP.getPreprocessingRecord()->getExternalSource())
+PP.getPreprocessingRecord()->SetExternalSource(*this);
+  F.BasePreprocessedSkippedRangeID = PP.getPreprocessingRecord()
+->allocateSkippedRanges(F.NumPreprocessedSkippedRanges);
+  
+  if (F.NumPreprocessedSkippedRanges > 0)
+GlobalSkippedRangeMap.insert(
+std::make_pair(F.BasePreprocessedSkippedRangeID, ));
+  break;
+}
 
 case DECL_UPDATE_OFFSETS: {
   if (Record.size() % 2 != 0) {
@@ -4874,6 +4892,20 @@
  Mod.FileSortedDecls + Mod.NumFileSortedDecls));
 }
 
+SourceRange ASTReader::ReadSkippedRange(unsigned GlobalIndex) {
+  auto I = GlobalSkippedRangeMap.find(GlobalIndex);
+  assert(I != GlobalSkippedRangeMap.end() &&
+"Corrupted global skipped range map");
+  ModuleFile *M = I->second;
+  unsigned LocalIndex = GlobalIndex - M->BasePreprocessedSkippedRangeID;
+  assert(LocalIndex < M->NumPreprocessedSkippedRanges);
+  PPSkippedRange RawRange = M->PreprocessedSkippedRangeOffsets[LocalIndex];
+  SourceRange Range(TranslateSourceLocation(*M, RawRange.getBegin()),
+TranslateSourceLocation(*M, RawRange.getEnd()));
+  assert(Range.isValid());
+  return Range;
+}
+
 PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
   PreprocessedEntityID PPID = Index+1;
   std::pair PPInfo = getModulePreprocessedEntity(Index);
Index: lib/Lex/PreprocessingRecord.cpp
===
--- lib/Lex/PreprocessingRecord.cpp
+++ lib/Lex/PreprocessingRecord.cpp
@@ -40,7 +40,8 @@
 
 PreprocessingRecord::PreprocessingRecord(SourceManager )
   : SourceMgr(SM),
-

[PATCH] D20125: [libclang] Added clang_getRealSpellingLocation to compensate for clang_getSpellingLocation returning the expansion location

2016-05-10 Thread Cameron via cfe-commits
cameron314 created this revision.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.

All the libclang functions for expanding a location, namely 
`clang_getExpansionLocation`, `clang_getPresumedLocation`, 
`clang_getInstantiationLocation`, and most surprisingly 
`clang_getSpellingLocation` return expansion locations, not spelling locations. 
As it turns out, there is no way to get a spelling location via libclang. This 
patch adds such a function.

Note that there's a FIXME in `clang_getSpellingLocation` about this, but 
changing `clang_getSpellingLocation` to actually return a spelling location 
would almost certainly break a large body of existing (third-party) code, 
mostly in subtle ways. I think it's better to introduce a new function, though 
I know it's ugly. But, this is what we've been using for the past year, and 
we've gotten quite comfortable with it.

http://reviews.llvm.org/D20125

Files:
  include/clang-c/Index.h
  tools/libclang/CXSourceLocation.cpp

Index: tools/libclang/CXSourceLocation.cpp
===
--- tools/libclang/CXSourceLocation.cpp
+++ tools/libclang/CXSourceLocation.cpp
@@ -346,6 +346,42 @@
 *offset = FileOffset;
 }
 
+void clang_getRealSpellingLocation(CXSourceLocation location,
+   CXFile *file,
+   unsigned *line,
+   unsigned *column,
+   unsigned *offset) {
+
+  if (!isASTUnitSourceLocation(location)) {
+CXLoadedDiagnostic::decodeLocation(location, file, line, column, offset);
+return;
+  }
+
+  SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
+
+  if (!location.ptr_data[0] || Loc.isInvalid())
+return createNullLocation(file, line, column, offset);
+
+  const SourceManager  =
+  *static_cast(location.ptr_data[0]);
+  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
+  std::pair LocInfo = SM.getDecomposedLoc(SpellLoc);
+  FileID FID = LocInfo.first;
+  unsigned FileOffset = LocInfo.second;
+
+  if (FID.isInvalid())
+return createNullLocation(file, line, column, offset);
+
+  if (file)
+*file = const_cast(SM.getFileEntryForID(FID));
+  if (line)
+*line = SM.getLineNumber(FID, FileOffset);
+  if (column)
+*column = SM.getColumnNumber(FID, FileOffset);
+  if (offset)
+*offset = FileOffset;
+}
+
 void clang_getFileLocation(CXSourceLocation location,
CXFile *file,
unsigned *line,
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -568,6 +568,36 @@
  * \brief Retrieve the file, line, column, and offset represented by
  * the given source location.
  *
+ * If the location refers into a macro instantiation, return where the
+ * location was originally spelled in the source file (i.e. where the token
+ * text is located). clang_getSpellingLocation() is supposed to do this
+ * but doesn't, hence this function.
+ *
+ * \param location the location within a source file that will be decomposed
+ * into its parts.
+ *
+ * \param file [out] if non-NULL, will be set to the file to which the given
+ * source location points.
+ *
+ * \param line [out] if non-NULL, will be set to the line to which the given
+ * source location points.
+ *
+ * \param column [out] if non-NULL, will be set to the column to which the 
given
+ * source location points.
+ *
+ * \param offset [out] if non-NULL, will be set to the offset into the
+ * buffer to which the given source location points.
+ */
+CINDEX_LINKAGE void clang_getRealSpellingLocation(CXSourceLocation location,
+  CXFile *file,
+  unsigned *line,
+  unsigned *column,
+  unsigned *offset);
+
+/**
+ * \brief Retrieve the file, line, column, and offset represented by
+ * the given source location.
+ *
  * If the location refers into a macro expansion, return where the macro was
  * expanded or where the macro argument was written, if the location points at
  * a macro argument.


Index: tools/libclang/CXSourceLocation.cpp
===
--- tools/libclang/CXSourceLocation.cpp
+++ tools/libclang/CXSourceLocation.cpp
@@ -346,6 +346,42 @@
 *offset = FileOffset;
 }
 
+void clang_getRealSpellingLocation(CXSourceLocation location,
+   CXFile *file,
+   unsigned *line,
+   unsigned *column,
+   unsigned *offset) {
+
+  if (!isASTUnitSourceLocation(location)) {
+CXLoadedDiagnostic::decodeLocation(location, file, line, column, 

Re: [PATCH] D20125: [libclang] Added clang_getRealSpellingLocation to compensate for clang_getSpellingLocation returning the expansion location

2016-05-11 Thread Cameron via cfe-commits
cameron314 added a comment.

Ah, I was wondering where the tests were. I found this in the CMake file:

  # FIXME: libclang unit tests are disabled on Windows due
  # to failures, mostly in libclang.VirtualFileOverlay_*.
  if(NOT WIN32 AND CLANG_TOOL_LIBCLANG_BUILD) 
add_subdirectory(libclang)
  endif()

I'll ignore the VFO failures for now, and add a new test for 
clang_getRealSpellingLocation :-)


http://reviews.llvm.org/D20125



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20125: [libclang] Added clang_getRealSpellingLocation to compensate for clang_getSpellingLocation returning the expansion location

2016-05-11 Thread Cameron via cfe-commits
cameron314 updated this revision to Diff 56916.
cameron314 added a comment.

I've added a unit test.


http://reviews.llvm.org/D20125

Files:
  include/clang-c/Index.h
  tools/libclang/CXSourceLocation.cpp
  unittests/libclang/LibclangTest.cpp

Index: unittests/libclang/LibclangTest.cpp
===
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -15,6 +15,9 @@
 #include "gtest/gtest.h"
 #include 
 #include 
+#include 
+#include 
+#include 
 #define DEBUG_TYPE "libclang-test"
 
 TEST(libclang, clang_parseTranslationUnit2_InvalidArgs) {
@@ -349,21 +352,25 @@
   clang_ModuleMapDescriptor_dispose(MMD);
 }
 
-class LibclangReparseTest : public ::testing::Test {
+class LibclangParseTest : public ::testing::Test {
   std::set Files;
+  typedef std::unique_ptr fixed_addr_string;
+  std::map UnsavedFileContents;
 public:
   std::string TestDir;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
+  std::vector UnsavedFiles;
 
   void SetUp() override {
 llvm::SmallString<256> Dir;
 ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir));
 TestDir = Dir.str();
 TUFlags = CXTranslationUnit_DetailedPreprocessingRecord |
-  clang_defaultEditingTranslationUnitOptions();
+  clang_defaultEditingTranslationUnitOptions();
 Index = clang_createIndex(0, 0);
+ClangTU = nullptr;
   }
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
@@ -384,6 +391,64 @@
 OS << Contents;
 assert(OS.good());
   }
+  void MapUnsavedFile(const char* name, const std::string ) {
+auto it = UnsavedFileContents.emplace(
+fixed_addr_string(new std::string(name)),
+fixed_addr_string(new std::string(contents)));
+UnsavedFiles.push_back({
+it.first->first->c_str(),   // filename
+it.first->second->c_str(),  // contents
+it.first->second->size()// length
+});
+  }
+  template
+  void Traverse(const F ) {
+CXCursor TuCursor = clang_getTranslationUnitCursor(ClangTU);
+std::reference_wrapper FunctorRef = std::cref(TraversalFunctor);
+clang_visitChildren(TuCursor,
+,
+);
+  }
+
+private:
+  template
+  static CXChildVisitResult TraverseStateless(CXCursor cx, CXCursor parent,
+  CXClientData data) {
+TState *State = static_cast(data);
+return State->get()(cx, parent);
+  }
+};
+
+TEST_F(LibclangParseTest, SpellingLocation) {
+  MapUnsavedFile("main.cpp",
+"#define BANANAS 4011\n"
+"int plu = BANANAS;");
+
+  ClangTU = clang_parseTranslationUnit(Index, "main.cpp", nullptr, 0,
+UnsavedFiles.data(), UnsavedFiles.size(), TUFlags);
+
+  bool sawInt;
+  Traverse([&](CXCursor cx, CXCursor) {
+if (cx.kind == CXCursor_IntegerLiteral) {
+  sawInt = true;
+  auto cxl = clang_getCursorLocation(cx);
+  CXFile expansionFile, spellingFile;
+  unsigned line, column, offset;
+  clang_getSpellingLocation(cxl, , , nullptr, nullptr);
+  EXPECT_EQ(2, line);  // getSpellingLocation returns expansion location
+  clang_getRealSpellingLocation(cxl, , , , );
+  EXPECT_TRUE(clang_File_isEqual(expansionFile, spellingFile));
+  EXPECT_EQ(1, line);
+  EXPECT_EQ(17, column);
+  EXPECT_EQ(16, offset);
+}
+return CXChildVisit_Recurse;
+  });
+  EXPECT_TRUE(sawInt);
+}
+
+class LibclangReparseTest : public LibclangParseTest {
+public:
   void DisplayDiagnostics() {
 unsigned NumDiagnostics = clang_getNumDiagnostics(ClangTU);
 for (unsigned i = 0; i < NumDiagnostics; ++i) {
Index: tools/libclang/CXSourceLocation.cpp
===
--- tools/libclang/CXSourceLocation.cpp
+++ tools/libclang/CXSourceLocation.cpp
@@ -346,6 +346,42 @@
 *offset = FileOffset;
 }
 
+void clang_getRealSpellingLocation(CXSourceLocation location,
+   CXFile *file,
+   unsigned *line,
+   unsigned *column,
+   unsigned *offset) {
+
+  if (!isASTUnitSourceLocation(location)) {
+CXLoadedDiagnostic::decodeLocation(location, file, line, column, offset);
+return;
+  }
+
+  SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
+
+  if (!location.ptr_data[0] || Loc.isInvalid())
+return createNullLocation(file, line, column, offset);
+
+  const SourceManager  =
+  *static_cast(location.ptr_data[0]);
+  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
+  std::pair LocInfo = SM.getDecomposedLoc(SpellLoc);
+  FileID FID = LocInfo.first;
+  unsigned FileOffset = LocInfo.second;
+
+  if (FID.isInvalid())
+return createNullLocation(file, line, column, offset);
+
+  if (file)
+*file = const_cast(SM.getFileEntryForID(FID));
+  if (line)
+*line = 

Re: [PATCH] D20125: [libclang] Added clang_getRealSpellingLocation to compensate for clang_getSpellingLocation returning the expansion location

2016-05-11 Thread Cameron via cfe-commits
cameron314 updated this revision to Diff 56917.

http://reviews.llvm.org/D20125

Files:
  include/clang-c/Index.h
  tools/libclang/CXSourceLocation.cpp
  unittests/libclang/LibclangTest.cpp

Index: unittests/libclang/LibclangTest.cpp
===
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -15,6 +15,9 @@
 #include "gtest/gtest.h"
 #include 
 #include 
+#include 
+#include 
+#include 
 #define DEBUG_TYPE "libclang-test"
 
 TEST(libclang, clang_parseTranslationUnit2_InvalidArgs) {
@@ -349,21 +352,25 @@
   clang_ModuleMapDescriptor_dispose(MMD);
 }
 
-class LibclangReparseTest : public ::testing::Test {
+class LibclangParseTest : public ::testing::Test {
   std::set Files;
+  typedef std::unique_ptr fixed_addr_string;
+  std::map UnsavedFileContents;
 public:
   std::string TestDir;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
+  std::vector UnsavedFiles;
 
   void SetUp() override {
 llvm::SmallString<256> Dir;
 ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir));
 TestDir = Dir.str();
 TUFlags = CXTranslationUnit_DetailedPreprocessingRecord |
-  clang_defaultEditingTranslationUnitOptions();
+  clang_defaultEditingTranslationUnitOptions();
 Index = clang_createIndex(0, 0);
+ClangTU = nullptr;
   }
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
@@ -384,6 +391,64 @@
 OS << Contents;
 assert(OS.good());
   }
+  void MapUnsavedFile(const char* name, const std::string ) {
+auto it = UnsavedFileContents.emplace(
+fixed_addr_string(new std::string(name)),
+fixed_addr_string(new std::string(contents)));
+UnsavedFiles.push_back({
+it.first->first->c_str(),   // filename
+it.first->second->c_str(),  // contents
+it.first->second->size()// length
+});
+  }
+  template
+  void Traverse(const F ) {
+CXCursor TuCursor = clang_getTranslationUnitCursor(ClangTU);
+std::reference_wrapper FunctorRef = std::cref(TraversalFunctor);
+clang_visitChildren(TuCursor,
+,
+);
+  }
+
+private:
+  template
+  static CXChildVisitResult TraverseStateless(CXCursor cx, CXCursor parent,
+  CXClientData data) {
+TState *State = static_cast(data);
+return State->get()(cx, parent);
+  }
+};
+
+TEST_F(LibclangParseTest, SpellingLocation) {
+  MapUnsavedFile("main.cpp",
+"#define BANANAS 4011\n"
+"int plu = BANANAS;");
+
+  ClangTU = clang_parseTranslationUnit(Index, "main.cpp", nullptr, 0,
+UnsavedFiles.data(), UnsavedFiles.size(), TUFlags);
+
+  bool sawInt = false;
+  Traverse([&](CXCursor cx, CXCursor) {
+if (cx.kind == CXCursor_IntegerLiteral) {
+  sawInt = true;
+  auto cxl = clang_getCursorLocation(cx);
+  CXFile expansionFile, spellingFile;
+  unsigned line, column, offset;
+  clang_getSpellingLocation(cxl, , , nullptr, nullptr);
+  EXPECT_EQ(2, line);  // getSpellingLocation returns expansion location
+  clang_getRealSpellingLocation(cxl, , , , );
+  EXPECT_TRUE(clang_File_isEqual(expansionFile, spellingFile));
+  EXPECT_EQ(1, line);
+  EXPECT_EQ(17, column);
+  EXPECT_EQ(16, offset);
+}
+return CXChildVisit_Recurse;
+  });
+  EXPECT_TRUE(sawInt);
+}
+
+class LibclangReparseTest : public LibclangParseTest {
+public:
   void DisplayDiagnostics() {
 unsigned NumDiagnostics = clang_getNumDiagnostics(ClangTU);
 for (unsigned i = 0; i < NumDiagnostics; ++i) {
Index: tools/libclang/CXSourceLocation.cpp
===
--- tools/libclang/CXSourceLocation.cpp
+++ tools/libclang/CXSourceLocation.cpp
@@ -346,6 +346,42 @@
 *offset = FileOffset;
 }
 
+void clang_getRealSpellingLocation(CXSourceLocation location,
+   CXFile *file,
+   unsigned *line,
+   unsigned *column,
+   unsigned *offset) {
+
+  if (!isASTUnitSourceLocation(location)) {
+CXLoadedDiagnostic::decodeLocation(location, file, line, column, offset);
+return;
+  }
+
+  SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
+
+  if (!location.ptr_data[0] || Loc.isInvalid())
+return createNullLocation(file, line, column, offset);
+
+  const SourceManager  =
+  *static_cast(location.ptr_data[0]);
+  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
+  std::pair LocInfo = SM.getDecomposedLoc(SpellLoc);
+  FileID FID = LocInfo.first;
+  unsigned FileOffset = LocInfo.second;
+
+  if (FID.isInvalid())
+return createNullLocation(file, line, column, offset);
+
+  if (file)
+*file = const_cast(SM.getFileEntryForID(FID));
+  if (line)
+*line = SM.getLineNumber(FID, FileOffset);
+  if (column)
+*column 

[PATCH] D20131: Fixed crash during code completion in file included within declaration

2016-05-10 Thread Cameron via cfe-commits
cameron314 created this revision.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.

When triggering code completion within a file that is included in the middle of 
a declaration in another file, clang would crash while parsing the code.

This occurred with real-world code; there was an enum declaration that included 
a header in the middle of its declaration to specify the enum members.

http://reviews.llvm.org/D20131

Files:
  lib/Lex/PPLexerChange.cpp

Index: lib/Lex/PPLexerChange.cpp
===
--- lib/Lex/PPLexerChange.cpp
+++ lib/Lex/PPLexerChange.cpp
@@ -378,6 +378,8 @@
 Result.startToken();
 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
 CurLexer.reset();
+if (CurLexerKind == CLK_Lexer)
+  CurLexerKind = CLK_CachingLexer;
   } else {
 assert(CurPTHLexer && "Got EOF but no current lexer set!");
 CurPTHLexer->getEOF(Result);


Index: lib/Lex/PPLexerChange.cpp
===
--- lib/Lex/PPLexerChange.cpp
+++ lib/Lex/PPLexerChange.cpp
@@ -378,6 +378,8 @@
 Result.startToken();
 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
 CurLexer.reset();
+if (CurLexerKind == CLK_Lexer)
+  CurLexerKind = CLK_CachingLexer;
   } else {
 assert(CurPTHLexer && "Got EOF but no current lexer set!");
 CurPTHLexer->getEOF(Result);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20134: [libclang] Fixed bug where ranges in spelling locations (in macro expansions) would get mangled

2016-05-10 Thread Cameron via cfe-commits
cameron314 created this revision.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.

The end location of the range would be changed into its expansion location, but 
the beginning of the range would stay as a spelling location. This would lead 
to very weird ranges spanning large parts of a file (starting in a macro until 
its expansion).

This bug was not previously caught because there was no way to actually obtain 
a spelling location via libclang (see my patch at D20125 which adds support for 
this), so later obtaining the start location of a range would result in an 
expansion location anyway, and wind up matching the expansion location that was 
stored in the end of the range.

http://reviews.llvm.org/D20134

Files:
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -142,8 +142,6 @@
   // We want the last character in this location, so we will adjust the
   // location accordingly.
   SourceLocation EndLoc = R.getEnd();
-  if (EndLoc.isValid() && EndLoc.isMacroID() && 
!SM.isMacroArgExpansion(EndLoc))
-EndLoc = SM.getExpansionRange(EndLoc).second;
   if (R.isTokenRange() && EndLoc.isValid()) {
 unsigned Length = Lexer::MeasureTokenLength(SM.getSpellingLoc(EndLoc),
 SM, LangOpts);


Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -142,8 +142,6 @@
   // We want the last character in this location, so we will adjust the
   // location accordingly.
   SourceLocation EndLoc = R.getEnd();
-  if (EndLoc.isValid() && EndLoc.isMacroID() && !SM.isMacroArgExpansion(EndLoc))
-EndLoc = SM.getExpansionRange(EndLoc).second;
   if (R.isTokenRange() && EndLoc.isValid()) {
 unsigned Length = Lexer::MeasureTokenLength(SM.getSpellingLoc(EndLoc),
 SM, LangOpts);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20137: [PCH] Fixed bugs with preamble invalidation when files change (on Windows)

2016-05-10 Thread Cameron via cfe-commits
cameron314 created this revision.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.

There were two bugs relating to remapped files, that are not specific to 
Windows but happen more often there:
- When remapped files were changed, they would never cause the preamble's PCH 
to be invalidated, because the remapped path didn't necessarily match the 
include path (e.g. slash direction). I fixed this by moving to a 
`llvm::sys::fs::UniqueID`-based map instead of using strings for paths and 
hoping they match.
- Fixing the above bug revealed a new bug where remapped files would always 
cause the preamble's PCH to be invalidated (even if they hadn't changed) 
because the file manager was replacing the remapped virtual entry (no modified 
time) with a real file entry (which has a modified time) when the include 
directive was processed, again because it had a slightly different path due to 
slash direction.

http://reviews.llvm.org/D20137

Files:
  include/clang/Basic/FileManager.h
  include/clang/Frontend/ASTUnit.h
  lib/Basic/FileManager.cpp
  lib/Frontend/ASTUnit.cpp

Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1378,7 +1378,7 @@
   
   // First, make a record of those files that have been overridden via
   // remapping or unsaved_files.
-  llvm::StringMap OverriddenFiles;
+  std::map OverriddenFiles;
   for (const auto  : PreprocessorOpts.RemappedFiles) {
 if (AnyFileChanged)
   break;
@@ -1391,40 +1391,47 @@
   break;
 }
 
-OverriddenFiles[R.first] = PreambleFileHash::createForFile(
+OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile(
 Status.getSize(), Status.getLastModificationTime().toEpochTime());
   }
 
   for (const auto  : PreprocessorOpts.RemappedFileBuffers) {
 if (AnyFileChanged)
   break;
-OverriddenFiles[RB.first] =
+
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(RB.first, Status)) {
+  AnyFileChanged = true;
+  break;
+}
+
+OverriddenFiles[Status.getUniqueID()] =
 PreambleFileHash::createForMemoryBuffer(RB.second);
   }

   // Check whether anything has changed.
-  for (llvm::StringMap::iterator 
+  for (FilesInPreambleMap::iterator
  F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end();
!AnyFileChanged && F != FEnd; 
++F) {
-llvm::StringMap::iterator Overridden
-  = OverriddenFiles.find(F->first());
+std::map::iterator Overridden
+  = OverriddenFiles.find(F->first);
 if (Overridden != OverriddenFiles.end()) {
   // This file was remapped; check whether the newly-mapped file 
   // matches up with the previous mapping.
-  if (Overridden->second != F->second)
+  if (Overridden->second != F->second.second)
 AnyFileChanged = true;
   continue;
 }
 
 // The file was not remapped; check whether it has changed on disk.
 vfs::Status Status;
-if (FileMgr->getNoncachedStatValue(F->first(), Status)) {
+if (FileMgr->getNoncachedStatValue(F->second.first, Status)) {
   // If we can't stat the file, assume that something horrible happened.
   AnyFileChanged = true;
-} else if (Status.getSize() != uint64_t(F->second.Size) ||
+} else if (Status.getSize() != uint64_t(F->second.second.Size) ||
Status.getLastModificationTime().toEpochTime() !=
-   uint64_t(F->second.ModTime))
+   uint64_t(F->second.second.ModTime))
   AnyFileChanged = true;
   }
   
@@ -1612,12 +1619,14 @@
 if (!File || File == SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()))
   continue;
 if (time_t ModTime = File->getModificationTime()) {
-  FilesInPreamble[File->getName()] = PreambleFileHash::createForFile(
-  File->getSize(), ModTime);
+  FilesInPreamble[File->getUniqueID()] = std::make_pair(
+StringRef(File->getName()),
+PreambleFileHash::createForFile(File->getSize(), ModTime));
 } else {
   llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File);
-  FilesInPreamble[File->getName()] =
-  PreambleFileHash::createForMemoryBuffer(Buffer);
+  FilesInPreamble[File->getUniqueID()] = std::make_pair(
+StringRef(File->getName()),
+PreambleFileHash::createForMemoryBuffer(Buffer));
 }
   }
 
Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -301,6 +301,11 @@
 return 
   }
 
+  if 

[PATCH] D20132: [libclang] Add clang_getAllSkippedRanges function

2016-05-10 Thread Cameron via cfe-commits
cameron314 created this revision.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.

This complements the `clang_getSkippedRanges` function which returns skipped 
ranges filtered by a specific file.

This function is useful when all the ranges are desired (and a lot more 
efficient than the equivalent of asking for the ranges file by file, since the 
implementation of `clang_getSkippedRanges` iterates over all ranges anyway). We 
use this internally to populate a database that later gets queried by our IDE.

http://reviews.llvm.org/D20132

Files:
  include/clang-c/Index.h
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -7680,6 +7680,33 @@
   return skipped;
 }
 
+CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) {
+  CXSourceRangeList *skipped = new CXSourceRangeList;
+  skipped->count = 0;
+  skipped->ranges = nullptr;
+
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return skipped;
+  }
+
+  ASTUnit *astUnit = cxtu::getASTUnit(TU);
+  PreprocessingRecord *ppRec = 
astUnit->getPreprocessor().getPreprocessingRecord();
+  if (!ppRec)
+return skipped;
+
+  ASTContext  = astUnit->getASTContext();
+
+  const std::vector  = ppRec->getSkippedRanges();
+
+  skipped->count = SkippedRanges.size();
+  skipped->ranges = new CXSourceRange[skipped->count];
+  for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
+skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]);
+
+  return skipped;
+}
+
 void clang_disposeSourceRangeList(CXSourceRangeList *ranges) {
   if (ranges) {
 delete[] ranges->ranges;
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -627,6 +627,15 @@
  CXFile file);
 
 /**
+ * \brief Retrieve all ranges from all files that were skipped by the
+ * preprocessor.
+ *
+ * The preprocessor will skip lines when they are surrounded by an
+ * if/ifdef/ifndef directive whose condition does not evaluate to true.
+ */
+CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit 
tu);
+
+/**
  * \brief Destroy the given \c CXSourceRangeList.
  */
 CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);


Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -7680,6 +7680,33 @@
   return skipped;
 }
 
+CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) {
+  CXSourceRangeList *skipped = new CXSourceRangeList;
+  skipped->count = 0;
+  skipped->ranges = nullptr;
+
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return skipped;
+  }
+
+  ASTUnit *astUnit = cxtu::getASTUnit(TU);
+  PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord();
+  if (!ppRec)
+return skipped;
+
+  ASTContext  = astUnit->getASTContext();
+
+  const std::vector  = ppRec->getSkippedRanges();
+
+  skipped->count = SkippedRanges.size();
+  skipped->ranges = new CXSourceRange[skipped->count];
+  for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
+skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]);
+
+  return skipped;
+}
+
 void clang_disposeSourceRangeList(CXSourceRangeList *ranges) {
   if (ranges) {
 delete[] ranges->ranges;
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -627,6 +627,15 @@
  CXFile file);
 
 /**
+ * \brief Retrieve all ranges from all files that were skipped by the
+ * preprocessor.
+ *
+ * The preprocessor will skip lines when they are surrounded by an
+ * if/ifdef/ifndef directive whose condition does not evaluate to true.
+ */
+CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit tu);
+
+/**
  * \brief Destroy the given \c CXSourceRangeList.
  */
 CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20132: [libclang] Add clang_getAllSkippedRanges function

2016-05-11 Thread Cameron via cfe-commits
cameron314 updated this revision to Diff 56964.
cameron314 added a comment.

Here's a test!


http://reviews.llvm.org/D20132

Files:
  include/clang-c/Index.h
  tools/libclang/CIndex.cpp
  unittests/libclang/LibclangTest.cpp

Index: unittests/libclang/LibclangTest.cpp
===
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -15,6 +15,9 @@
 #include "gtest/gtest.h"
 #include 
 #include 
+#include 
+#include 
+#include 
 #define DEBUG_TYPE "libclang-test"
 
 TEST(libclang, clang_parseTranslationUnit2_InvalidArgs) {
@@ -349,21 +352,25 @@
   clang_ModuleMapDescriptor_dispose(MMD);
 }
 
-class LibclangReparseTest : public ::testing::Test {
+class LibclangParseTest : public ::testing::Test {
   std::set Files;
+  typedef std::unique_ptr fixed_addr_string;
+  std::map UnsavedFileContents;
 public:
   std::string TestDir;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
+  std::vector UnsavedFiles;
 
   void SetUp() override {
 llvm::SmallString<256> Dir;
 ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir));
 TestDir = Dir.str();
 TUFlags = CXTranslationUnit_DetailedPreprocessingRecord |
-  clang_defaultEditingTranslationUnitOptions();
+  clang_defaultEditingTranslationUnitOptions();
 Index = clang_createIndex(0, 0);
+ClangTU = nullptr;
   }
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
@@ -384,6 +391,77 @@
 OS << Contents;
 assert(OS.good());
   }
+  void MapUnsavedFile(std::string Filename, const std::string ) {
+if (!llvm::sys::path::is_absolute(Filename)) {
+  llvm::SmallString<256> Path(TestDir);
+  llvm::sys::path::append(Path, Filename);
+  Filename = Path.str();
+}
+auto it = UnsavedFileContents.emplace(
+fixed_addr_string(new std::string(Filename)),
+fixed_addr_string(new std::string(Contents)));
+UnsavedFiles.push_back({
+it.first->first->c_str(),   // filename
+it.first->second->c_str(),  // contents
+it.first->second->size()// length
+});
+  }
+  template
+  void Traverse(const F ) {
+CXCursor TuCursor = clang_getTranslationUnitCursor(ClangTU);
+std::reference_wrapper FunctorRef = std::cref(TraversalFunctor);
+clang_visitChildren(TuCursor,
+,
+);
+  }
+private:
+  template
+  static CXChildVisitResult TraverseStateless(CXCursor cx, CXCursor parent,
+  CXClientData data) {
+TState *State = static_cast(data);
+return State->get()(cx, parent);
+  }
+};
+
+TEST_F(LibclangParseTest, AllSkippedRanges) {
+  std::string Header = "header.h", Main = "main.cpp";
+  WriteFile(Header,
+"#ifdef MANGOS\n"
+"printf(\"mmm\");\n"
+"#endif");
+  WriteFile(Main,
+"#include \"header.h\"\n"
+"#ifdef KIWIS\n"
+"printf(\"mmm!!\");\n"
+"#endif");
+
+  ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0,
+   nullptr, 0, TUFlags);
+
+  CXSourceRangeList *Ranges = clang_getAllSkippedRanges(ClangTU);
+  EXPECT_EQ(2, Ranges->count);
+  
+  CXSourceLocation cxl;
+  unsigned line;
+  cxl = clang_getRangeStart(Ranges->ranges[0]);
+  clang_getSpellingLocation(cxl, nullptr, , nullptr, nullptr);
+  EXPECT_EQ(1, line);
+  cxl = clang_getRangeEnd(Ranges->ranges[0]);
+  clang_getSpellingLocation(cxl, nullptr, , nullptr, nullptr);
+  EXPECT_EQ(3, line);
+
+  cxl = clang_getRangeStart(Ranges->ranges[1]);
+  clang_getSpellingLocation(cxl, nullptr, , nullptr, nullptr);
+  EXPECT_EQ(2, line);
+  cxl = clang_getRangeEnd(Ranges->ranges[1]);
+  clang_getSpellingLocation(cxl, nullptr, , nullptr, nullptr);
+  EXPECT_EQ(4, line);
+
+  clang_disposeSourceRangeList(Ranges);
+}
+
+class LibclangReparseTest : public LibclangParseTest {
+public:
   void DisplayDiagnostics() {
 unsigned NumDiagnostics = clang_getNumDiagnostics(ClangTU);
 for (unsigned i = 0; i < NumDiagnostics; ++i) {
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -7680,6 +7680,33 @@
   return skipped;
 }
 
+CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) {
+  CXSourceRangeList *skipped = new CXSourceRangeList;
+  skipped->count = 0;
+  skipped->ranges = nullptr;
+
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return skipped;
+  }
+
+  ASTUnit *astUnit = cxtu::getASTUnit(TU);
+  PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord();
+  if (!ppRec)
+return skipped;
+
+  ASTContext  = astUnit->getASTContext();
+
+  const std::vector  = ppRec->getSkippedRanges();
+
+  skipped->count = SkippedRanges.size();
+  skipped->ranges = new CXSourceRange[skipped->count];
+  for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
+

Re: [PATCH] D20131: Fixed crash during code completion in file included within declaration

2016-05-11 Thread Cameron via cfe-commits
cameron314 updated this revision to Diff 56961.
cameron314 added a comment.

Ah, perfect, thanks.
Behold, a test that fails without the patch and passes with it :-)


http://reviews.llvm.org/D20131

Files:
  lib/Lex/PPLexerChange.cpp
  test/CodeCompletion/include-within-declaration.c

Index: test/CodeCompletion/include-within-declaration.c
===
--- /dev/null
+++ test/CodeCompletion/include-within-declaration.c
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: echo 'MACRO(here)' > %t/y.h
+// Clang will generate an error in this case (though internally the correct 
completions
+// are present -- this can be seen via libclang) but it should not crash. If 
it crashes
+// then `not` will fail, otherwise the test succeeds.
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%t/y.h:1:7 -I %t %s
+
+enum {
+#define MACRO(a) FOO
+#include "y.h"
+};
Index: lib/Lex/PPLexerChange.cpp
===
--- lib/Lex/PPLexerChange.cpp
+++ lib/Lex/PPLexerChange.cpp
@@ -378,6 +378,8 @@
 Result.startToken();
 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
 CurLexer.reset();
+if (CurLexerKind == CLK_Lexer)
+  CurLexerKind = CLK_CachingLexer;
   } else {
 assert(CurPTHLexer && "Got EOF but no current lexer set!");
 CurPTHLexer->getEOF(Result);


Index: test/CodeCompletion/include-within-declaration.c
===
--- /dev/null
+++ test/CodeCompletion/include-within-declaration.c
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: echo 'MACRO(here)' > %t/y.h
+// Clang will generate an error in this case (though internally the correct completions
+// are present -- this can be seen via libclang) but it should not crash. If it crashes
+// then `not` will fail, otherwise the test succeeds.
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%t/y.h:1:7 -I %t %s
+
+enum {
+#define MACRO(a) FOO
+#include "y.h"
+};
Index: lib/Lex/PPLexerChange.cpp
===
--- lib/Lex/PPLexerChange.cpp
+++ lib/Lex/PPLexerChange.cpp
@@ -378,6 +378,8 @@
 Result.startToken();
 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
 CurLexer.reset();
+if (CurLexerKind == CLK_Lexer)
+  CurLexerKind = CLK_CachingLexer;
   } else {
 assert(CurPTHLexer && "Got EOF but no current lexer set!");
 CurPTHLexer->getEOF(Result);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20131: Fixed crash during code completion in file included within declaration

2016-05-11 Thread Cameron via cfe-commits
cameron314 added a comment.

I fixed this last July so the details are a little hazy, but fortunately it 
turns out I documented what I had found:

> It seems when clang parses an enum declaration, it first parses the 
> declaration specifiers, then stops if a semicolon is present.

>  The trouble is, an #include could cause the file to change part-way through 
> the declaration. If completion is enabled, then when leaving the included 
> file in which the completion was requested, the tokenizer is cleared (clang 
> tries to simulate an EOF at that point to prevent further parsing).

>  But, while the tokenizer is cleared, the rest of the declaration still needs 
> to be parsed, and the peeked token (a semicolon here) can no longer be 
> advanced over, since it refers in this case to a token in a tokenizer that 
> has been freed. Boom, null reference exception!

>  It seems changing the lexer kind to the caching lexer when the artificial 
> EOF is inserted does the right thing in this case – a cached EOF token is 
> returned on the advancement of the peeked semicolon.


I tried to add a test; I can reproduce the crash, and with this patch it no 
longer crashes, but because there's a subsequent parsing error after the 
completion point, when passing via `clang.exe` only the error diagnostics are 
printed without any of the completions (compared to libclang which allows you 
to retrieve both the completions and the diagnostics). This means I cannot 
write a RUN command in the lit test without it failing (the exit code is 
non-zero). I have no way to distinguish between a crash and the normal errors 
(with hidden completions). Is there any other way to test this?



Comment at: lib/Lex/PPLexerChange.cpp:380-382
@@ -379,3 +379,5 @@
 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
 CurLexer.reset();
+if (CurLexerKind == CLK_Lexer)
+  CurLexerKind = CLK_CachingLexer;
   } else {

rsmith wrote:
> Can you use `CurLexer->cutOffLexing()` instead?
Nope, still crashes when I try (before the reset, obviously).


http://reviews.llvm.org/D20131



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20131: Fixed crash during code completion in file included within declaration

2016-05-11 Thread Cameron via cfe-commits
cameron314 added inline comments.


Comment at: lib/Lex/PPLexerChange.cpp:380-383
@@ -379,4 +379,6 @@
 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
 CurLexer.reset();
+if (CurLexerKind == CLK_Lexer)
+  CurLexerKind = CLK_CachingLexer;
   } else {
 assert(CurPTHLexer && "Got EOF but no current lexer set!");

Ah, wait, yes this also prevents the crash if I remove the `CurLexer.reset()` 
and use `CurLexer->cutOffLexing()`, but it not only produces an error about a 
missing '}', but an error about an extra '}' just after, which doesn't really 
make sense. That means it's inspecting tokens past the EOF that was injected.


http://reviews.llvm.org/D20131



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20134: [libclang] Fixed bug where ranges in spelling locations (in macro expansions) would get mangled

2016-05-12 Thread Cameron via cfe-commits
cameron314 added a comment.

You're right, this breaks that test. The corner case that it exercises is 
arguably less important than breaking all spelling ranges, though. But I'm 
going to see if I can fix both with a little wizardry (ideally there wouldn't 
be open ranges in the first place, since clang doesn't really support them, but 
failing that we can distinguish between an inclusive and exclusive source 
location internally and that might be enough).


http://reviews.llvm.org/D20134



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-05-12 Thread Krystyna via cfe-commits
krystyna updated this revision to Diff 57007.
krystyna marked 8 inline comments as done.

Repository:
  rL LLVM

http://reviews.llvm.org/D18919

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseUsingCheck.cpp
  clang-tidy/modernize/UseUsingCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-using.rst
  test/clang-tidy/modernize-use-using.cpp

Index: test/clang-tidy/modernize-use-using.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-using.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t
+
+typedef int Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Type = int;
+
+typedef long LL;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using LL = long;
+
+typedef int Bla;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using Bla = int;
+
+typedef Bla Bla2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using Bla2 = Bla;
+
+typedef void (*type)(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using type = void (*)(int);
+
+typedef void (*type2)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using type2 = void (*)();
+
+class Class {
+  typedef long long Type;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use using instead of typedef
+  // CHECK-FIXES: using Type = long long;
+};
+
+typedef void (Class::*MyPtrType)(Bla) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using MyPtrType = void (Class::*)(Bla) const;
+
+class Iterable {
+public:
+  class Iterator {};
+};
+
+template 
+class Test {
+  typedef typename T::iterator Iter;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use using instead of typedef
+  // CHECK-FIXES: using Iter = typename T::iterator;
+};
+
+using balba = long long;
+
+union A {};
+
+typedef void (A::*PtrType)(int, int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using PtrType = void (A::*)(int, int) const;
+
+typedef Class some_class;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using some_class = Class;
+
+typedef Class Cclass;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using Cclass = Class;
+
+typedef Cclass cclass2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using cclass2 = Cclass;
+
+class cclass {};
+
+typedef void (cclass::*MyPtrType3)(Bla);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla);
+
+using my_class = int;
+
+typedef Test another;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using another = Test;
Index: docs/clang-tidy/checks/modernize-use-using.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-using.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - modernize-use-using
+
+modernize-use-using
+===
+
+Use C++11's ``using`` instead of ``typedef``.
+
+Before:
+
+.. code:: c++
+
+  typedef int variable;
+
+  class Class{};
+  typedef void (Class::* MyPtrType)() const;
+
+After:
+
+.. code:: c++
+
+  using variable = int;
+
+  class Class{};
+  using MyPtrType = void (Class::*)() const;
+
+This check requires using C++11 or higher to run.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -96,6 +96,7 @@
modernize-use-default
modernize-use-nullptr
modernize-use-override
+   modernize-use-using
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -161,6 +161,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-using
+  `_ check
+
+  Finds typedefs and replaces it with usings.
+
 - New `performance-faster-string-find
   `_ check
 
Index: clang-tidy/modernize/UseUsingCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseUsingCheck.h
@@ -0,0 +1,35 @@
+//===--- UseUsingCheck.h - 

Re: [PATCH] D20137: [PCH] Fixed bugs with preamble invalidation when files change (on Windows)

2016-05-17 Thread Cameron via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269769: [PCH] Fixed bug with preamble invalidation when 
overridden files change (authored by cameron314).

Changed prior to commit:
  http://reviews.llvm.org/D20137?vs=57367=57477#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20137

Files:
  cfe/trunk/lib/Frontend/ASTUnit.cpp

Index: cfe/trunk/lib/Frontend/ASTUnit.cpp
===
--- cfe/trunk/lib/Frontend/ASTUnit.cpp
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp
@@ -1378,7 +1378,7 @@
   
   // First, make a record of those files that have been overridden via
   // remapping or unsaved_files.
-  llvm::StringMap OverriddenFiles;
+  std::map OverriddenFiles;
   for (const auto  : PreprocessorOpts.RemappedFiles) {
 if (AnyFileChanged)
   break;
@@ -1391,24 +1391,38 @@
   break;
 }
 
-OverriddenFiles[R.first] = PreambleFileHash::createForFile(
+OverriddenFiles[Status.getUniqueID()] = 
PreambleFileHash::createForFile(
 Status.getSize(), Status.getLastModificationTime().toEpochTime());
   }
 
   for (const auto  : PreprocessorOpts.RemappedFileBuffers) {
 if (AnyFileChanged)
   break;
-OverriddenFiles[RB.first] =
+
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(RB.first, Status)) {
+  AnyFileChanged = true;
+  break;
+}
+
+OverriddenFiles[Status.getUniqueID()] =
 PreambleFileHash::createForMemoryBuffer(RB.second);
   }

   // Check whether anything has changed.
-  for (llvm::StringMap::iterator 
+  for (llvm::StringMap::iterator
  F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end();
!AnyFileChanged && F != FEnd; 
++F) {
-llvm::StringMap::iterator Overridden
-  = OverriddenFiles.find(F->first());
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(F->first(), Status)) {
+  // If we can't stat the file, assume that something horrible 
happened.
+  AnyFileChanged = true;
+  break;
+}
+
+std::map::iterator 
Overridden
+  = OverriddenFiles.find(Status.getUniqueID());
 if (Overridden != OverriddenFiles.end()) {
   // This file was remapped; check whether the newly-mapped file 
   // matches up with the previous mapping.
@@ -1418,13 +1432,9 @@
 }
 
 // The file was not remapped; check whether it has changed on disk.
-vfs::Status Status;
-if (FileMgr->getNoncachedStatValue(F->first(), Status)) {
-  // If we can't stat the file, assume that something horrible 
happened.
-  AnyFileChanged = true;
-} else if (Status.getSize() != uint64_t(F->second.Size) ||
-   Status.getLastModificationTime().toEpochTime() !=
-   uint64_t(F->second.ModTime))
+if (Status.getSize() != uint64_t(F->second.Size) ||
+Status.getLastModificationTime().toEpochTime() !=
+uint64_t(F->second.ModTime))
   AnyFileChanged = true;
   }
   


Index: cfe/trunk/lib/Frontend/ASTUnit.cpp
===
--- cfe/trunk/lib/Frontend/ASTUnit.cpp
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp
@@ -1378,7 +1378,7 @@
   
   // First, make a record of those files that have been overridden via
   // remapping or unsaved_files.
-  llvm::StringMap OverriddenFiles;
+  std::map OverriddenFiles;
   for (const auto  : PreprocessorOpts.RemappedFiles) {
 if (AnyFileChanged)
   break;
@@ -1391,24 +1391,38 @@
   break;
 }
 
-OverriddenFiles[R.first] = PreambleFileHash::createForFile(
+OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile(
 Status.getSize(), Status.getLastModificationTime().toEpochTime());
   }
 
   for (const auto  : PreprocessorOpts.RemappedFileBuffers) {
 if (AnyFileChanged)
   break;
-OverriddenFiles[RB.first] =
+
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(RB.first, Status)) {
+  AnyFileChanged = true;
+  break;
+}
+
+OverriddenFiles[Status.getUniqueID()] =
 PreambleFileHash::createForMemoryBuffer(RB.second);
   }

   // Check whether anything has changed.
-  for (llvm::StringMap::iterator 
+  for (llvm::StringMap::iterator
  F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end();
!AnyFileChanged && F != FEnd; 
++F) {
-llvm::StringMap::iterator Overridden
-  = OverriddenFiles.find(F->first());
+   

[PATCH] D20338: [PCH] Fixed overridden files always invalidating preamble even when unchanged

2016-05-17 Thread Cameron via cfe-commits
cameron314 created this revision.
cameron314 added a reviewer: rsmith.
cameron314 added a subscriber: cfe-commits.
cameron314 set the repository for this revision to rL LLVM.

Remapped files would always cause the preamble's PCH to be invalidated (even if 
they hadn't changed) because the file manager was replacing the remapped 
virtual entry (no modified time) with a real file entry (which has a modified 
time) when an include directive was processed. This happens when the include 
directive results in a slightly different path for the same file (e.g. 
different slash direction, which happens very often on Windows).

Note: This was initially part of D20137 but I had incorrectly applied my own 
patch, so the `IsVirtual = true` line was in the wrong spot and served no 
purpose (and was subsequently removed from the patch). Now it actually does 
something!

Repository:
  rL LLVM

http://reviews.llvm.org/D20338

Files:
  include/clang/Basic/FileManager.h
  lib/Basic/FileManager.cpp

Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -301,6 +301,11 @@
 return 
   }
 
+  if (UFE.isVirtual()) {
+UFE.Name = InterndFileName;
+return 
+  }
+
   // Otherwise, we don't have this file yet, add it.
   UFE.Name= InterndFileName;
   UFE.Size = Data.Size;
@@ -381,6 +386,7 @@
   UFE->Dir = DirInfo;
   UFE->UID = NextFileUID++;
   UFE->File.reset();
+  UFE->IsVirtual = true;
   return UFE;
 }
 
Index: include/clang/Basic/FileManager.h
===
--- include/clang/Basic/FileManager.h
+++ include/clang/Basic/FileManager.h
@@ -60,6 +60,7 @@
   bool IsNamedPipe;
   bool InPCH;
   bool IsValid;   // Is this \c FileEntry initialized and valid?
+  bool IsVirtual; // Is this \c FileEntry a virtual file?
 
   /// \brief The open file, if it is owned by the \p FileEntry.
   mutable std::unique_ptr File;
@@ -69,20 +70,23 @@
 
 public:
   FileEntry()
-  : UniqueID(0, 0), IsNamedPipe(false), InPCH(false), IsValid(false)
+  : UniqueID(0, 0), IsNamedPipe(false), InPCH(false), IsValid(false),
+IsVirtual(false)
   {}
 
   // FIXME: this is here to allow putting FileEntry in std::map.  Once we have
   // emplace, we shouldn't need a copy constructor anymore.
   /// Intentionally does not copy fields that are not set in an uninitialized
   /// \c FileEntry.
   FileEntry(const FileEntry ) : UniqueID(FE.UniqueID),
-  IsNamedPipe(FE.IsNamedPipe), InPCH(FE.InPCH), IsValid(FE.IsValid) {
+  IsNamedPipe(FE.IsNamedPipe), InPCH(FE.InPCH), IsValid(FE.IsValid),
+  IsVirtual(FE.IsVirtual) {
 assert(!isValid() && "Cannot copy an initialized FileEntry");
   }
 
   const char *getName() const { return Name; }
   bool isValid() const { return IsValid; }
+  bool isVirtual() const { return IsVirtual; }
   off_t getSize() const { return Size; }
   unsigned getUID() const { return UID; }
   const llvm::sys::fs::UniqueID () const { return UniqueID; }


Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -301,6 +301,11 @@
 return 
   }
 
+  if (UFE.isVirtual()) {
+UFE.Name = InterndFileName;
+return 
+  }
+
   // Otherwise, we don't have this file yet, add it.
   UFE.Name= InterndFileName;
   UFE.Size = Data.Size;
@@ -381,6 +386,7 @@
   UFE->Dir = DirInfo;
   UFE->UID = NextFileUID++;
   UFE->File.reset();
+  UFE->IsVirtual = true;
   return UFE;
 }
 
Index: include/clang/Basic/FileManager.h
===
--- include/clang/Basic/FileManager.h
+++ include/clang/Basic/FileManager.h
@@ -60,6 +60,7 @@
   bool IsNamedPipe;
   bool InPCH;
   bool IsValid;   // Is this \c FileEntry initialized and valid?
+  bool IsVirtual; // Is this \c FileEntry a virtual file?
 
   /// \brief The open file, if it is owned by the \p FileEntry.
   mutable std::unique_ptr File;
@@ -69,20 +70,23 @@
 
 public:
   FileEntry()
-  : UniqueID(0, 0), IsNamedPipe(false), InPCH(false), IsValid(false)
+  : UniqueID(0, 0), IsNamedPipe(false), InPCH(false), IsValid(false),
+IsVirtual(false)
   {}
 
   // FIXME: this is here to allow putting FileEntry in std::map.  Once we have
   // emplace, we shouldn't need a copy constructor anymore.
   /// Intentionally does not copy fields that are not set in an uninitialized
   /// \c FileEntry.
   FileEntry(const FileEntry ) : UniqueID(FE.UniqueID),
-  IsNamedPipe(FE.IsNamedPipe), InPCH(FE.InPCH), IsValid(FE.IsValid) {
+  IsNamedPipe(FE.IsNamedPipe), InPCH(FE.InPCH), IsValid(FE.IsValid),
+  IsVirtual(FE.IsVirtual) {
 assert(!isValid() && "Cannot copy an initialized FileEntry");
   }
 
   const char *getName() const { return Name; }
   bool isValid() const { return IsValid; 

Re: [PATCH] D20137: [PCH] Fixed bugs with preamble invalidation when files change (on Windows)

2016-05-16 Thread Cameron via cfe-commits
cameron314 added inline comments.


Comment at: lib/Frontend/ASTUnit.cpp:1402-1406
@@ +1401,7 @@
+
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(RB.first, Status)) {
+  AnyFileChanged = true;
+  break;
+}
+

rsmith wrote:
> Suppose file names A and B refer to file (inode) X, and the map contains X -> 
> (A, hash). If B is deleted (and maybe recreated pointing at a new inode), 
> this approach won't detect that anything has changed.
Ah, I understand. The problem isn't really with the overridden file map, which 
still has to be by inode in order for lookups to find the right file regardless 
of name, but with the FilesInPreamble map, which needs to stay as a list of 
independent filenames in case the inodes associated to those filenames changes 
in between parses.

I'll make the change, thanks!


http://reviews.llvm.org/D20137



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20137: [PCH] Fixed bugs with preamble invalidation when files change (on Windows)

2016-05-16 Thread Cameron via cfe-commits
cameron314 updated the summary for this revision.
cameron314 updated this revision to Diff 57367.
cameron314 added a comment.

This version of the patch takes into account potential changes between 
filenames and their unique IDs between parses.


http://reviews.llvm.org/D20137

Files:
  lib/Frontend/ASTUnit.cpp

Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1378,7 +1378,7 @@
   
   // First, make a record of those files that have been overridden via
   // remapping or unsaved_files.
-  llvm::StringMap OverriddenFiles;
+  std::map OverriddenFiles;
   for (const auto  : PreprocessorOpts.RemappedFiles) {
 if (AnyFileChanged)
   break;
@@ -1391,24 +1391,38 @@
   break;
 }
 
-OverriddenFiles[R.first] = PreambleFileHash::createForFile(
+OverriddenFiles[Status.getUniqueID()] = 
PreambleFileHash::createForFile(
 Status.getSize(), Status.getLastModificationTime().toEpochTime());
   }
 
   for (const auto  : PreprocessorOpts.RemappedFileBuffers) {
 if (AnyFileChanged)
   break;
-OverriddenFiles[RB.first] =
+
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(RB.first, Status)) {
+  AnyFileChanged = true;
+  break;
+}
+
+OverriddenFiles[Status.getUniqueID()] =
 PreambleFileHash::createForMemoryBuffer(RB.second);
   }

   // Check whether anything has changed.
-  for (llvm::StringMap::iterator 
+  for (llvm::StringMap::iterator
  F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end();
!AnyFileChanged && F != FEnd; 
++F) {
-llvm::StringMap::iterator Overridden
-  = OverriddenFiles.find(F->first());
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(F->first(), Status)) {
+  // If we can't stat the file, assume that something horrible 
happened.
+  AnyFileChanged = true;
+  break;
+}
+
+std::map::iterator 
Overridden
+  = OverriddenFiles.find(Status.getUniqueID());
 if (Overridden != OverriddenFiles.end()) {
   // This file was remapped; check whether the newly-mapped file 
   // matches up with the previous mapping.
@@ -1418,11 +1432,7 @@
 }
 
 // The file was not remapped; check whether it has changed on disk.
-vfs::Status Status;
-if (FileMgr->getNoncachedStatValue(F->first(), Status)) {
-  // If we can't stat the file, assume that something horrible 
happened.
-  AnyFileChanged = true;
-} else if (Status.getSize() != uint64_t(F->second.Size) ||
+if (Status.getSize() != uint64_t(F->second.Size) ||
Status.getLastModificationTime().toEpochTime() !=
uint64_t(F->second.ModTime))
   AnyFileChanged = true;


Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1378,7 +1378,7 @@
   
   // First, make a record of those files that have been overridden via
   // remapping or unsaved_files.
-  llvm::StringMap OverriddenFiles;
+  std::map OverriddenFiles;
   for (const auto  : PreprocessorOpts.RemappedFiles) {
 if (AnyFileChanged)
   break;
@@ -1391,24 +1391,38 @@
   break;
 }
 
-OverriddenFiles[R.first] = PreambleFileHash::createForFile(
+OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile(
 Status.getSize(), Status.getLastModificationTime().toEpochTime());
   }
 
   for (const auto  : PreprocessorOpts.RemappedFileBuffers) {
 if (AnyFileChanged)
   break;
-OverriddenFiles[RB.first] =
+
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(RB.first, Status)) {
+  AnyFileChanged = true;
+  break;
+}
+
+OverriddenFiles[Status.getUniqueID()] =
 PreambleFileHash::createForMemoryBuffer(RB.second);
   }

   // Check whether anything has changed.
-  for (llvm::StringMap::iterator 
+  for (llvm::StringMap::iterator
  F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end();
!AnyFileChanged && F != FEnd; 
++F) {
-llvm::StringMap::iterator Overridden
-  = OverriddenFiles.find(F->first());
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(F->first(), Status)) {
+  // If we can't stat the file, assume that something horrible happened.
+  AnyFileChanged = true;
+  break;
+}
+
+

Re: [PATCH] D20089: Adding a TargetParser for AArch64

2016-05-16 Thread jojo.ma via cfe-commits
jojo added a comment.

Dear  Bradley,Renato

Sorry for late reply,I have been on leave the last three days.
Thank you very much for your review and suggestons.I will re pondering the 
changes.


Repository:
  rL LLVM

http://reviews.llvm.org/D20089



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20137: [PCH] Fixed bugs with preamble invalidation when files change (on Windows)

2016-05-13 Thread Cameron via cfe-commits
cameron314 updated this revision to Diff 57253.
cameron314 added a comment.

Removed workaround for case that can no longer happen.


http://reviews.llvm.org/D20137

Files:
  include/clang/Frontend/ASTUnit.h
  lib/Frontend/ASTUnit.cpp

Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1378,7 +1378,7 @@
   
   // First, make a record of those files that have been overridden via
   // remapping or unsaved_files.
-  llvm::StringMap OverriddenFiles;
+  std::map OverriddenFiles;
   for (const auto  : PreprocessorOpts.RemappedFiles) {
 if (AnyFileChanged)
   break;
@@ -1391,40 +1391,47 @@
   break;
 }
 
-OverriddenFiles[R.first] = PreambleFileHash::createForFile(
+OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile(
 Status.getSize(), Status.getLastModificationTime().toEpochTime());
   }
 
   for (const auto  : PreprocessorOpts.RemappedFileBuffers) {
 if (AnyFileChanged)
   break;
-OverriddenFiles[RB.first] =
+
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(RB.first, Status)) {
+  AnyFileChanged = true;
+  break;
+}
+
+OverriddenFiles[Status.getUniqueID()] =
 PreambleFileHash::createForMemoryBuffer(RB.second);
   }

   // Check whether anything has changed.
-  for (llvm::StringMap::iterator 
+  for (FilesInPreambleMap::iterator
  F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end();
!AnyFileChanged && F != FEnd; 
++F) {
-llvm::StringMap::iterator Overridden
-  = OverriddenFiles.find(F->first());
+std::map::iterator Overridden
+  = OverriddenFiles.find(F->first);
 if (Overridden != OverriddenFiles.end()) {
   // This file was remapped; check whether the newly-mapped file 
   // matches up with the previous mapping.
-  if (Overridden->second != F->second)
+  if (Overridden->second != F->second.second)
 AnyFileChanged = true;
   continue;
 }
 
 // The file was not remapped; check whether it has changed on disk.
 vfs::Status Status;
-if (FileMgr->getNoncachedStatValue(F->first(), Status)) {
+if (FileMgr->getNoncachedStatValue(F->second.first, Status)) {
   // If we can't stat the file, assume that something horrible happened.
   AnyFileChanged = true;
-} else if (Status.getSize() != uint64_t(F->second.Size) ||
+} else if (Status.getSize() != uint64_t(F->second.second.Size) ||
Status.getLastModificationTime().toEpochTime() !=
-   uint64_t(F->second.ModTime))
+   uint64_t(F->second.second.ModTime))
   AnyFileChanged = true;
   }
   
@@ -1612,12 +1619,14 @@
 if (!File || File == SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()))
   continue;
 if (time_t ModTime = File->getModificationTime()) {
-  FilesInPreamble[File->getName()] = PreambleFileHash::createForFile(
-  File->getSize(), ModTime);
+  FilesInPreamble[File->getUniqueID()] = std::make_pair(
+File->getName(),
+PreambleFileHash::createForFile(File->getSize(), ModTime));
 } else {
   llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File);
-  FilesInPreamble[File->getName()] =
-  PreambleFileHash::createForMemoryBuffer(Buffer);
+  FilesInPreamble[File->getUniqueID()] = std::make_pair(
+File->getName(),
+PreambleFileHash::createForMemoryBuffer(Buffer));
 }
   }
 
Index: include/clang/Frontend/ASTUnit.h
===
--- include/clang/Frontend/ASTUnit.h
+++ include/clang/Frontend/ASTUnit.h
@@ -31,6 +31,7 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/FileSystem.h"
 #include 
 #include 
 #include 
@@ -264,12 +265,15 @@
   /// a line after skipping the preamble.
   bool PreambleEndsAtStartOfLine;
 
+  typedef std::map> FilesInPreambleMap;
+
   /// \brief Keeps track of the files that were used when computing the 
   /// preamble, with both their buffer size and their modification time.
   ///
   /// If any of the files have changed from one compile to the next,
   /// the preamble must be thrown away.
-  llvm::StringMap FilesInPreamble;
+  FilesInPreambleMap FilesInPreamble;
 
   /// \brief When non-NULL, this is the buffer used to store the contents of
   /// the main file when it has been padded for use with the precompiled

Re: [PATCH] D20137: [PCH] Fixed bugs with preamble invalidation when files change (on Windows)

2016-05-13 Thread Cameron via cfe-commits
cameron314 added inline comments.


Comment at: lib/Basic/FileManager.cpp:304-307
@@ -303,1 +303,6 @@
 
+  if (UFE.isVirtual()) {
+UFE.Name = InterndFileName;
+return 
+  }
+

rsmith wrote:
> It looks like this is unreachable: `IsVirtual` is only ever `true` when 
> `IsValid` is also `true`, and we don't reach this line if `UFE.isValid()`. As 
> this is the only consumer of `FileEntry::IsValid`, it looks like it does 
> nothing. Am I missing something?
Hmm, interesting, good catch. Back when I made this change UFE.IsValid was 
//not// set to true in the fall-through after this if, which is why I had to 
introduce `IsVirtual` in the first place.

But looking at the history on this file, it seems it //was// set to true since 
the very beginning. I think we'd removed it in our local fork at one point to 
work around a different bug, but it's back to normal in ours as well. So I 
guess this part of the patch is unnecessary now. Yay! I'll remove it, it wasn't 
very pretty anyway.


Comment at: lib/Frontend/ASTUnit.cpp:1402-1406
@@ +1401,7 @@
+
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(RB.first, Status)) {
+  AnyFileChanged = true;
+  break;
+}
+

rsmith wrote:
> If there are multiple file names with the same inode, `RB.first` is an 
> arbitrarily-chosen one of those names, and stat'ing it isn't sufficient to 
> check that none of the other names for the file have changed. Maybe we need 
> to store a list of filenames used for each `UniqueID`?
I'm not sure I understand -- if the file changed on disk, why would it matter 
which name we're accessing it by?


http://reviews.llvm.org/D20137



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19902: [ProfileData] (clang) Use Error in InstrProf and Coverage

2016-05-13 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269492: Reapply "[ProfileData] (clang) Use Error in 
InstrProf and Coverage, NFC" (authored by vedantk).

Changed prior to commit:
  http://reviews.llvm.org/D19902?vs=56346=57259#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19902

Files:
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Index: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
@@ -800,20 +800,21 @@
   bool IsInMainFile) {
   CGM.getPGOStats().addVisited(IsInMainFile);
   RegionCounts.clear();
-  llvm::ErrorOr RecordErrorOr =
+  llvm::Expected RecordExpected =
   PGOReader->getInstrProfRecord(FuncName, FunctionHash);
-  if (std::error_code EC = RecordErrorOr.getError()) {
-if (EC == llvm::instrprof_error::unknown_function)
+  if (auto E = RecordExpected.takeError()) {
+auto IPE = llvm::InstrProfError::take(std::move(E));
+if (IPE == llvm::instrprof_error::unknown_function)
   CGM.getPGOStats().addMissing(IsInMainFile);
-else if (EC == llvm::instrprof_error::hash_mismatch)
+else if (IPE == llvm::instrprof_error::hash_mismatch)
   CGM.getPGOStats().addMismatched(IsInMainFile);
-else if (EC == llvm::instrprof_error::malformed)
+else if (IPE == llvm::instrprof_error::malformed)
   // TODO: Consider a more specific warning for this case.
   CGM.getPGOStats().addMismatched(IsInMainFile);
 return;
   }
   ProfRecord =
-  llvm::make_unique(std::move(RecordErrorOr.get()));
+  
llvm::make_unique(std::move(RecordExpected.get()));
   RegionCounts = ProfRecord->Counts;
 }
 
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -141,11 +141,13 @@
   if (CodeGenOpts.hasProfileClangUse()) {
 auto ReaderOrErr = llvm::IndexedInstrProfReader::create(
 CodeGenOpts.ProfileInstrumentUsePath);
-if (std::error_code EC = ReaderOrErr.getError()) {
+if (auto E = ReaderOrErr.takeError()) {
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
   "Could not read profile %0: %1");
-  getDiags().Report(DiagID) << CodeGenOpts.ProfileInstrumentUsePath
-<< EC.message();
+  llvm::handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase ) {
+getDiags().Report(DiagID) << CodeGenOpts.ProfileInstrumentUsePath
+  << EI.message();
+  });
 } else
   PGOReader = std::move(ReaderOrErr.get());
   }
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -403,7 +403,8 @@
   const std::string ProfileName) {
   auto ReaderOrErr = llvm::IndexedInstrProfReader::create(ProfileName);
   // In error, return silently and let Clang PGOUse report the error message.
-  if (ReaderOrErr.getError()) {
+  if (auto E = ReaderOrErr.takeError()) {
+llvm::consumeError(std::move(E));
 Opts.setProfileUse(CodeGenOptions::ProfileClangInstr);
 return;
   }


Index: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
@@ -800,20 +800,21 @@
   bool IsInMainFile) {
   CGM.getPGOStats().addVisited(IsInMainFile);
   RegionCounts.clear();
-  llvm::ErrorOr RecordErrorOr =
+  llvm::Expected RecordExpected =
   PGOReader->getInstrProfRecord(FuncName, FunctionHash);
-  if (std::error_code EC = RecordErrorOr.getError()) {
-if (EC == llvm::instrprof_error::unknown_function)
+  if (auto E = RecordExpected.takeError()) {
+auto IPE = llvm::InstrProfError::take(std::move(E));
+if (IPE == llvm::instrprof_error::unknown_function)
   CGM.getPGOStats().addMissing(IsInMainFile);
-else if (EC == llvm::instrprof_error::hash_mismatch)
+else if (IPE == llvm::instrprof_error::hash_mismatch)
   CGM.getPGOStats().addMismatched(IsInMainFile);
-else if (EC == llvm::instrprof_error::malformed)
+else if (IPE == llvm::instrprof_error::malformed)
   // TODO: Consider a more specific warning for this case.
   CGM.getPGOStats().addMismatched(IsInMainFile);
 return;
   }
   ProfRecord =
-  llvm::make_unique(std::move(RecordErrorOr.get()));
+  llvm::make_unique(std::move(RecordExpected.get()));
   RegionCounts = ProfRecord->Counts;
 }
 
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Re: [PATCH] D20372: [include-fixer] Also look up prefixes of queries.

2016-05-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269956: [include-fixer] Also look up prefixes of queries. 
(authored by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D20372?vs=57635=57642#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20372

Files:
  clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
  clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp

Index: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
===
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
@@ -55,9 +55,6 @@
  {{SymbolInfo::ContextType::Namespace, "std"}}),
   SymbolInfo("sting", SymbolInfo::SymbolKind::Class, "\"sting\"", 1,
  {{SymbolInfo::ContextType::Namespace, "std"}}),
-  SymbolInfo("size_type", SymbolInfo::SymbolKind::Variable, "", 1,
- {{SymbolInfo::ContextType::Namespace, "string"},
-  {SymbolInfo::ContextType::Namespace, "std"}}),
   SymbolInfo("foo", SymbolInfo::SymbolKind::Class, "\"dir/otherdir/qux.h\"",
  1, {{SymbolInfo::ContextType::Namespace, "b"},
  {SymbolInfo::ContextType::Namespace, "a"}}),
Index: clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
===
--- clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
+++ clang-tools-extra/trunk/include-fixer/SymbolIndexManager.cpp
@@ -24,53 +24,61 @@
   llvm::SmallVector Names;
   Identifier.split(Names, "::");
 
-  std::vector Symbols;
-  for (const auto  : SymbolIndices) {
-auto Res = DB->search(Names.back().str());
-Symbols.insert(Symbols.end(), Res.begin(), Res.end());
-  }
+  // As long as we don't find a result keep stripping name parts from the end.
+  // This is to support nested classes which aren't recorded in the database.
+  // Eventually we will either hit a class (namespaces aren't in the database
+  // either) and can report that result.
+  std::vector Results;
+  while (Results.empty() && !Names.empty()) {
+std::vector Symbols;
+for (const auto  : SymbolIndices) {
+  auto Res = DB->search(Names.back().str());
+  Symbols.insert(Symbols.end(), Res.begin(), Res.end());
+}
 
-  DEBUG(llvm::dbgs() << "Searching " << Names.back() << "... got "
- << Symbols.size() << " results...\n");
+DEBUG(llvm::dbgs() << "Searching " << Names.back() << "... got "
+   << Symbols.size() << " results...\n");
 
-  std::vector Results;
-  for (const auto  : Symbols) {
-// Match the identifier name without qualifier.
-if (Symbol.getName() == Names.back()) {
-  bool IsMatched = true;
-  auto SymbolContext = Symbol.getContexts().begin();
-  auto IdentiferContext = Names.rbegin() + 1; // Skip identifier name;
-  // Match the remaining context names.
-  while (IdentiferContext != Names.rend() &&
- SymbolContext != Symbol.getContexts().end()) {
-if (SymbolContext->second == *IdentiferContext) {
-  ++IdentiferContext;
-  ++SymbolContext;
-} else if (SymbolContext->first ==
-   find_all_symbols::SymbolInfo::ContextType::EnumDecl) {
-  // Skip non-scoped enum context.
-  ++SymbolContext;
-} else {
-  IsMatched = false;
-  break;
+for (const auto  : Symbols) {
+  // Match the identifier name without qualifier.
+  if (Symbol.getName() == Names.back()) {
+bool IsMatched = true;
+auto SymbolContext = Symbol.getContexts().begin();
+auto IdentiferContext = Names.rbegin() + 1; // Skip identifier name.
+// Match the remaining context names.
+while (IdentiferContext != Names.rend() &&
+   SymbolContext != Symbol.getContexts().end()) {
+  if (SymbolContext->second == *IdentiferContext) {
+++IdentiferContext;
+++SymbolContext;
+  } else if (SymbolContext->first ==
+ find_all_symbols::SymbolInfo::ContextType::EnumDecl) {
+// Skip non-scoped enum context.
+++SymbolContext;
+  } else {
+IsMatched = false;
+break;
+  }
 }
-  }
 
-  // FIXME: Support full match. At this point, we only find symbols in
-  // database which end with the same contexts with the identifier.
-  if (IsMatched && IdentiferContext == Names.rend()) {
-// FIXME: file path should never be in the form of <...> or "...", but
-// the unit test with fixed database use <...> file path, which might
-// need to be changed.
-// FIXME: if the file path is a system header name, we want to use angle
-// brackets.
-

Re: [PATCH] D20137: [PCH] Fixed bugs with preamble invalidation when files change (on Windows)

2016-05-13 Thread Cameron via cfe-commits
cameron314 updated this revision to Diff 57222.
cameron314 added a comment.

Updated patch to include later fixes I had made after the initial change.


http://reviews.llvm.org/D20137

Files:
  include/clang/Basic/FileManager.h
  include/clang/Frontend/ASTUnit.h
  lib/Basic/FileManager.cpp
  lib/Frontend/ASTUnit.cpp

Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1378,7 +1378,7 @@
   
   // First, make a record of those files that have been overridden via
   // remapping or unsaved_files.
-  llvm::StringMap OverriddenFiles;
+  std::map OverriddenFiles;
   for (const auto  : PreprocessorOpts.RemappedFiles) {
 if (AnyFileChanged)
   break;
@@ -1391,40 +1391,47 @@
   break;
 }
 
-OverriddenFiles[R.first] = PreambleFileHash::createForFile(
+OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile(
 Status.getSize(), Status.getLastModificationTime().toEpochTime());
   }
 
   for (const auto  : PreprocessorOpts.RemappedFileBuffers) {
 if (AnyFileChanged)
   break;
-OverriddenFiles[RB.first] =
+
+vfs::Status Status;
+if (FileMgr->getNoncachedStatValue(RB.first, Status)) {
+  AnyFileChanged = true;
+  break;
+}
+
+OverriddenFiles[Status.getUniqueID()] =
 PreambleFileHash::createForMemoryBuffer(RB.second);
   }

   // Check whether anything has changed.
-  for (llvm::StringMap::iterator 
+  for (FilesInPreambleMap::iterator
  F = FilesInPreamble.begin(), FEnd = FilesInPreamble.end();
!AnyFileChanged && F != FEnd; 
++F) {
-llvm::StringMap::iterator Overridden
-  = OverriddenFiles.find(F->first());
+std::map::iterator Overridden
+  = OverriddenFiles.find(F->first);
 if (Overridden != OverriddenFiles.end()) {
   // This file was remapped; check whether the newly-mapped file 
   // matches up with the previous mapping.
-  if (Overridden->second != F->second)
+  if (Overridden->second != F->second.second)
 AnyFileChanged = true;
   continue;
 }
 
 // The file was not remapped; check whether it has changed on disk.
 vfs::Status Status;
-if (FileMgr->getNoncachedStatValue(F->first(), Status)) {
+if (FileMgr->getNoncachedStatValue(F->second.first, Status)) {
   // If we can't stat the file, assume that something horrible happened.
   AnyFileChanged = true;
-} else if (Status.getSize() != uint64_t(F->second.Size) ||
+} else if (Status.getSize() != uint64_t(F->second.second.Size) ||
Status.getLastModificationTime().toEpochTime() !=
-   uint64_t(F->second.ModTime))
+   uint64_t(F->second.second.ModTime))
   AnyFileChanged = true;
   }
   
@@ -1612,12 +1619,14 @@
 if (!File || File == SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()))
   continue;
 if (time_t ModTime = File->getModificationTime()) {
-  FilesInPreamble[File->getName()] = PreambleFileHash::createForFile(
-  File->getSize(), ModTime);
+  FilesInPreamble[File->getUniqueID()] = std::make_pair(
+File->getName(),
+PreambleFileHash::createForFile(File->getSize(), ModTime));
 } else {
   llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File);
-  FilesInPreamble[File->getName()] =
-  PreambleFileHash::createForMemoryBuffer(Buffer);
+  FilesInPreamble[File->getUniqueID()] = std::make_pair(
+File->getName(),
+PreambleFileHash::createForMemoryBuffer(Buffer));
 }
   }
 
Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -301,6 +301,11 @@
 return 
   }
 
+  if (UFE.isVirtual()) {
+UFE.Name = InterndFileName;
+return 
+  }
+
   // Otherwise, we don't have this file yet, add it.
   UFE.Name= InterndFileName;
   UFE.Size = Data.Size;
@@ -312,6 +317,7 @@
   UFE.InPCH = Data.InPCH;
   UFE.File = std::move(F);
   UFE.IsValid = true;
+  UFE.IsVirtual = true;
   return 
 }
 
Index: include/clang/Frontend/ASTUnit.h
===
--- include/clang/Frontend/ASTUnit.h
+++ include/clang/Frontend/ASTUnit.h
@@ -31,6 +31,7 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/FileSystem.h"
 #include 
 #include 
 #include 
@@ -264,12 +265,15 @@
   /// a line after skipping the preamble.
   bool PreambleEndsAtStartOfLine;
 
+  typedef 

Re: [PATCH] D20213: [Clang] Fix Clang-tidy modernize-use-bool-literals in generated code.

2016-05-12 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269371: Fix Clang-tidy modernize-use-bool-literals in 
generated code. (authored by eugenezelenko).

Changed prior to commit:
  http://reviews.llvm.org/D20213?vs=57106=57110#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20213

Files:
  cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Index: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
===
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
@@ -11,24 +11,36 @@
 //
 //===--===//
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/StringMatcher.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include 
+#include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 using namespace llvm;
 
 namespace {
+
 class FlattenedSpelling {
   std::string V, N, NS;
   bool K;
@@ -54,6 +66,7 @@
   const std::string () const { return NS; }
   bool knownToGCC() const { return K; }
 };
+
 } // end anonymous namespace
 
 static std::vector
@@ -159,6 +172,7 @@
 }
 
 namespace {
+
   class Argument {
 std::string lowerName, upperName;
 StringRef attrName;
@@ -230,35 +244,45 @@
   OS << "return " << getLowerName() << ";\n";
   OS << "  }";
 }
+
 void writeCloneArgs(raw_ostream ) const override {
   OS << getLowerName();
 }
+
 void writeTemplateInstantiationArgs(raw_ostream ) const override {
   OS << "A->get" << getUpperName() << "()";
 }
+
 void writeCtorInitializers(raw_ostream ) const override {
   OS << getLowerName() << "(" << getUpperName() << ")";
 }
+
 void writeCtorDefaultInitializers(raw_ostream ) const override {
   OS << getLowerName() << "()";
 }
+
 void writeCtorParameters(raw_ostream ) const override {
   OS << type << " " << getUpperName();
 }
+
 void writeDeclarations(raw_ostream ) const override {
   OS << type << " " << getLowerName() << ";";
 }
+
 void writePCHReadDecls(raw_ostream ) const override {
   std::string read = ReadPCHRecord(type);
   OS << "" << type << " " << getLowerName() << " = " << read << ";\n";
 }
+
 void writePCHReadArgs(raw_ostream ) const override {
   OS << getLowerName();
 }
+
 void writePCHWrite(raw_ostream ) const override {
   OS << "" << WritePCHRecord(type, "SA->get" +
std::string(getUpperName()) + "()");
 }
+
 void writeValue(raw_ostream ) const override {
   if (type == "FunctionDecl *") {
 OS << "\" << get" << getUpperName()
@@ -271,6 +295,7 @@
 OS << "\" << get" << getUpperName() << "() << \"";
   }
 }
+
 void writeDump(raw_ostream ) const override {
   if (type == "FunctionDecl *") {
 OS << "OS << \" \";\n";
@@ -306,7 +331,12 @@
   SimpleArgument::writeAccessors(OS);
 
   OS << "\n\n  static const " << getType() << " Default" << getUpperName()
- << " = " << Default << ";";
+ << " = ";
+  if (getType() == "bool")
+OS << (Default != 0 ? "true" : "false");
+  else
+OS << Default;
+  OS << ";";
 }
   };
 
@@ -334,45 +364,57 @@
  << getLowerName() << "Length);\n";
   OS << "  }";
 }
+
 void writeCloneArgs(raw_ostream ) const override {
   OS << "get" << getUpperName() << "()";
 }
+
 void writeTemplateInstantiationArgs(raw_ostream ) const override {
   OS << "A->get" << getUpperName() << "()";
 }
+
 void writeCtorBody(raw_ostream ) const override {
   OS << "  if (!" << getUpperName() << ".empty())\n";
   OS << "std::memcpy(" << getLowerName() << ", " << getUpperName()
- << ".data(), " << getLowerName() << "Length);";
+ << ".data(), " << getLowerName() << "Length);\n";
 }
+
 void writeCtorInitializers(raw_ostream ) const override {
   OS << getLowerName() << "Length(" << getUpperName() << ".size()),"
  << getLowerName() << "(new (Ctx, 1) char[" << getLowerName()
  << "Length])";
 }
+
 void writeCtorDefaultInitializers(raw_ostream ) const override {
   OS << getLowerName() << "Length(0)," << getLowerName() << "(nullptr)";
 }
+
 void writeCtorParameters(raw_ostream ) const override {
   OS << "llvm::StringRef " << getUpperName();
 }
+
 void writeDeclarations(raw_ostream ) const 

Re: [PATCH] D20103: PR27132: Proper mangling for __unaligned qualifier (now with both PR27367 and PR27666 fixed)

2016-05-11 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL269220: [MSVC] Implementation of __unaligned as a proper 
type qualifier (authored by asbokhan).

Changed prior to commit:
  http://reviews.llvm.org/D20103?vs=56874=56945#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20103

Files:
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Basic/AddressSpaces.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/DeclSpec.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/AST/MicrosoftMangle.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseTentative.cpp
  cfe/trunk/lib/Sema/DeclSpec.cpp
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclObjC.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp
  cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp
  cfe/trunk/test/Sema/MicrosoftExtensions.c
  cfe/trunk/test/Sema/address_spaces.c
  cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c
  cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3374,6 +3374,16 @@
 "%select{const|restrict|const and restrict|volatile|const and volatile|"
 "volatile and restrict|const, volatile, and restrict}3 qualifier"
 "%select{||s||s|s|s}3">;
+def note_ovl_candidate_bad_unaligned : Note<"candidate "
+"%select{function|function|constructor|"
+"function |function |constructor |"
+"constructor (the implicit default constructor)|"
+"constructor (the implicit copy constructor)|"
+"constructor (the implicit move constructor)|"
+"function (the implicit copy assignment operator)|"
+"function (the implicit move assignment operator)|"
+"constructor (inherited)}0%1 not viable: "
+"%ordinal4 argument (%2) would lose __unaligned qualifier">;
 def note_ovl_candidate_bad_base_to_derived_conv : Note<"candidate "
 "%select{function|function|constructor|"
 "function |function |constructor |"
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -2157,10 +2157,6 @@
   }];
 }
 
-def Unaligned : IgnoredAttr {
-  let Spellings = [Keyword<"__unaligned">];
-}
-
 def LoopHint : Attr {
   /// #pragma clang loop  directive
   /// vectorize: vectorizes loop operations if State == Enable.
Index: cfe/trunk/include/clang/Basic/AddressSpaces.h
===
--- cfe/trunk/include/clang/Basic/AddressSpaces.h
+++ cfe/trunk/include/clang/Basic/AddressSpaces.h
@@ -25,7 +25,7 @@
 /// This uses a high starting offset so as not to conflict with any address
 /// space used by a target.
 enum ID {
-  Offset = 0x00,
+  Offset = 0x7FFF00,
 
   opencl_global = Offset,
   opencl_local,
Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -111,6 +111,7 @@
 /// The collection of all-type qualifiers we support.
 /// Clang supports five independent qualifiers:
 /// * C99: const, volatile, and restrict
+/// * MS: __unaligned
 /// * Embedded C (TR18037): address spaces
 /// * Objective C: the GC attributes (none, weak, or strong)
 class Qualifiers {
@@ -152,8 +153,8 @@
 
   enum {
 /// The maximum supported address space number.
-/// 24 bits should be enough for anyone.
-MaxAddressSpace = 0xffu,
+/// 23 bits should be enough for anyone.
+MaxAddressSpace = 0x7fu,
 
 /// The width of the "fast" qualifier mask.
 FastWidth = 3,
@@ -265,6 +266,13 @@
 Mask |= mask;
   }
 
+  bool hasUnaligned() const { return Mask & UMask; }
+  void setUnaligned(bool flag) {
+Mask = (Mask & ~UMask) | (flag ? UMask : 0);
+  }
+  void removeUnaligned() { Mask &= ~UMask; }
+  void addUnaligned() { Mask |= UMask; }
+
   bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
   GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
   void setObjCGCAttr(GC type) {
@@ -433,7 +441,9 @@
// ObjC lifetime qualifiers must match exactly.
getObjCLifetime() == other.getObjCLifetime() &&
// CVR qualifiers may subset.
-   (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
+   (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
+   // U qualifier may superset.
+   (!other.hasUnaligned() 

Re: [PATCH] D18088: Add a new warning to notify users of mismatched SDK and deployment target

2016-04-29 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268127: Add a new warning to notify users of mismatched SDK 
and deployment target (authored by cbieneman).

Changed prior to commit:
  http://reviews.llvm.org/D18088?vs=55652=55678#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18088

Files:
  cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
  cfe/trunk/lib/Driver/ToolChains.cpp
  cfe/trunk/lib/Driver/ToolChains.h
  cfe/trunk/test/Driver/incompatible_sysroot.c

Index: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
@@ -198,6 +198,8 @@
   "precompiled header '%0' was ignored because '%1' is not first '-include'">;
 def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,
   InGroup>;
+def warn_incompatible_sysroot : Warning<"using sysroot for '%0' but targeting '%1'">,
+  InGroup>;
 def warn_debug_compression_unavailable : Warning<"cannot compress debug sections (zlib not installed)">,
   InGroup>;
 def warn_drv_enabling_rtti_with_exceptions : Warning<
Index: cfe/trunk/test/Driver/incompatible_sysroot.c
===
--- cfe/trunk/test/Driver/incompatible_sysroot.c
+++ cfe/trunk/test/Driver/incompatible_sysroot.c
@@ -0,0 +1,12 @@
+// RUN: %clang -Wincompatible-sysroot -isysroot SDKs/MacOSX10.9.sdk -mios-version-min=9.0 -S -o - %s 2>&1 | FileCheck -check-prefix CHECK-OSX-IOS %s
+// RUN: %clang -Wincompatible-sysroot -isysroot SDKs/iPhoneOS9.2.sdk -mwatchos-version-min=2.0 -S -o - %s 2>&1 | FileCheck -check-prefix CHECK-IOS-WATCHOS %s
+// RUN: %clang -Wincompatible-sysroot -isysroot SDKs/iPhoneOS9.2.sdk -mtvos-version-min=9.0 -S -o - %s 2>&1 | FileCheck -check-prefix CHECK-IOS-TVOS %s
+// RUN: %clang -Wincompatible-sysroot -isysroot SDKs/iPhoneSimulator9.2.sdk -mios-version-min=9.0 -S -o - %s 2>&1 | FileCheck -check-prefix CHECK-IOS-IOSSIM %s
+// RUN: %clang -Wno-incompatible-sysroot -isysroot SDKs/MacOSX10.9.sdk -mios-version-min=9.0 -S -o - %s 2>&1 | FileCheck -check-prefix CHECK-OSX-IOS-DISABLED %s
+
+int main() { return 0; }
+// CHECK-OSX-IOS: warning: using sysroot for 'MacOSX' but targeting 'iPhone'
+// CHECK-IOS-WATCHOS: warning: using sysroot for 'iPhoneOS' but targeting 'Watch'
+// CHECK-IOS-TVOS: warning: using sysroot for 'iPhoneOS' but targeting 'AppleTV'
+// CHECK-IOS-IOSSIM-NOT: warning: using sysroot for '{{.*}}' but targeting '{{.*}}'
+// CHECK-OSX-IOS-DISABLED-NOT: warning: using sysroot for '{{.*}}' but targeting '{{.*}}'
Index: cfe/trunk/lib/Driver/ToolChains.h
===
--- cfe/trunk/lib/Driver/ToolChains.h
+++ cfe/trunk/lib/Driver/ToolChains.h
@@ -496,6 +496,8 @@
 return TargetVersion < VersionTuple(V0, V1, V2);
   }
 
+  StringRef getPlatformFamily() const;
+  static StringRef getSDKName(StringRef isysroot);
   StringRef getOSLibraryNameSuffix() const;
 
 public:
Index: cfe/trunk/lib/Driver/ToolChains.cpp
===
--- cfe/trunk/lib/Driver/ToolChains.cpp
+++ cfe/trunk/lib/Driver/ToolChains.cpp
@@ -329,6 +329,36 @@
   }
 }
 
+StringRef Darwin::getPlatformFamily() const {
+  switch (TargetPlatform) {
+case DarwinPlatformKind::MacOS:
+  return "MacOSX";
+case DarwinPlatformKind::IPhoneOS:
+case DarwinPlatformKind::IPhoneOSSimulator:
+  return "iPhone";
+case DarwinPlatformKind::TvOS:
+case DarwinPlatformKind::TvOSSimulator:
+  return "AppleTV";
+case DarwinPlatformKind::WatchOS:
+case DarwinPlatformKind::WatchOSSimulator:
+  return "Watch";
+  }
+  llvm_unreachable("Unsupported platform");
+}
+
+StringRef Darwin::getSDKName(StringRef isysroot) {
+  // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk
+  llvm::sys::path::const_iterator SDKDir;
+  auto BeginSDK = llvm::sys::path::begin(isysroot);
+  auto EndSDK = llvm::sys::path::end(isysroot);
+  for (auto IT = BeginSDK; IT != EndSDK; ++IT) {
+StringRef SDK = *IT;
+if (SDK.endswith(".sdk"))
+  return SDK.slice(0, SDK.size() - 4);
+  }
+  return "";
+}
+
 StringRef Darwin::getOSLibraryNameSuffix() const {
   switch(TargetPlatform) {
   case DarwinPlatformKind::MacOS:
@@ -540,11 +570,8 @@
 TvOSTarget.empty() && Args.hasArg(options::OPT_isysroot)) {
   if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
 StringRef isysroot = A->getValue();
-// Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk
-size_t BeginSDK = isysroot.rfind("SDKs/");
-size_t EndSDK = isysroot.rfind(".sdk");
-if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) {
-  StringRef SDK = isysroot.slice(BeginSDK 

Re: [PATCH] D19524: [OpenCL] Fix pipe type dump.

2016-05-02 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268364: [OpenCL] Fix pipe type dump. (authored by pxl).

Changed prior to commit:
  http://reviews.llvm.org/D19524?vs=55161=55946#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19524

Files:
  cfe/trunk/lib/AST/ASTDumper.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/test/Misc/ast-dump-pipe.cl
  cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
  cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl

Index: cfe/trunk/lib/AST/ASTDumper.cpp
===
--- cfe/trunk/lib/AST/ASTDumper.cpp
+++ cfe/trunk/lib/AST/ASTDumper.cpp
@@ -404,6 +404,9 @@
 void VisitAtomicType(const AtomicType *T) {
   dumpTypeAsChild(T->getValueType());
 }
+void VisitPipeType(const PipeType *T) {
+  dumpTypeAsChild(T->getElementType());
+}
 void VisitAdjustedType(const AdjustedType *T) {
   dumpTypeAsChild(T->getOriginalType());
 }
Index: cfe/trunk/lib/AST/TypePrinter.cpp
===
--- cfe/trunk/lib/AST/TypePrinter.cpp
+++ cfe/trunk/lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream ) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: cfe/trunk/test/Misc/ast-dump-pipe.cl
===
--- cfe/trunk/test/Misc/ast-dump-pipe.cl
+++ cfe/trunk/test/Misc/ast-dump-pipe.cl
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter 
pipetype %s | FileCheck -strict-whitespace %s
+typedef pipe int pipetype;
+// CHECK:  PipeType {{.*}} 'pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
Index: cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
===
--- cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
+++ cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
@@ -8,7 +8,7 @@
 void test3(read_only read_only image1d_t i){} // expected-error{{multiple 
access qualifiers}}
 
 #ifdef CL20
-void test4(read_write pipe int i){} // expected-error{{access qualifier 
'read_write' can not be used for 'pipe'}}
+void test4(read_write pipe int i){} // expected-error{{access qualifier 
'read_write' can not be used for 'pipe int'}}
 #else
 void test4(__read_write image1d_t i) {} // expected-error{{access qualifier 
'__read_write' can not be used for '__read_write image1d_t' earlier than 
OpenCL2.0 version}}
 #endif
Index: cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -7,5 +7,5 @@
 void test3(int pipe p){// expected-error {{cannot combine with previous 'int' 
declaration specifier}}
 }
 void test4() {
-  pipe int p; // expected-error {{type 'pipe' can only be used as a function 
parameter}}
+  pipe int p; // expected-error {{type 'pipe int' can only be used as a 
function parameter}}
 }


Index: cfe/trunk/lib/AST/ASTDumper.cpp
===
--- cfe/trunk/lib/AST/ASTDumper.cpp
+++ cfe/trunk/lib/AST/ASTDumper.cpp
@@ -404,6 +404,9 @@
 void VisitAtomicType(const AtomicType *T) {
   dumpTypeAsChild(T->getValueType());
 }
+void VisitPipeType(const PipeType *T) {
+  dumpTypeAsChild(T->getElementType());
+}
 void VisitAdjustedType(const AdjustedType *T) {
   dumpTypeAsChild(T->getOriginalType());
 }
Index: cfe/trunk/lib/AST/TypePrinter.cpp
===
--- cfe/trunk/lib/AST/TypePrinter.cpp
+++ cfe/trunk/lib/AST/TypePrinter.cpp
@@ -895,7 +895,8 @@
 void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream ) {
   IncludeStrongLifetimeRAII Strong(Policy);
 
-  OS << "pipe";
+  OS << "pipe ";
+  print(T->getElementType(), OS, StringRef());
   spaceBeforePlaceHolder(OS);
 }
 
Index: cfe/trunk/test/Misc/ast-dump-pipe.cl
===
--- cfe/trunk/test/Misc/ast-dump-pipe.cl
+++ cfe/trunk/test/Misc/ast-dump-pipe.cl
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter pipetype %s | FileCheck -strict-whitespace %s
+typedef pipe int pipetype;
+// CHECK:  PipeType {{.*}} 'pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
Index: cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
===
--- cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
+++ cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl
@@ -8,7 +8,7 @@
 void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
 
 

Re: [PATCH] D19458: Add address space 258 to Clang documentation

2016-05-03 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268432: Add address space 258 (X86 SS segment) to clang 
documentation. (authored by dlkreitz).

Changed prior to commit:
  http://reviews.llvm.org/D19458?vs=54877=56056#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19458

Files:
  cfe/trunk/docs/LanguageExtensions.rst

Index: cfe/trunk/docs/LanguageExtensions.rst
===
--- cfe/trunk/docs/LanguageExtensions.rst
+++ cfe/trunk/docs/LanguageExtensions.rst
@@ -1912,12 +1912,13 @@
 
 The X86 backend has these language extensions:
 
-Memory references off the GS segment
-
+Memory references to specified segments
+^^^
 
 Annotating a pointer with address space #256 causes it to be code generated
-relative to the X86 GS segment register, and address space #257 causes it to be
-relative to the X86 FS segment.  Note that this is a very very low-level
+relative to the X86 GS segment register, address space #257 causes it to be
+relative to the X86 FS segment, and address space #258 causes it to be
+relative to the X86 SS segment.  Note that this is a very very low-level
 feature that should only be used if you know what you're doing (for example in
 an OS kernel).
 


Index: cfe/trunk/docs/LanguageExtensions.rst
===
--- cfe/trunk/docs/LanguageExtensions.rst
+++ cfe/trunk/docs/LanguageExtensions.rst
@@ -1912,12 +1912,13 @@
 
 The X86 backend has these language extensions:
 
-Memory references off the GS segment
-
+Memory references to specified segments
+^^^
 
 Annotating a pointer with address space #256 causes it to be code generated
-relative to the X86 GS segment register, and address space #257 causes it to be
-relative to the X86 FS segment.  Note that this is a very very low-level
+relative to the X86 GS segment register, address space #257 causes it to be
+relative to the X86 FS segment, and address space #258 causes it to be
+relative to the X86 SS segment.  Note that this is a very very low-level
 feature that should only be used if you know what you're doing (for example in
 an OS kernel).
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19952: AMDGPU: Use lld as the linker again

2016-05-05 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268648: AMDGPU: Use lld as the linker again (authored by 
tstellar).

Changed prior to commit:
  http://reviews.llvm.org/D19952?vs=56231=56307#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19952

Files:
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Driver/Tools.h
  cfe/trunk/test/Driver/amdgpu-toolchain.c

Index: cfe/trunk/lib/Driver/Tools.h
===
--- cfe/trunk/lib/Driver/Tools.h
+++ cfe/trunk/lib/Driver/Tools.h
@@ -242,7 +242,7 @@
 
 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
 public:
-  Linker(const ToolChain ) : GnuTool("amdgpu::Linker", "amdphdrs", TC) {}
+  Linker(const ToolChain ) : GnuTool("amdgpu::Linker", "ld.lld", TC) {}
   bool isLinkJob() const override { return true; }
   bool hasIntegratedCPP() const override { return false; }
   void ConstructJob(Compilation , const JobAction ,
Index: cfe/trunk/lib/Driver/Tools.cpp
===
--- cfe/trunk/lib/Driver/Tools.cpp
+++ cfe/trunk/lib/Driver/Tools.cpp
@@ -6786,6 +6786,8 @@
   std::string Linker = getToolChain().GetProgramPath(getShortName());
   ArgStringList CmdArgs;
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
+  CmdArgs.push_back("-shared");
+  CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
   C.addCommand(llvm::make_unique(JA, *this, 
Args.MakeArgString(Linker),
   CmdArgs, Inputs));
Index: cfe/trunk/test/Driver/amdgpu-toolchain.c
===
--- cfe/trunk/test/Driver/amdgpu-toolchain.c
+++ cfe/trunk/test/Driver/amdgpu-toolchain.c
@@ -1,3 +1,3 @@
 // RUN: %clang -### -target amdgcn--amdhsa -x assembler -mcpu=kaveri %s 2>&1 | 
FileCheck -check-prefix=AS_LINK %s
 // AS_LINK: clang{{.*}} "-cc1as"
-// AS_LINK: amdphdrs{{.*}}
+// AS_LINK: ld.lld{{.*}} "-shared"


Index: cfe/trunk/lib/Driver/Tools.h
===
--- cfe/trunk/lib/Driver/Tools.h
+++ cfe/trunk/lib/Driver/Tools.h
@@ -242,7 +242,7 @@
 
 class LLVM_LIBRARY_VISIBILITY Linker : public GnuTool {
 public:
-  Linker(const ToolChain ) : GnuTool("amdgpu::Linker", "amdphdrs", TC) {}
+  Linker(const ToolChain ) : GnuTool("amdgpu::Linker", "ld.lld", TC) {}
   bool isLinkJob() const override { return true; }
   bool hasIntegratedCPP() const override { return false; }
   void ConstructJob(Compilation , const JobAction ,
Index: cfe/trunk/lib/Driver/Tools.cpp
===
--- cfe/trunk/lib/Driver/Tools.cpp
+++ cfe/trunk/lib/Driver/Tools.cpp
@@ -6786,6 +6786,8 @@
   std::string Linker = getToolChain().GetProgramPath(getShortName());
   ArgStringList CmdArgs;
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
+  CmdArgs.push_back("-shared");
+  CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
   C.addCommand(llvm::make_unique(JA, *this, Args.MakeArgString(Linker),
   CmdArgs, Inputs));
Index: cfe/trunk/test/Driver/amdgpu-toolchain.c
===
--- cfe/trunk/test/Driver/amdgpu-toolchain.c
+++ cfe/trunk/test/Driver/amdgpu-toolchain.c
@@ -1,3 +1,3 @@
 // RUN: %clang -### -target amdgcn--amdhsa -x assembler -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=AS_LINK %s
 // AS_LINK: clang{{.*}} "-cc1as"
-// AS_LINK: amdphdrs{{.*}}
+// AS_LINK: ld.lld{{.*}} "-shared"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-05-02 Thread Krystyna via cfe-commits
krystyna marked 8 inline comments as done.
krystyna added a comment.

Repository:
  rL LLVM

http://reviews.llvm.org/D18919



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-05-02 Thread Krystyna via cfe-commits
krystyna added a comment.

hide done comments


Repository:
  rL LLVM

http://reviews.llvm.org/D18919



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-05-02 Thread Krystyna via cfe-commits
krystyna updated this revision to Diff 55867.

Repository:
  rL LLVM

http://reviews.llvm.org/D18919

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseUsingCheck.cpp
  clang-tidy/modernize/UseUsingCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-using.rst
  test/clang-tidy/modernize-use-using.cpp

Index: test/clang-tidy/modernize-use-using.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-using.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t
+
+typedef int Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Type = int;
+
+typedef long LL;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using LL = long;
+
+typedef int Bla;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using Bla = int;
+
+typedef Bla Bla2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using Bla2 = Bla;
+
+typedef void (*type)(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using type = void (*)(int);
+
+typedef void (*type2)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using type2 = void (*)();
+
+class Class {
+typedef long long Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef
+	// CHECK-FIXES: using Type = long long;
+};
+
+typedef void (Class::* MyPtrType)(Bla) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using MyPtrType = void (Class::*)(Bla) const;
+
+class Iterable {
+public:
+	class Iterator {};
+};
+
+template
+class Test {
+typedef typename T::iterator Iter;
+	// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef
+	// CHECK-FIXES: using Iter = typename T::iterator;
+};
+
+using balba = long long;
+
+union A {};
+
+typedef void (A::*PtrType)(int, int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using PtrType = void (A::*)(int, int) const;
+
+typedef Class some_class;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using some_class = Class;
+
+typedef Class Cclass;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using Cclass = Class;
+
+typedef Cclass cclass2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using cclass2 = Cclass;
+
+class cclass {};
+
+typedef void (cclass::* MyPtrType3)(Bla);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla);
+
+using my_class = int;
+
+typedef Test another;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef
+// CHECK-FIXES: using another = Test;
Index: docs/clang-tidy/checks/modernize-use-using.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-using.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - modernize-use-using
+
+modernize-use-using
+===
+
+Use C++11's ``using`` instead of ``typedef``.
+
+Before:
+
+.. code:: c++
+
+  typedef int variable;
+
+  class Class{};
+  typedef void (Class::* MyPtrType)() const;
+
+After:
+
+.. code:: c++
+
+  using varible = int;
+
+  class Class{};
+  using MyPtrType = void (Class::*)() const;
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -96,6 +96,7 @@
modernize-use-default
modernize-use-nullptr
modernize-use-override
+   modernize-use-using
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
Index: clang-tidy/modernize/UseUsingCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseUsingCheck.h
@@ -0,0 +1,35 @@
+//===--- UseUsingCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_USING_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_USING_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// Check finds typedefs and replaces it with usings.
+///
+/// For the user-facing documentation see:
+/// 

Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-05-02 Thread Krystyna via cfe-commits
krystyna marked 4 inline comments as done.
krystyna added a comment.

Repository:
  rL LLVM

http://reviews.llvm.org/D18919



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19947: [Clang] Fix some Clang-tidy readability-simplify-boolean-expr and Include What You Use warnings

2016-05-05 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268674: Fix some Clang-tidy 
readability-simplify-boolean-expr and Include What You… (authored by 
eugenezelenko).

Changed prior to commit:
  http://reviews.llvm.org/D19947?vs=56226=56337#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19947

Files:
  cfe/trunk/include/clang/Lex/Token.h
  cfe/trunk/include/clang/Sema/ParsedTemplate.h

Index: cfe/trunk/include/clang/Lex/Token.h
===
--- cfe/trunk/include/clang/Lex/Token.h
+++ cfe/trunk/include/clang/Lex/Token.h
@@ -14,12 +14,10 @@
 #ifndef LLVM_CLANG_LEX_TOKEN_H
 #define LLVM_CLANG_LEX_TOKEN_H
 
-#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/TemplateKinds.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/StringRef.h"
-#include 
+#include 
 
 namespace clang {
 
@@ -69,8 +67,8 @@
 
   /// Flags - Bits we track about this token, members of the TokenFlags enum.
   unsigned short Flags;
-public:
 
+public:
   // Various flags set per token:
   enum TokenFlags {
 StartOfLine   = 0x01,  // At start of line or only after whitespace
@@ -236,6 +234,11 @@
 Flags |= Flag;
   }
 
+  /// \brief Get the specified flag.
+  bool getFlag(TokenFlags Flag) const {
+return (Flags & Flag) != 0;
+  }
+
   /// \brief Unset the specified flag.
   void clearFlag(TokenFlags Flag) {
 Flags &= ~Flag;
@@ -259,50 +262,42 @@
 
   /// isAtStartOfLine - Return true if this token is at the start of a line.
   ///
-  bool isAtStartOfLine() const { return (Flags & StartOfLine) ? true : false; }
+  bool isAtStartOfLine() const { return getFlag(StartOfLine); }
 
   /// \brief Return true if this token has whitespace before it.
   ///
-  bool hasLeadingSpace() const { return (Flags & LeadingSpace) ? true : false; }
+  bool hasLeadingSpace() const { return getFlag(LeadingSpace); }
 
   /// \brief Return true if this identifier token should never
   /// be expanded in the future, due to C99 6.10.3.4p2.
-  bool isExpandDisabled() const {
-return (Flags & DisableExpand) ? true : false;
-  }
+  bool isExpandDisabled() const { return getFlag(DisableExpand); }
 
   /// \brief Return true if we have an ObjC keyword identifier.
   bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const;
 
   /// \brief Return the ObjC keyword kind.
   tok::ObjCKeywordKind getObjCKeywordID() const;
 
   /// \brief Return true if this token has trigraphs or escaped newlines in it.
-  bool needsCleaning() const { return (Flags & NeedsCleaning) ? true : false; }
+  bool needsCleaning() const { return getFlag(NeedsCleaning); }
 
   /// \brief Return true if this token has an empty macro before it.
   ///
-  bool hasLeadingEmptyMacro() const {
-return (Flags & LeadingEmptyMacro) ? true : false;
-  }
+  bool hasLeadingEmptyMacro() const { return getFlag(LeadingEmptyMacro); }
 
   /// \brief Return true if this token is a string or character literal which
   /// has a ud-suffix.
-  bool hasUDSuffix() const { return (Flags & HasUDSuffix) ? true : false; }
+  bool hasUDSuffix() const { return getFlag(HasUDSuffix); }
 
   /// Returns true if this token contains a universal character name.
-  bool hasUCN() const { return (Flags & HasUCN) ? true : false; }
+  bool hasUCN() const { return getFlag(HasUCN); }
 
   /// Returns true if this token is formed by macro by stringizing or charizing
   /// operator.
-  bool stringifiedInMacro() const {
-return (Flags & StringifiedInMacro) ? true : false;
-  }
+  bool stringifiedInMacro() const { return getFlag(StringifiedInMacro); }
 
   /// Returns true if the comma after this token was elided.
-  bool commaAfterElided() const {
-return (Flags & CommaAfterElided) ? true : false;
-  }
+  bool commaAfterElided() const { return getFlag(CommaAfterElided); }
 };
 
 /// \brief Information about the conditional stack (\#if directives)
@@ -324,11 +319,11 @@
   bool FoundElse;
 };
 
-}  // end namespace clang
+} // end namespace clang
 
 namespace llvm {
   template <>
   struct isPodLike { static const bool value = true; };
-}  // end namespace llvm
+} // end namespace llvm
 
-#endif
+#endif // LLVM_CLANG_LEX_TOKEN_H
Index: cfe/trunk/include/clang/Sema/ParsedTemplate.h
===
--- cfe/trunk/include/clang/Sema/ParsedTemplate.h
+++ cfe/trunk/include/clang/Sema/ParsedTemplate.h
@@ -1,4 +1,4 @@
-//===--- ParsedTemplate.h - Template Parsing Data Types ---===//
+//===--- ParsedTemplate.h - Template Parsing Data Types -*- C++ -*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -11,12 +11,19 @@
 //  templates.
 //
 //===--===//
+
 #ifndef LLVM_CLANG_SEMA_PARSEDTEMPLATE_H
 #define LLVM_CLANG_SEMA_PARSEDTEMPLATE_H
 
+#include "clang/Basic/OperatorKinds.h"
+#include 

Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-04 Thread andreybokhanko via cfe-commits
What Reid said...

Yours,
Andrey

> 5 мая 2016 г., в 1:48, Reid Kleckner  написал(а):
> 
> rnk added inline comments.
> 
> 
> Comment at: lib/AST/MicrosoftMangle.cpp:1583-1584
> @@ -1579,2 +1582,4 @@
>   case QMM_Result:
> +// Presence of __unaligned qualifier shouldn't affect mangling here.
> +Quals.removeUnaligned();
> if ((!IsPointer && Quals) || isa(T)) {
> 
> majnemer wrote:
>> andreybokhanko wrote:
>>> majnemer wrote:
 andreybokhanko wrote:
> Done. Test added.
 Hmm, can you give a concrete example why we need this line?
>>> Sure. An example is:
>>> 
>>> __unaligned int unaligned_foo3() { return 0; }
>>> 
>>> MS mangles it as
>>> 
>>> ?unaligned_foo3@@YAHXZ
>>> 
>>> However, if __unaligned is taken into account, "if ((!IsPointer && Quals) 
>>> || isa(T))" computes to true and clang adds "?A", resulting to
>>> 
>>> ?unaligned_foo3@@YA?AHXZ
>>> 
>>> Yours,
>>> Andrey
>> Wait, I thought __unaligned can only apply to pointer types.  Is this not 
>> so?!
>> Does `__unaligned int x;` really keep it's `__unaligned` qualifier?
> Yeah it does:
>  $ cat t.cpp
>  __unaligned int x;
>  $ cl -nologo -c t.cpp && dumpbin /symbols t.obj  | grep ?x
>  t.cpp
>  008  SECT3  notype   External | ?x@@3HFA (int __unaligned x)
> 
> 
> http://reviews.llvm.org/D19654
> 
> 
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19654: PR27132: Proper mangling for __unaligned qualifier (now with PR27367 fixed)

2016-05-06 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268727: [MSVC] Implementation of __unaligned as a proper 
type qualifier (authored by asbokhan).

Changed prior to commit:
  http://reviews.llvm.org/D19654?vs=55588=56401#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19654

Files:
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Basic/AddressSpaces.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Sema/DeclSpec.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/AST/MicrosoftMangle.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseTentative.cpp
  cfe/trunk/lib/Sema/DeclSpec.cpp
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclObjC.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp
  cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp
  cfe/trunk/test/Sema/MicrosoftExtensions.c
  cfe/trunk/test/Sema/address_spaces.c
  cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c
  cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp

Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -152,8 +152,8 @@
 
   enum {
 /// The maximum supported address space number.
-/// 24 bits should be enough for anyone.
-MaxAddressSpace = 0xffu,
+/// 23 bits should be enough for anyone.
+MaxAddressSpace = 0x7fu,
 
 /// The width of the "fast" qualifier mask.
 FastWidth = 3,
@@ -265,6 +265,13 @@
 Mask |= mask;
   }
 
+  bool hasUnaligned() const { return Mask & UMask; }
+  void setUnaligned(bool flag) {
+Mask = (Mask & ~UMask) | (flag ? UMask : 0);
+  }
+  void removeUnaligned() { Mask &= ~UMask; }
+  void addUnaligned() { Mask |= UMask; }
+
   bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
   GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
   void setObjCGCAttr(GC type) {
@@ -433,7 +440,9 @@
// ObjC lifetime qualifiers must match exactly.
getObjCLifetime() == other.getObjCLifetime() &&
// CVR qualifiers may subset.
-   (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
+   (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
+   // U qualifier may superset.
+   (!(other.Mask & UMask) || (Mask & UMask));
   }
 
   /// \brief Determines if these qualifiers compatibly include another set of
@@ -501,16 +510,19 @@
 
 private:
 
-  // bits: |0 1 2|3 .. 4|5  ..  7|8   ...   31|
-  //   |C R V|GCAttr|Lifetime|AddressSpace|
+  // bits: |0 1 2|3|4 .. 5|6  ..  8|9   ...   31|
+  //   |C R V|U|GCAttr|Lifetime|AddressSpace|
   uint32_t Mask;
 
-  static const uint32_t GCAttrMask = 0x18;
-  static const uint32_t GCAttrShift = 3;
-  static const uint32_t LifetimeMask = 0xE0;
-  static const uint32_t LifetimeShift = 5;
-  static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask);
-  static const uint32_t AddressSpaceShift = 8;
+  static const uint32_t UMask = 0x8;
+  static const uint32_t UShift = 3;
+  static const uint32_t GCAttrMask = 0x30;
+  static const uint32_t GCAttrShift = 4;
+  static const uint32_t LifetimeMask = 0x1C0;
+  static const uint32_t LifetimeShift = 6;
+  static const uint32_t AddressSpaceMask =
+  ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
+  static const uint32_t AddressSpaceShift = 9;
 };
 
 /// A std::pair-like structure for storing a qualified type split
@@ -5377,7 +5389,13 @@
 /// int" is at least as qualified as "const int", "volatile int",
 /// "int", and "const volatile int".
 inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
-  return getQualifiers().compatiblyIncludes(other.getQualifiers());
+  Qualifiers otherQuals = other.getQualifiers();
+
+  // Ignore __unaligned qualifier if this type is a void.
+  if (getUnqualifiedType()->isVoidType())
+otherQuals.removeUnaligned();
+
+  return getQualifiers().compatiblyIncludes(otherQuals);
 }
 
 /// If Type is a reference type (e.g., const
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1675,7 +1675,8 @@
 SourceLocation ConstQualLoc = SourceLocation(),
 SourceLocation VolatileQualLoc = SourceLocation(),
 SourceLocation RestrictQualLoc = SourceLocation(),
-SourceLocation AtomicQualLoc = SourceLocation());
+SourceLocation AtomicQualLoc = SourceLocation(),
+SourceLocation 

[PATCH] D20089: Adding a TargetParser for AArch64

2016-05-10 Thread jojo.ma via cfe-commits
jojo created this revision.
jojo added reviewers: bsmith, jmolloy, rengolin.
jojo added subscribers: llvm-commits, cfe-commits.
jojo set the repository for this revision to rL LLVM.
jojo changed the visibility of this Differential Revision from "Public (No 
Login Required)" to "All Users".
Herald added subscribers: rengolin, aemerson.

Adding a TargetParser for AArch64

Repository:
  rL LLVM

http://reviews.llvm.org/D20089

Files:
  include/llvm/Support/ARMTargetParser.def
  include/llvm/Support/TargetParser.h
  lib/Support/TargetParser.cpp

Index: lib/Support/TargetParser.cpp
===
--- lib/Support/TargetParser.cpp
+++ lib/Support/TargetParser.cpp
@@ -21,6 +21,7 @@
 
 using namespace llvm;
 using namespace ARM;
+using namespace AArch64;
 
 namespace {
 
@@ -75,6 +76,11 @@
   {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH,   \
sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR},
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64ARCHNames[] = {
+#define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT)   \
+  {NAME, sizeof(NAME) - 1, CPU_ATTR, sizeof(CPU_ATTR) - 1, SUB_ARCH,   \
+   sizeof(SUB_ARCH) - 1, ARCH_FPU, ARCH_BASE_EXT, ID, ARCH_ATTR},
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 // List of Arch Extension names.
@@ -91,6 +97,10 @@
 #define ARM_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
   { NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE },
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64ARCHExtNames[] = {
+#define AARCH64_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE) \
+  { NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE },
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 // List of HWDiv names (use getHWDivSynonym) and which architectural
@@ -124,6 +134,10 @@
 #define ARM_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
   { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT },
 #include "llvm/Support/ARMTargetParser.def"
+},AArch64CPUNames[] = {
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+  { NAME, sizeof(NAME) - 1, ID, IS_DEFAULT, DEFAULT_EXT },
+#include "llvm/Support/AArch64TargetParser.def"
 };
 
 } // namespace
@@ -369,6 +383,134 @@
   return "generic";
 }
 
+StringRef llvm::AArch64::getFPUName(unsigned FPUKind) {
+  return ARM::getFPUName(FPUKind);
+}
+
+unsigned llvm::AArch64::getFPUVersion(unsigned FPUKind) {
+  return ARM::getFPUVersion(FPUKind);
+}
+
+unsigned llvm::AArch64::getFPUNeonSupportLevel(unsigned FPUKind) {
+  return ARM::getFPUNeonSupportLevel( FPUKind);
+}
+
+unsigned llvm::AArch64::getFPURestriction(unsigned FPUKind) {
+  return ARM::getFPURestriction(FPUKind);
+}
+
+unsigned llvm::AArch64::getDefaultFPU(StringRef CPU, unsigned ArchKind) {
+  if (CPU == "generic")
+return AArch64ARCHNames[ArchKind].DefaultFPU;
+
+  return StringSwitch(CPU)
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+.Case(NAME, DEFAULT_FPU)
+#include "llvm/Support/AArch64TargetParser.def"
+.Default(ARM::FK_INVALID);
+}
+
+unsigned llvm::AArch64::getDefaultExtensions(StringRef CPU, unsigned ArchKind) {
+  if (CPU == "generic")
+return AArch64ARCHNames[ArchKind].ArchBaseExtensions;
+
+  return StringSwitch(CPU)
+#define AARCH64_CPU_NAME(NAME, ID, DEFAULT_FPU, IS_DEFAULT, DEFAULT_EXT) \
+.Case(NAME, AArch64ARCHNames[ID].ArchBaseExtensions | DEFAULT_EXT)
+#include "llvm/Support/AArch64TargetParser.def"
+.Default(AArch64::AEK_INVALID);
+}
+
+bool llvm::AArch64::getExtensionFeatures(unsigned Extensions,
+ std::vector ) {
+
+  if (Extensions == AArch64::AEK_INVALID)
+return false;
+
+  if (Extensions & AArch64::AEK_FP)
+Features.push_back("+fp-armv8");
+  if (Extensions & AArch64::AEK_SIMD)
+Features.push_back("+neon");
+  if (Extensions & AArch64::AEK_CRC)
+Features.push_back("+crc");
+  if (Extensions & AArch64::AEK_CRYPTO)
+Features.push_back("+crypto");
+  if (Extensions & AArch64::AEK_FP16)
+Features.push_back("+fullfp16");
+  if (Extensions & AArch64::AEK_PROFILE)
+Features.push_back("+spe");
+
+  return true;
+}
+
+bool llvm::AArch64::getFPUFeatures(unsigned FPUKind,
+   std::vector ) {
+  return ARM::getFPUFeatures(FPUKind, Features);
+}
+
+StringRef llvm::AArch64::getArchName(unsigned ArchKind) {
+  if (ArchKind >= ARM::AK_LAST)
+return StringRef();
+  return AArch64ARCHNames[ArchKind].getName();
+}
+
+StringRef llvm::AArch64::getCPUAttr(unsigned ArchKind) {
+  if (ArchKind == ARM::AK_INVALID || ArchKind >= ARM::AK_LAST)
+return StringRef();
+  return AArch64ARCHNames[ArchKind].getCPUAttr();
+}
+
+StringRef llvm::AArch64::getSubArch(unsigned ArchKind) {
+  if (ArchKind == ARM::AK_INVALID || ArchKind >= ARM::AK_LAST)
+return StringRef();
+  return AArch64ARCHNames[ArchKind].getSubArch();
+}
+
+unsigned llvm::AArch64::getArchAttr(unsigned 

Re: [PATCH] D20100: [NFC] Header cleanup

2016-05-10 Thread Eugene via cfe-commits
kevgs added a comment.

Sadly, I dont know such a tool. I was using a simple script to find unused 
headers ack --cpp -l 'SmallString\.h"' | xargs grep -L 'SmallString[ (

Re: [PATCH] D18567: Block: Fix a crash when we have type attributes or qualifiers with omitted return type.

2016-04-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266648: Block: Fix a crash when we have type attributes or 
qualifiers with omitted (authored by mren).

Changed prior to commit:
  http://reviews.llvm.org/D18567?vs=52398=54090#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18567

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/SemaObjC/block-omitted-return-type.m
  cfe/trunk/test/SemaOpenCL/invalid-block.cl

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8437,4 +8437,12 @@
   "parameterized class %0 already conforms to the protocols listed; did you "
   "forget a '*'?">, InGroup;
 
+def warn_block_literal_attributes_on_omitted_return_type : Warning<
+  "attribute %0 ignored, because it cannot be applied to omitted return type">,
+  InGroup;
+
+def warn_block_literal_qualifiers_on_omitted_return_type : Warning<
+  "'%0' qualifier on omitted return type %1 has no effect">,
+  InGroup;
+
 } // end of sema component.
Index: cfe/trunk/test/SemaOpenCL/invalid-block.cl
===
--- cfe/trunk/test/SemaOpenCL/invalid-block.cl
+++ cfe/trunk/test/SemaOpenCL/invalid-block.cl
@@ -4,16 +4,15 @@
 
 // All blocks declarations must be const qualified and initialized.
 void f1() {
-  int (^bl1)() = ^() {}; // expected-error{{invalid block variable declaration - must be const qualified}}
+  int (^bl1)() = ^() {return 1;}; // expected-error{{invalid block variable declaration - must be const qualified}}
   int (^const bl2)(); // expected-error{{invalid block variable declaration - must be initialized}}
-  int (^const bl3)() = ^const(){
-  };
+  int (^const bl3)() = ^(){return 1;};
 }
 
 // A block with extern storage class is not allowed.
-extern int (^const bl)() = ^const(){}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
+extern int (^const bl)() = ^(){return 1;}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
 void f2() {
-  extern int (^const bl)() = ^const(){}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
+  extern int (^const bl)() = ^(){return 1;}; // expected-error{{invalid block variable declaration - using 'extern' storage class is disallowed}}
 }
 
 // A block cannot be the return value of a function.
@@ -29,22 +28,22 @@
 }
 
 // A block with variadic argument is not allowed.
-int (^const bl)(int, ...) = ^const int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
+int (^const bl)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed in OpenCL}}
   return 0;
 };
 
 // A block can't be used to declare an array
 typedef int (^const bl1_t)(int);
 void f5(int i) {
-  bl1_t bl1 = ^const(int i) {return 1;};
-  bl1_t bl2 = ^const(int i) {return 2;};
+  bl1_t bl1 = ^(int i) {return 1;};
+  bl1_t bl2 = ^(int i) {return 2;};
   bl1_t arr[] = {bl1, bl2}; // expected-error {{array of 'bl1_t' (aka 'int (^const)(int)') type is invalid in OpenCL}}
   int tmp = i ? bl1(i)  // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
   : bl2(i); // expected-error {{block type cannot be used as expression in ternary expression in OpenCL}}
 }
 
 void f6(bl1_t * bl_ptr) {
-  bl1_t bl = ^const(int i) {return 1;};
+  bl1_t bl = ^(int i) {return 1;};
   bl1_t *p =  // expected-error {{invalid argument type 'bl1_t' (aka 'int (^const)(int)') to unary expression}}
   bl = *bl_ptr;  // expected-error {{dereferencing pointer of type '__generic bl1_t *' (aka 'int (^const __generic *)(int)') is not allowed in OpenCL}}
 }
Index: cfe/trunk/test/SemaObjC/block-omitted-return-type.m
===
--- cfe/trunk/test/SemaObjC/block-omitted-return-type.m
+++ cfe/trunk/test/SemaObjC/block-omitted-return-type.m
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 %s -fblocks -verify -fsyntax-only
+
+@interface NSObject
+@end
+
+@interface Test : NSObject
+- (void)test;
+@end
+
+@implementation Test
+- (void)test
+{
+  void (^simpleBlock)() = ^ _Nonnull { //expected-warning {{attribute '_Nonnull' ignored, because it cannot be applied to omitted return type}}
+return;
+  };
+  void (^simpleBlock2)() = ^ _Nonnull void { //expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'void'}}
+return;
+  };
+  void (^simpleBlock3)() = ^ _Nonnull (void) {  //expected-warning {{attribute '_Nonnull' ignored, because it cannot be applied to omitted return type}}
+return;
+  };
+
+  void 

Re: [PATCH] D19262: [clang-tidy] readability-container-size-empty fixes

2016-04-19 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266734: [clang-tidy] readability-container-size-empty fixes 
(authored by xazax).

Changed prior to commit:
  http://reviews.llvm.org/D19262?vs=54182=54187#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19262

Files:
  clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp

Index: 
clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
@@ -7,6 +7,15 @@
   bool empty() const;
 };
 
+template  struct basic_string {
+  basic_string();
+  unsigned long size() const;
+  bool empty() const;
+};
+
+typedef basic_string string;
+typedef basic_string wstring;
+
 inline namespace __v2 {
 template  struct set {
   set();
@@ -20,10 +29,24 @@
 
 int main() {
   std::set intSet;
+  std::string str;
+  std::wstring wstr;
+  str.size() + 0;
+  str.size() - 0;
+  0 + str.size();
+  0 - str.size();
   if (intSet.size() == 0)
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be 
used to check for emptiness instead of 'size' [readability-container-size-empty]
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
+  if (str.size() == 0)
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+  // CHECK-FIXES: {{^  }}if (str.empty()){{$}}
+  if (wstr.size() == 0)
+;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
+  // CHECK-FIXES: {{^  }}if (wstr.empty()){{$}}
   std::vector vect;
   if (vect.size() == 0)
 ;
Index: 
clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -16,6 +16,7 @@
 
 static bool isContainerName(llvm::StringRef ClassName) {
   static const char *const ContainerNames[] = {"array",
+   "basic_string",
"deque",
"forward_list",
"list",
@@ -59,14 +60,13 @@
 return;
 
   const auto WrongUse = anyOf(
-  hasParent(
-  binaryOperator(
-  anyOf(has(integerLiteral(equals(0))),
-allOf(anyOf(hasOperatorName("<"), hasOperatorName(">="),
-hasOperatorName(">"), hasOperatorName("<=")),
-  hasEitherOperand(
-  ignoringImpCasts(integerLiteral(equals(1)))
-  .bind("SizeBinaryOp")),
+  hasParent(binaryOperator(
+anyOf(hasOperatorName("<"), hasOperatorName(">="),
+  hasOperatorName(">"), hasOperatorName("<="),
+  hasOperatorName("=="), hasOperatorName("!=")),
+hasEitherOperand(ignoringImpCasts(anyOf(
+integerLiteral(equals(1)), 
integerLiteral(equals(0))
+.bind("SizeBinaryOp")),
   hasParent(implicitCastExpr(
   hasImplicitDestinationType(booleanType()),
   anyOf(
@@ -122,6 +122,10 @@
 if (Value > 1)
   return;
 
+if (Value == 1 && (OpCode == BinaryOperatorKind::BO_EQ ||
+   OpCode == BinaryOperatorKind::BO_NE))
+  return;
+
 // Always true, no warnings for that.
 if ((OpCode == BinaryOperatorKind::BO_GE && Value == 0 && ContainerIsLHS) 
||
 (OpCode == BinaryOperatorKind::BO_LE && Value == 0 && !ContainerIsLHS))


Index: clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/readability-container-size-empty.cpp
@@ -7,6 +7,15 @@
   bool empty() const;
 };
 
+template  struct basic_string {
+  basic_string();
+  unsigned long size() const;
+  bool empty() const;
+};
+
+typedef basic_string string;
+typedef basic_string wstring;
+
 inline namespace __v2 {
 template  struct set {
   set();
@@ -20,10 +29,24 @@
 
 int main() {
   std::set intSet;
+  std::string str;
+  std::wstring wstr;
+  str.size() + 0;
+  str.size() - 0;
+  0 + str.size();
+  0 - str.size();
   if (intSet.size() == 0)
 ;
   // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty]
   // CHECK-FIXES: {{^  }}if (intSet.empty()){{$}}
+ 

Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-04-17 Thread Krystyna via cfe-commits
krystyna removed rL LLVM as the repository for this revision.
krystyna updated this revision to Diff 54007.
krystyna marked 5 inline comments as done.

http://reviews.llvm.org/D18919

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseUsingCheck.cpp
  clang-tidy/modernize/UseUsingCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-using.rst
  test/clang-tidy/modernize-use-using.cpp

Index: test/clang-tidy/modernize-use-using.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-using.cpp
@@ -0,0 +1,84 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t
+
+
+typedef int Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Type = int;
+
+typedef long LL;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using LL = long;
+
+typedef int Bla;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Bla = int;
+
+typedef Bla Bla2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Bla2 = Bla;
+
+typedef void (*type)(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using type = void (*)(int);
+
+typedef void (*type2)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using type2 = void (*)();
+
+class Class {
+typedef long long Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef [modernize-use-using]
+	// CHECK-FIXES: using Type = long long;
+};
+
+typedef void (Class::* MyPtrType)(Bla) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using MyPtrType = void (Class::*)(Bla) const;
+
+class Iterable {
+public:
+	class Iterator {};
+};
+
+template
+class Test {
+typedef typename T::iterator Iter;
+	// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef [modernize-use-using]
+	// CHECK-FIXES: using Iter = typename T::iterator;
+};
+
+using balba = long long;
+
+union A {};
+
+typedef void (A::*PtrType)(int, int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using PtrType = void (A::*)(int, int) const;
+
+typedef Class some_class;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using some_class = Class;
+
+typedef Class Cclass;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Cclass = Class;
+typedef Cclass cclass2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using cclass2 = Cclass;
+
+class cclass {
+
+};
+
+typedef void (cclass::* MyPtrType3)(Bla);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla);
+
+using my_class = int;
+
+//FIXME: below test fails
+typedef Test another;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using another = Test;
+
+
Index: docs/clang-tidy/checks/modernize-use-using.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-using.rst
@@ -0,0 +1,24 @@
+.. title:: clang-tidy - modernize-use-using
+
+modernize-use-using
+===
+
+Use C++11's ``using`` instead of ``typedef``.
+
+Before:
+
+.. code:: c++
+
+  typedef int variable;
+
+  class Class{};
+  typedef void (Class::* MyPtrType)() const;
+
+After:
+
+.. code:: c++
+
+  using varible = int;
+
+  class Class{};
+  using MyPtrType = void (Class::*)() const;
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -85,6 +85,7 @@
modernize-use-default
modernize-use-nullptr
modernize-use-override
+   modernize-use-using
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
Index: clang-tidy/modernize/UseUsingCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseUsingCheck.h
@@ -0,0 +1,35 @@
+//===--- UseUsingCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//

Re: [PATCH] D19314: [include-fixer] Add a prototype for a new include fixing tool.

2016-04-20 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266870: [include-fixer] Add a prototype for a new include 
fixing tool. (authored by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D19314?vs=54344=54350#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19314

Files:
  clang-tools-extra/trunk/CMakeLists.txt
  clang-tools-extra/trunk/include-fixer/CMakeLists.txt
  clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.cpp
  clang-tools-extra/trunk/include-fixer/InMemoryXrefsDB.h
  clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
  clang-tools-extra/trunk/include-fixer/IncludeFixer.h
  clang-tools-extra/trunk/include-fixer/XrefsDB.h
  clang-tools-extra/trunk/include-fixer/tool/CMakeLists.txt
  clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
  clang-tools-extra/trunk/unittests/CMakeLists.txt
  clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
  clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp

Index: clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
===
--- clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
+++ clang-tools-extra/trunk/unittests/include-fixer/IncludeFixerTest.cpp
@@ -0,0 +1,87 @@
+//===-- IncludeFixerTest.cpp - Include fixer unit tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../../../../unittests/Tooling/RewriterTestContext.h"
+#include "InMemoryXrefsDB.h"
+#include "IncludeFixer.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+using namespace clang;
+
+namespace clang {
+namespace include_fixer {
+namespace {
+
+static bool runOnCode(tooling::ToolAction *ToolAction, StringRef Code,
+  StringRef FileName) {
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new vfs::InMemoryFileSystem);
+  llvm::IntrusiveRefCntPtr Files(
+  new FileManager(FileSystemOptions(), InMemoryFileSystem));
+  tooling::ToolInvocation Invocation(
+  {std::string("include_fixer"), std::string("-fsyntax-only"),
+   FileName.str()},
+  ToolAction, Files.get(), std::make_shared());
+
+  InMemoryFileSystem->addFile(FileName, 0,
+  llvm::MemoryBuffer::getMemBuffer(Code));
+
+  InMemoryFileSystem->addFile("foo.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+  InMemoryFileSystem->addFile("bar.h", 0,
+  llvm::MemoryBuffer::getMemBuffer("\n"));
+  return Invocation.run();
+}
+
+static std::string runIncludeFixer(StringRef Code) {
+  std::map XrefsMap = {
+  {"std::string", {""}}, {"std::string::size_type", {""}}};
+  auto XrefsDB =
+  llvm::make_unique(std::move(XrefsMap));
+  std::vector Replacements;
+  IncludeFixerActionFactory Factory(*XrefsDB, Replacements);
+  runOnCode(, Code, "input.cc");
+  clang::RewriterTestContext Context;
+  clang::FileID ID = Context.createInMemoryFile("input.cc", Code);
+  clang::tooling::applyAllReplacements(Replacements, Context.Rewrite);
+  return Context.getRewrittenText(ID);
+}
+
+TEST(IncludeFixer, Typo) {
+  EXPECT_EQ("#include \nstd::string foo;\n",
+runIncludeFixer("std::string foo;\n"));
+
+  EXPECT_EQ(
+  "// comment\n#include \n#include \"foo.h\"\nstd::string foo;\n"
+  "#include \"bar.h\"\n",
+  runIncludeFixer("// comment\n#include \"foo.h\"\nstd::string foo;\n"
+  "#include \"bar.h\"\n"));
+
+  EXPECT_EQ("#include \n#include \"foo.h\"\nstd::string foo;\n",
+runIncludeFixer("#include \"foo.h\"\nstd::string foo;\n"));
+
+  EXPECT_EQ(
+  "#include \n#include \"foo.h\"\nstd::string::size_type foo;\n",
+  runIncludeFixer("#include \"foo.h\"\nstd::string::size_type foo;\n"));
+
+  // The fixed xrefs db doesn't know how to handle string without std::.
+  EXPECT_EQ("string foo;\n", runIncludeFixer("string foo;\n"));
+}
+
+TEST(IncludeFixer, IncompleteType) {
+  EXPECT_EQ(
+  "#include \n#include \"foo.h\"\n"
+  "namespace std {\nclass string;\n}\nstring foo;\n",
+  runIncludeFixer("#include \"foo.h\"\n"
+  "namespace std {\nclass string;\n}\nstring foo;\n"));
+}
+
+} // namespace
+} // namespace include_fixer
+} // namespace clang
Index: clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
===
--- clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
+++ clang-tools-extra/trunk/unittests/include-fixer/CMakeLists.txt
@@ -0,0 +1,22 @@
+set(LLVM_LINK_COMPONENTS
+  support
+  )
+
+get_filename_component(INCLUDE_FIXER_SOURCE_DIR
+  

Re: [PATCH] D18596: [MSVC] PR27132: Proper mangling for __unaligned qualifier

2016-04-15 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266415: [MSVC Compat] Implementation of __unaligned (MS 
extension) as a type qualifier (authored by asbokhan).

Changed prior to commit:
  http://reviews.llvm.org/D18596?vs=53509=53854#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18596

Files:
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Basic/AddressSpaces.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Sema/DeclSpec.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/AST/MicrosoftMangle.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseTentative.cpp
  cfe/trunk/lib/Sema/DeclSpec.cpp
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclObjC.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp
  cfe/trunk/test/Sema/MicrosoftExtensions.c
  cfe/trunk/test/Sema/address_spaces.c
  cfe/trunk/test/Sema/invalid-assignment-constant-address-space.c
  cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp

Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -152,8 +152,8 @@
 
   enum {
 /// The maximum supported address space number.
-/// 24 bits should be enough for anyone.
-MaxAddressSpace = 0xffu,
+/// 23 bits should be enough for anyone.
+MaxAddressSpace = 0x7fu,
 
 /// The width of the "fast" qualifier mask.
 FastWidth = 3,
@@ -265,6 +265,13 @@
 Mask |= mask;
   }
 
+  bool hasUnaligned() const { return Mask & UMask; }
+  void setUnaligned(bool flag) {
+Mask = (Mask & ~UMask) | (flag ? UMask : 0);
+  }
+  void removeUnaligned() { Mask &= ~UMask; }
+  void addUnaligned() { Mask |= UMask; }
+
   bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
   GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
   void setObjCGCAttr(GC type) {
@@ -433,7 +440,9 @@
// ObjC lifetime qualifiers must match exactly.
getObjCLifetime() == other.getObjCLifetime() &&
// CVR qualifiers may subset.
-   (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
+   (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
+   // U qualifier may superset.
+   (!(other.Mask & UMask) || (Mask & UMask));
   }
 
   /// \brief Determines if these qualifiers compatibly include another set of
@@ -501,16 +510,19 @@
 
 private:
 
-  // bits: |0 1 2|3 .. 4|5  ..  7|8   ...   31|
-  //   |C R V|GCAttr|Lifetime|AddressSpace|
+  // bits: |0 1 2|3|4 .. 5|6  ..  8|9   ...   31|
+  //   |C R V|U|GCAttr|Lifetime|AddressSpace|
   uint32_t Mask;
 
-  static const uint32_t GCAttrMask = 0x18;
-  static const uint32_t GCAttrShift = 3;
-  static const uint32_t LifetimeMask = 0xE0;
-  static const uint32_t LifetimeShift = 5;
-  static const uint32_t AddressSpaceMask = ~(CVRMask|GCAttrMask|LifetimeMask);
-  static const uint32_t AddressSpaceShift = 8;
+  static const uint32_t UMask = 0x8;
+  static const uint32_t UShift = 3;
+  static const uint32_t GCAttrMask = 0x30;
+  static const uint32_t GCAttrShift = 4;
+  static const uint32_t LifetimeMask = 0x1C0;
+  static const uint32_t LifetimeShift = 6;
+  static const uint32_t AddressSpaceMask =
+  ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
+  static const uint32_t AddressSpaceShift = 9;
 };
 
 /// A std::pair-like structure for storing a qualified type split
Index: cfe/trunk/include/clang/Sema/DeclSpec.h
===
--- cfe/trunk/include/clang/Sema/DeclSpec.h
+++ cfe/trunk/include/clang/Sema/DeclSpec.h
@@ -313,8 +313,10 @@
 TQ_volatile= 4,
 // This has no corresponding Qualifiers::TQ value, because it's not treated
 // as a qualifier in our type system.
-TQ_atomic  = 8
-  };
+TQ_atomic  = 8,
+// There is no corresponding Qualifiers::TQ value, but it's kept separately
+// in a dedicated Qualifiers::Mask bit.
+TQ_unaligned   = 16 };
 
   /// ParsedSpecifiers - Flags to query which specifiers were applied.  This is
   /// returned by getParsedSpecifiers.
@@ -344,7 +346,7 @@
   unsigned TypeSpecPipe : 1;
 
   // type-qualifiers
-  unsigned TypeQualifiers : 4;  // Bitwise OR of TQ.
+  unsigned TypeQualifiers : 5;  // Bitwise OR of TQ.
 
   // function-specifier
   unsigned FS_inline_specified : 1;
@@ -386,7 +388,8 @@
   /// TSTNameLoc provides source range info for tag types.
   SourceLocation TSTNameLoc;
   SourceRange TypeofParensRange;
-  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc;
+  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc,
+  TQ_unalignedLoc;
   SourceLocation 

[PATCH] D19108: [Sema] Fixed assert failure in template code analyzer

2016-04-14 Thread Eugene via cfe-commits
kevgs created this revision.
kevgs added reviewers: rsmith, dblaikie.
kevgs added a subscriber: cfe-commits.

Fix for this bug https://llvm.org/bugs/show_bug.cgi?id=27312

http://reviews.llvm.org/D19108

Files:
  lib/Sema/SemaAccess.cpp
  test/SemaTemplate/crash-bug-27258.cpp

Index: test/SemaTemplate/crash-bug-27258.cpp
===
--- /dev/null
+++ test/SemaTemplate/crash-bug-27258.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+template 
+struct AA {
+  template 
+  struct B {};
+};
+
+class C {
+  int i; // expected-note{{implicitly declared private here}}
+  template 
+  template 
+  friend struct AA::B;
+};
+
+struct A {
+  template 
+  struct B {
+void f() {
+  C c;
+  c.i; // expected-error{{'i' is a private member of 'C'}} 
expected-warning{{expression result unused}}
+}
+  };
+};
Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -475,8 +475,8 @@
 
 // If the class's context can't instantiate to the friend's
 // context, it can't be a dependent match.
-if (!MightInstantiateTo(S, CTD->getDeclContext(),
-Friend->getDeclContext()))
+if (Friend->getDeclContext()->isDependentContext() ||
+!MightInstantiateTo(S, CTD->getDeclContext(), 
Friend->getDeclContext()))
   continue;
 
 // Otherwise, it's a dependent match.


Index: test/SemaTemplate/crash-bug-27258.cpp
===
--- /dev/null
+++ test/SemaTemplate/crash-bug-27258.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+template 
+struct AA {
+  template 
+  struct B {};
+};
+
+class C {
+  int i; // expected-note{{implicitly declared private here}}
+  template 
+  template 
+  friend struct AA::B;
+};
+
+struct A {
+  template 
+  struct B {
+void f() {
+  C c;
+  c.i; // expected-error{{'i' is a private member of 'C'}} expected-warning{{expression result unused}}
+}
+  };
+};
Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -475,8 +475,8 @@
 
 // If the class's context can't instantiate to the friend's
 // context, it can't be a dependent match.
-if (!MightInstantiateTo(S, CTD->getDeclContext(),
-Friend->getDeclContext()))
+if (Friend->getDeclContext()->isDependentContext() ||
+!MightInstantiateTo(S, CTD->getDeclContext(), Friend->getDeclContext()))
   continue;
 
 // Otherwise, it's a dependent match.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19068: Lit C++11 Compatibility Patch #7

2016-04-13 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266239: Lit C++11 Compatibility Patch #7 (authored by 
lcharles).

Changed prior to commit:
  http://reviews.llvm.org/D19068?vs=53603=53607#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19068

Files:
  cfe/trunk/test/CXX/class.access/class.access.dcl/p1.cpp
  cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p2.cpp
  cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p3.cpp
  cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p2.cpp
  cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p5.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp
  cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp
  cfe/trunk/test/SemaCXX/type-convert-construct.cpp
  cfe/trunk/test/SemaCXX/vararg-non-pod.cpp
  cfe/trunk/test/SemaTemplate/class-template-spec.cpp
  cfe/trunk/test/SemaTemplate/instantiate-cast.cpp
  cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
  cfe/trunk/test/SemaTemplate/instantiate-member-class.cpp

Index: cfe/trunk/test/CXX/class.access/class.access.dcl/p1.cpp
===
--- cfe/trunk/test/CXX/class.access/class.access.dcl/p1.cpp
+++ cfe/trunk/test/CXX/class.access/class.access.dcl/p1.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
 
 // This is just the test for [namespace.udecl]p4 with 'using'
 // uniformly stripped out.
@@ -24,10 +26,33 @@
   }
 
   class Test0 {
-NonClass::type; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}}
-NonClass::hiding; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}}
-NonClass::union_member; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}}
-NonClass::enumerator; // expected-error {{not a class}} expected-warning {{access declarations are deprecated}}
+NonClass::type; // expected-error {{not a class}}
+#if __cplusplus <= 199711L
+// expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
+#else
+// expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
+#endif
+
+NonClass::hiding; // expected-error {{not a class}}
+#if __cplusplus <= 199711L
+// expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
+#else
+// expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
+#endif
+
+NonClass::union_member; // expected-error {{not a class}}
+#if __cplusplus <= 199711L
+// expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
+#else
+// expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
+#endif
+
+NonClass::enumerator; // expected-error {{not a class}}
+#if __cplusplus <= 199711L
+// expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
+#else
+// expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
+#endif
   };
 }
 
@@ -43,11 +68,39 @@
   };
 
   struct B : A {
-A::type; // expected-warning {{access declarations are deprecated}}
-A::hiding; // expected-warning {{access declarations are deprecated}}
-A::union_member; // expected-warning {{access declarations are deprecated}}
-A::enumerator; // expected-warning {{access declarations are deprecated}}
-A::tagname; // expected-warning {{access declarations are deprecated}}
+A::type;
+#if __cplusplus <= 199711L
+// expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
+#else
+// expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
+#endif
+A::hiding;
+#if __cplusplus <= 199711L
+// expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
+#else
+// expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
+#endif
+
+A::union_member;
+#if __cplusplus <= 199711L
+// expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
+#else
+// expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
+#endif
+
+A::enumerator;
+#if __cplusplus <= 199711L
+// expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
+#else
+// expected-error@-4 {{ISO C++11 does not allow access declarations; use using declarations instead}}
+#endif
+
+A::tagname;
+#if __cplusplus <= 199711L
+// expected-warning@-2 {{access declarations are deprecated; use using declarations instead}}
+#else
+// expected-error@-4 {{ISO C++11 does not allow access 

Re: [PATCH] D19331: [Clang-tidy] Fix for crash in modernize-raw-string-literal check

2016-04-21 Thread Marek via cfe-commits
edyp87 added a comment.

Yes, please apply this patch for me.

As for macro cases - I also thought about this but check's author has taken 
care of macros in `check()` method :

  void RawStringLiteralCheck::check(const MatchFinder::MatchResult ) {
 [...]
 if (Literal->getLocStart().isMacroID())
   return;
 [...]
  }

Thank you for quick review!


http://reviews.llvm.org/D19331



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19331: [Clang-tidy] Fix for crash in modernize-raw-string-literal check

2016-04-20 Thread Marek via cfe-commits
edyp87 removed rL LLVM as the repository for this revision.
edyp87 updated this revision to Diff 54401.
edyp87 added a comment.

Extended diff range + removed unnecessary variable.


http://reviews.llvm.org/D19331

Files:
  clang-tidy/modernize/RawStringLiteralCheck.cpp
  test/clang-tidy/modernize-raw-string-literal.cpp

Index: test/clang-tidy/modernize-raw-string-literal.cpp
===
--- test/clang-tidy/modernize-raw-string-literal.cpp
+++ test/clang-tidy/modernize-raw-string-literal.cpp
@@ -91,6 +91,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw 
string literal
 // CHECK-FIXES: {{^}}char const *const HexPrintable(R"(@\)");{{$}}
 
+char const *const prettyFunction(__PRETTY_FUNCTION__);
+char const *const function(__FUNCTION__);
+char const *const func(__func__);
+
 #define TRICK(arg_) #arg_
 char const *const MacroBody = TRICK(foo\\bar);
 
Index: clang-tidy/modernize/RawStringLiteralCheck.cpp
===
--- clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -108,7 +108,10 @@
 }
 
 void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(stringLiteral().bind("lit"), this);
+
+  Finder->addMatcher(
+  stringLiteral(unless(hasParent(predefinedExpr(.bind("lit"),
+  this);
 }
 
 void RawStringLiteralCheck::check(const MatchFinder::MatchResult ) {


Index: test/clang-tidy/modernize-raw-string-literal.cpp
===
--- test/clang-tidy/modernize-raw-string-literal.cpp
+++ test/clang-tidy/modernize-raw-string-literal.cpp
@@ -91,6 +91,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: {{.*}} can be written as a raw string literal
 // CHECK-FIXES: {{^}}char const *const HexPrintable(R"(@\)");{{$}}
 
+char const *const prettyFunction(__PRETTY_FUNCTION__);
+char const *const function(__FUNCTION__);
+char const *const func(__func__);
+
 #define TRICK(arg_) #arg_
 char const *const MacroBody = TRICK(foo\\bar);
 
Index: clang-tidy/modernize/RawStringLiteralCheck.cpp
===
--- clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -108,7 +108,10 @@
 }
 
 void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(stringLiteral().bind("lit"), this);
+
+  Finder->addMatcher(
+  stringLiteral(unless(hasParent(predefinedExpr(.bind("lit"),
+  this);
 }
 
 void RawStringLiteralCheck::check(const MatchFinder::MatchResult ) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19331: [Clang-tidy] Fix for crash in modernize-raw-string-literal check

2016-04-20 Thread Marek via cfe-commits
edyp87 marked an inline comment as done.
edyp87 added a comment.

1. Extended diff has been generated - sorry, I am new to Phabricator.
2. AST for this case looks like this:

> AST for crashing case:

> 

>   -VarDecl 0x2b27370  col:19 function 'const char *const' 
> callinit

>`-ImplicitCastExpr 0x2b274c0  'const char *' 

>  `-PredefinedExpr 0x2b27470  'const char [1]' lvalue __FUNCTION__

>`-StringLiteral 0x2b27448  'const char [1]' lvalue ""

> 

> Valid case:

> 

>   -VarDecl 0x2b26660  col:19 HexPrintable 'const char 
> *const' callinit

>`-ImplicitCastExpr 0x2b26718  'const char *' 

>  `-StringLiteral 0x2b266b8  'const char [3]' lvalue "@\\"


For `StringExpr` whose parent is `PredefinedExpr` `Lexer::getSourceText` 
returns this expr literally (`__FUNCTION__`) instead of evaluated function 
name. 
I was wondering whether there is another case which results in such assert 
(lack of quote in string) but I could not came with an idea of such scenario.
Another approach would be just returning from `check()` method while evaluating 
"quote-less" string but I thought that it would be less elegant.


http://reviews.llvm.org/D19331



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D19356: [Tooling] Inject -resource-dir instead of overwriting argv[0].

2016-04-21 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266973: [Tooling] Inject -resource-dir instead of 
overwriting argv[0]. (authored by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D19356?vs=54474=54478#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19356

Files:
  cfe/trunk/lib/Tooling/Tooling.cpp
  cfe/trunk/test/Tooling/clang-check-builtin-headers.cpp

Index: cfe/trunk/test/Tooling/clang-check-builtin-headers.cpp
===
--- cfe/trunk/test/Tooling/clang-check-builtin-headers.cpp
+++ cfe/trunk/test/Tooling/clang-check-builtin-headers.cpp
@@ -4,9 +4,11 @@
 // RUN: echo '[{"directory":".","command":"/random/tool -c 
%t/test.cpp","file":"%t/test.cpp"}]' | sed -e 's/\\/\//g' > 
%t/compile_commands.json
 // RUN: cp "%s" "%t/test.cpp"
 // RUN: not clang-check -p "%t" "%t/test.cpp" 2>&1|FileCheck %s
+// RUN: not clang-check -p "%t" "%t/test.cpp" -extra-arg=-resource-dir=foo 
2>&1|FileCheck %s -check-prefix=CHECK-NOHDR
 // FIXME: Make the above easier.
 
 #include 
 
 // CHECK: C++ requires
+// CHECK-NOHDR: fatal error: 'stddef.h' file not
 invalid;
Index: cfe/trunk/lib/Tooling/Tooling.cpp
===
--- cfe/trunk/lib/Tooling/Tooling.cpp
+++ cfe/trunk/lib/Tooling/Tooling.cpp
@@ -338,17 +338,22 @@
   ArgsAdjuster = nullptr;
 }
 
+static void injectResourceDir(CommandLineArguments , const char *Argv0,
+  void *MainAddr) {
+  // Allow users to override the resource dir.
+  for (StringRef Arg : Args)
+if (Arg.startswith("-resource-dir"))
+  return;
+
+  // If there's no override in place add our resource dir.
+  Args.push_back("-resource-dir=" +
+ CompilerInvocation::GetResourcesPath(Argv0, MainAddr));
+}
+
 int ClangTool::run(ToolAction *Action) {
   // Exists solely for the purpose of lookup of the resource path.
   // This just needs to be some symbol in the binary.
   static int StaticSymbol;
-  // The driver detects the builtin header path based on the path of the
-  // executable.
-  // FIXME: On linux, GetMainExecutable is independent of the value of the
-  // first argument, thus allowing ClangTool and runToolOnCode to just
-  // pass in made-up names here. Make sure this works on other platforms.
-  std::string MainExecutable =
-  llvm::sys::fs::getMainExecutable("clang_tool", );
 
   llvm::SmallString<128> InitialDirectory;
   if (std::error_code EC = llvm::sys::fs::current_path(InitialDirectory))
@@ -413,7 +418,17 @@
   if (ArgsAdjuster)
 CommandLine = ArgsAdjuster(CommandLine, CompileCommand.Filename);
   assert(!CommandLine.empty());
-  CommandLine[0] = MainExecutable;
+
+  // Add the resource dir based on the binary of this tool. argv[0] in the
+  // compilation database may refer to a different compiler and we want to
+  // pick up the very same standard library that compiler is using. The
+  // builtin headers in the resource dir need to match the exact clang
+  // version the tool is using.
+  // FIXME: On linux, GetMainExecutable is independent of the value of the
+  // first argument, thus allowing ClangTool and runToolOnCode to just
+  // pass in made-up names here. Make sure this works on other platforms.
+  injectResourceDir(CommandLine, "clang_tool", );
+
   // FIXME: We need a callback mechanism for the tool writer to output a
   // customized message for each file.
   DEBUG({ llvm::dbgs() << "Processing: " << File << ".\n"; });


Index: cfe/trunk/test/Tooling/clang-check-builtin-headers.cpp
===
--- cfe/trunk/test/Tooling/clang-check-builtin-headers.cpp
+++ cfe/trunk/test/Tooling/clang-check-builtin-headers.cpp
@@ -4,9 +4,11 @@
 // RUN: echo '[{"directory":".","command":"/random/tool -c %t/test.cpp","file":"%t/test.cpp"}]' | sed -e 's/\\/\//g' > %t/compile_commands.json
 // RUN: cp "%s" "%t/test.cpp"
 // RUN: not clang-check -p "%t" "%t/test.cpp" 2>&1|FileCheck %s
+// RUN: not clang-check -p "%t" "%t/test.cpp" -extra-arg=-resource-dir=foo 2>&1|FileCheck %s -check-prefix=CHECK-NOHDR
 // FIXME: Make the above easier.
 
 #include 
 
 // CHECK: C++ requires
+// CHECK-NOHDR: fatal error: 'stddef.h' file not
 invalid;
Index: cfe/trunk/lib/Tooling/Tooling.cpp
===
--- cfe/trunk/lib/Tooling/Tooling.cpp
+++ cfe/trunk/lib/Tooling/Tooling.cpp
@@ -338,17 +338,22 @@
   ArgsAdjuster = nullptr;
 }
 
+static void injectResourceDir(CommandLineArguments , const char *Argv0,
+  void *MainAddr) {
+  // Allow users to override the resource dir.
+  for (StringRef Arg : Args)
+if (Arg.startswith("-resource-dir"))
+  return;
+
+  // If there's no override in place add our resource dir.
+  Args.push_back("-resource-dir=" +
+ 

Re: [PATCH] D18652: [Inline asm] Correctly parse GCC-style asm line following MS-style asm line

2016-04-21 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266976: Correctly parse GCC-style asm line following 
MS-style asm line. (authored by dzobnin).

Changed prior to commit:
  http://reviews.llvm.org/D18652?vs=53543=54480#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18652

Files:
  cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
  cfe/trunk/include/clang/Parse/Parser.h
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Parse/ParseStmtAsm.cpp
  cfe/trunk/test/CodeGen/inline-asm-mixed-style.c

Index: cfe/trunk/include/clang/Parse/Parser.h
===
--- cfe/trunk/include/clang/Parse/Parser.h
+++ cfe/trunk/include/clang/Parse/Parser.h
@@ -1873,7 +1873,6 @@
 
   bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
   bool isTypeSpecifierQualifier();
-  bool isTypeQualifier() const;
 
   /// isKnownToBeTypeSpecifier - Return true if we know that the specified token
   /// is definitely a type-specifier.  Return false if it isn't part of a type
Index: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
@@ -27,6 +27,8 @@
   "MS-style inline assembly is not available: %0">;
 def err_gnu_inline_asm_disabled : Error<
   "GNU-style inline assembly is disabled">;
+def err_asm_goto_not_supported_yet : Error<
+  "'asm goto' constructs are not supported yet">;
 }
 
 let CategoryName = "Parse Issue" in {
Index: cfe/trunk/test/CodeGen/inline-asm-mixed-style.c
===
--- cfe/trunk/test/CodeGen/inline-asm-mixed-style.c
+++ cfe/trunk/test/CodeGen/inline-asm-mixed-style.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fasm-blocks -fsyntax-only -verify %s -DCHECK_ASM_GOTO
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fasm-blocks -O0 -emit-llvm -S %s -o - | FileCheck %s
+
+void f() {
+  __asm mov eax, ebx
+  __asm mov ebx, ecx
+  __asm__("movl %ecx, %edx");
+  // CHECK: movl%ebx, %eax
+  // CHECK: movl%ecx, %ebx
+  // CHECK: movl%ecx, %edx
+
+  __asm mov eax, ebx
+  __asm volatile ("movl %ecx, %edx");
+  // CHECK: movl%ebx, %eax
+  // CHECK: movl%ecx, %edx
+
+  __asm mov eax, ebx
+  __asm const ("movl %ecx, %edx"); // expected-warning {{ignored const qualifier on asm}} 
+  // CHECK: movl%ebx, %eax
+  // CHECK: movl%ecx, %edx
+
+#ifdef CHECK_ASM_GOTO
+  __asm volatile goto ("movl %ecx, %edx"); // expected-error {{'asm goto' constructs are not supported yet}}
+
+  __asm mov eax, ebx
+  __asm goto ("movl %ecx, %edx"); // expected-error {{'asm goto' constructs are not supported yet}}
+#endif
+}
Index: cfe/trunk/lib/Parse/ParseStmtAsm.cpp
===
--- cfe/trunk/lib/Parse/ParseStmtAsm.cpp
+++ cfe/trunk/lib/Parse/ParseStmtAsm.cpp
@@ -335,6 +335,33 @@
   return false;
 }
 
+/// isTypeQualifier - Return true if the current token could be the
+/// start of a type-qualifier-list.
+static bool isTypeQualifier(const Token ) {
+  switch (Tok.getKind()) {
+  default: return false;
+  // type-qualifier
+  case tok::kw_const:
+  case tok::kw_volatile:
+  case tok::kw_restrict:
+  case tok::kw___private:
+  case tok::kw___local:
+  case tok::kw___global:
+  case tok::kw___constant:
+  case tok::kw___generic:
+  case tok::kw___read_only:
+  case tok::kw___read_write:
+  case tok::kw___write_only:
+return true;
+  }
+}
+
+// Determine if this is a GCC-style asm statement.
+static bool isGCCAsmStatement(const Token ) {
+  return TokAfterAsm.is(tok::l_paren) || TokAfterAsm.is(tok::kw_goto) ||
+ isTypeQualifier(TokAfterAsm);
+}
+
 /// ParseMicrosoftAsmStatement. When -fms-extensions/-fasm-blocks is enabled,
 /// this routine is called to collect the tokens for an MS asm statement.
 ///
@@ -415,11 +442,11 @@
   if (ExpLoc.first != FID ||
   SrcMgr.getLineNumber(ExpLoc.first, ExpLoc.second) != LineNo) {
 // If this is a single-line __asm, we're done, except if the next
-// line begins with an __asm too, in which case we finish a comment
+// line is MS-style asm too, in which case we finish a comment
 // if needed and then keep processing the next line as a single
 // line __asm.
 bool isAsm = Tok.is(tok::kw_asm);
-if (SingleLineMode && !isAsm)
+if (SingleLineMode && (!isAsm || isGCCAsmStatement(NextToken(
   break;
 // We're no longer in a comment.
 InAsmComment = false;
@@ -643,8 +670,7 @@
   assert(Tok.is(tok::kw_asm) && "Not an asm stmt");
   SourceLocation AsmLoc = ConsumeToken();
 
-  if (getLangOpts().AsmBlocks && Tok.isNot(tok::l_paren) &&
-  !isTypeQualifier()) {
+  if (getLangOpts().AsmBlocks && !isGCCAsmStatement(Tok)) {
 msAsm = true;
 

Re: [PATCH] D20066: [include-fixer] Autodetect yaml databases in parent directories.

2016-05-09 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268920: [include-fixer] Autodetect yaml databases in parent 
directories. (authored by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D20066?vs=56570=56575#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20066

Files:
  clang-tools-extra/trunk/include-fixer/YamlXrefsDB.cpp
  clang-tools-extra/trunk/include-fixer/YamlXrefsDB.h
  clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
  clang-tools-extra/trunk/test/include-fixer/yamldb_autodetect.cpp

Index: clang-tools-extra/trunk/test/include-fixer/yamldb_autodetect.cpp
===
--- clang-tools-extra/trunk/test/include-fixer/yamldb_autodetect.cpp
+++ clang-tools-extra/trunk/test/include-fixer/yamldb_autodetect.cpp
@@ -0,0 +1,12 @@
+// REQUIRES: shell
+// RUN: mkdir -p %T/foo/bar
+// RUN: cp %p/Inputs/fake_yaml_db.yaml %T/find_all_symbols_db.yaml
+// RUN: cd %T/foo
+// RUN: sed -e 's#//.*$##' %s > bar/test.cpp
+// RUN: clang-include-fixer -db=yaml bar/test.cpp --
+// RUN: FileCheck %s -input-file=bar/test.cpp
+
+// CHECK: #include "foo.h"
+// CHECK: b::a::foo f;
+
+b::a::foo f;
Index: clang-tools-extra/trunk/include-fixer/YamlXrefsDB.cpp
===
--- clang-tools-extra/trunk/include-fixer/YamlXrefsDB.cpp
+++ clang-tools-extra/trunk/include-fixer/YamlXrefsDB.cpp
@@ -8,27 +8,43 @@
 //===--===//
 
 #include "YamlXrefsDB.h"
-
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
 #include 
 #include 
 
 using clang::find_all_symbols::SymbolInfo;
 
 namespace clang {
 namespace include_fixer {
 
-YamlXrefsDB::YamlXrefsDB(llvm::StringRef FilePath) {
-  int ReadFD = 0;
-  if (llvm::sys::fs::openFileForRead(FilePath, ReadFD))
-return;
-  auto Buffer = llvm::MemoryBuffer::getOpenFile(ReadFD, FilePath, -1);
+llvm::ErrorOr
+YamlXrefsDB::createFromFile(llvm::StringRef FilePath) {
+  auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
   if (!Buffer)
-return;
-  Symbols = clang::find_all_symbols::ReadSymbolInfosFromYAML(
-  Buffer.get()->getBuffer());
+return Buffer.getError();
+
+  return std::unique_ptr(
+  new YamlXrefsDB(clang::find_all_symbols::ReadSymbolInfosFromYAML(
+  Buffer.get()->getBuffer(;
+}
+
+llvm::ErrorOr
+YamlXrefsDB::createFromDirectory(llvm::StringRef Directory,
+ llvm::StringRef Name) {
+  // Walk upwards from Directory, looking for files.
+  for (llvm::SmallString<128> PathStorage = Directory; !Directory.empty();
+   Directory = llvm::sys::path::parent_path(Directory)) {
+assert(Directory.size() <= PathStorage.size());
+PathStorage.resize(Directory.size()); // Shrink to parent.
+llvm::sys::path::append(PathStorage, Name);
+if (auto DB = createFromFile(PathStorage))
+  return DB;
+  }
+  return llvm::make_error_code(llvm::errc::no_such_file_or_directory);
 }
 
 std::vector YamlXrefsDB::search(llvm::StringRef Identifier) {
Index: clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
===
--- clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
+++ clang-tools-extra/trunk/include-fixer/tool/ClangIncludeFixer.cpp
@@ -73,8 +73,26 @@
 break;
   }
   case yaml: {
-XrefsDBMgr->addXrefsDB(
-llvm::make_unique(Input));
+llvm::ErrorOr DB(nullptr);
+if (!Input.empty()) {
+  DB = include_fixer::YamlXrefsDB::createFromFile(Input);
+} else {
+  // If we don't have any input file, look in the directory of the first
+  // file and its parents.
+  SmallString<128> AbsolutePath(
+  tooling::getAbsolutePath(options.getSourcePathList().front()));
+  StringRef Directory = llvm::sys::path::parent_path(AbsolutePath);
+  DB = include_fixer::YamlXrefsDB::createFromDirectory(
+  Directory, "find_all_symbols_db.yaml");
+}
+
+if (!DB) {
+  llvm::errs() << "Couldn't find YAML db: " << DB.getError().message()
+   << '\n';
+  return 1;
+}
+
+XrefsDBMgr->addXrefsDB(std::move(*DB));
 break;
   }
   }
Index: clang-tools-extra/trunk/include-fixer/YamlXrefsDB.h
===
--- clang-tools-extra/trunk/include-fixer/YamlXrefsDB.h
+++ clang-tools-extra/trunk/include-fixer/YamlXrefsDB.h
@@ -12,6 +12,7 @@
 
 #include "XrefsDB.h"
 #include "find-all-symbols/SymbolInfo.h"
+#include "llvm/Support/ErrorOr.h"
 #include 
 #include 
 
@@ -21,12 +22,20 @@
 /// Yaml format database.
 class YamlXrefsDB : public XrefsDB {
 public:
-  YamlXrefsDB(llvm::StringRef FilePath);
+  /// Create a new Yaml 

Re: [PATCH] D20011: [OpenMP 4.5] Parse+Sema for '#pragma omp declare target' clauses

2016-05-09 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268925: [OpenMP] Parse+Sema for '#pragma omp declare target' 
syntax version 4.5 (authored by dpolukhin).

Changed prior to commit:
  http://reviews.llvm.org/D20011?vs=56387=56582#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20011

Files:
  cfe/trunk/include/clang/AST/ASTMutationListener.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Parse/Parser.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/include/clang/Serialization/ASTWriter.h
  cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
  cfe/trunk/lib/Parse/ParseOpenMP.cpp
  cfe/trunk/lib/Sema/SemaOpenMP.cpp
  cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/test/OpenMP/declare_target_ast_print.cpp
  cfe/trunk/test/OpenMP/declare_target_messages.cpp

Index: cfe/trunk/lib/Sema/SemaOpenMP.cpp
===
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp
@@ -1101,6 +1101,23 @@
 return false;
   }
 };
+
+class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback {
+private:
+  Sema 
+
+public:
+  explicit VarOrFuncDeclFilterCCC(Sema ) : SemaRef(S) {}
+  bool ValidateCandidate(const TypoCorrection ) override {
+NamedDecl *ND = Candidate.getCorrectionDecl();
+if (isa(ND) || isa(ND)) {
+  return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(),
+   SemaRef.getCurScope());
+}
+return false;
+  }
+};
+
 } // namespace
 
 ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope,
@@ -10752,6 +10769,52 @@
   IsInOpenMPDeclareTargetContext = false;
 }
 
+void
+Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, CXXScopeSpec ,
+   const DeclarationNameInfo ,
+   OMPDeclareTargetDeclAttr::MapTypeTy MT,
+   NamedDeclSetType ) {
+  LookupResult Lookup(*this, Id, LookupOrdinaryName);
+  LookupParsedName(Lookup, CurScope, , true);
+
+  if (Lookup.isAmbiguous())
+return;
+  Lookup.suppressDiagnostics();
+
+  if (!Lookup.isSingleResult()) {
+if (TypoCorrection Corrected =
+CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr,
+llvm::make_unique(*this),
+CTK_ErrorRecovery)) {
+  diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
+  << Id.getName());
+  checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl());
+  return;
+}
+
+Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName();
+return;
+  }
+
+  NamedDecl *ND = Lookup.getAsSingle();
+  if (isa(ND) || isa(ND)) {
+if (!SameDirectiveDecls.insert(cast(ND->getCanonicalDecl(
+  Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName();
+
+if (!ND->hasAttr()) {
+  Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT);
+  ND->addAttr(A);
+  if (ASTMutationListener *ML = Context.getASTMutationListener())
+ML->DeclarationMarkedOpenMPDeclareTarget(ND, A);
+  checkDeclIsAllowedInOpenMPTarget(nullptr, ND);
+} else if (ND->getAttr()->getMapType() != MT) {
+  Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link)
+  << Id.getName();
+}
+  } else
+Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName();
+}
+
 static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR,
  Sema , Decl *D) {
   if (!D)
@@ -10765,9 +10828,11 @@
 // If this is an implicit variable that is legal and we do not need to do
 // anything.
 if (cast(D)->isImplicit()) {
-  D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(SemaRef.Context));
+  Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(
+  SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To);
+  D->addAttr(A);
   if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener())
-ML->DeclarationMarkedOpenMPDeclareTarget(D);
+ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
   return;
 }
 
@@ -10780,9 +10845,11 @@
 // target region (it can be e.g. a lambda) that is legal and we do not need
 // to do anything else.
 if (LD == D) {
-  D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(SemaRef.Context));
+  Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(
+  SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To);
+  D->addAttr(A);
   if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener())
-ML->DeclarationMarkedOpenMPDeclareTarget(D);
+ML->DeclarationMarkedOpenMPDeclareTarget(D, A);
   return;
 }
   }
@@ -10810,9 +10877,11 @@
   

<    1   2   3   4   5   6   7   8   9   10   >