[PATCH] D26922: [ObjC++] Don't enter a C++ declarator context when the current context is an Objective-C declaration

2016-11-29 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Yes, I meant ParseDecl:5266. Reading the comment in ShouldEnterDeclaratorScope, 
it seemed to me that it shouldn't return true in this context (when parsing an 
objective-c).

Also, the following code (which is not valid) crashes with ToT trunk,

  @property (nonatomic) int OuterType::InnerType

but compiles without any errors with your patch applied. Do you know why clang 
doesn't error out?


Repository:
  rL LLVM

https://reviews.llvm.org/D26922



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


[PATCH] D27207: Adds hasUnqualifiedDesugaredType to allow matching through type sugar.

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

hasUnqualifiedDesugaredType(hasDeclaration(

How about using hasUnqualifiedDesugaredType(recordType(hasDeclaration instead?


https://reviews.llvm.org/D27207



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


[PATCH] D26657: [Sema] Respect DLL attributes more faithfully

2016-11-29 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added inline comments.



Comment at: include/clang/Sema/Sema.h:7494
 
+  /// \brief Make an existing DLL attribute on a class take effect.
+  void ActOnDLLAttr(ClassTemplateSpecializationDecl *Def,

hans wrote:
> Nit: I think `///` implies `\brief`, so we don't usually include it.
Cool, will drop.



Comment at: include/clang/Sema/Sema.h:7495
+  /// \brief Make an existing DLL attribute on a class take effect.
+  void ActOnDLLAttr(ClassTemplateSpecializationDecl *Def,
+InheritableAttr *Attr);

hans wrote:
> hans wrote:
> > I'd suggest making the function name more specific. It obviously doesn't 
> > apply to all DLL attributes, but only class templates.
> > 
> > Also, the "ActOn" methods in Sema are used as an interface to be called by 
> > the parser, so I would avoid that prefix.
> > 
> > Naming is hard :-/
> > 
> > Maybe `checkDllExportedTemplateSpecialization`
> also it should be in the `private:` section since it's just a helper. And 
> maybe the "check" part is unnecessary? `dllExportClassTemplateSpecialization` 
> might work.
Good point about the prefix. I'll do the rename. I intended to make it private; 
if it's in the wrong part of the header, that's an accident on my part :)



Comment at: lib/Sema/SemaTemplate.cpp:7439
+void Sema::ActOnDLLAttr(ClassTemplateSpecializationDecl *Def,
+InheritableAttr *Attr) {
+  // We reject explicit instantiations in class scope, so there should

hans wrote:
> This function only applies to dllexport, not dllimport, so it would be good 
> if the name reflected that, and maybe we could also add an assert to check 
> for it.
It's called in two places (the refactored original call for explicit 
instantiation declaration followed by explicit instantiation definition, and my 
new call for implicit instantiation followed by explicit instantiation 
definition). The dllexport guarantee only applies to the second one, right? 
I'll come up with a better name based on your suggestions in the other comment.



Comment at: lib/Sema/SemaTemplate.cpp:7710
+(Context.getTargetInfo().getCXXABI().isMicrosoft() ||
+ Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment())) {
+  // In the MS ABI, an explicit instantiation definition can add a dll

hans wrote:
> Why the isWindowsItaniumEnvironment check? I'd expect checking for the MS ABI 
> is sufficient?
windows-itanium in general tries to stick to MSVC semantics for 
dllexport/import annotations (unlike Cygwin and MinGW which kinda do their own 
thing). This is consistent with the conditional for the previous case (lines 
7691 to 7693 in this diff).


https://reviews.llvm.org/D26657



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


[PATCH] D27248: [clang-tidy] Do not trigger unnecessary-value-param check on methods marked as final

2016-11-29 Thread Felix Berger via Phabricator via cfe-commits
flx created this revision.
flx added reviewers: sbenza, alexfh, hokein.
flx added a subscriber: cfe-commits.
flx set the repository for this revision to rL LLVM.
flx added a project: clang-tools-extra.
Herald added a subscriber: JDevlieghere.

Virtual method overrides of dependent types cannot be recognized unless they  
are marked as override or final.

Exclude methods marked as final from check and add test.


Repository:
  rL LLVM

https://reviews.llvm.org/D27248

Files:
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  test/clang-tidy/performance-unnecessary-value-param.cpp


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -271,3 +271,21 @@
 void ReferenceFunctionByCallingIt() {
   PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType());
 }
+
+// Virtual method overrides of dependent types cannot be recognized unless they
+// are marked as override or final. Test that check is not triggered on methods
+// marked with override or final.
+template 
+struct NegativeDependentTypeInterface {
+  virtual void Method(ExpensiveToCopyType E) = 0;
+};
+
+template 
+struct NegativOverrideImpl : public NegativeDependentTypeInterface {
+  void Method(ExpensiveToCopyType E) override {}
+};
+
+template 
+struct NegativFinalImpl : public NegativeDependentTypeInterface {
+  void Method(ExpensiveToCopyType E) final {}
+};
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -61,7 +61,8 @@
  unless(referenceType(),
   decl().bind("param"));
   Finder->addMatcher(
-  functionDecl(isDefinition(), unless(cxxMethodDecl(isOverride())),
+  functionDecl(isDefinition(),
+   unless(cxxMethodDecl(anyOf(isOverride(), isFinal(,
unless(isInstantiated()),
has(typeLoc(forEach(ExpensiveValueParamDecl))),
decl().bind("functionDecl")),


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -271,3 +271,21 @@
 void ReferenceFunctionByCallingIt() {
   PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType());
 }
+
+// Virtual method overrides of dependent types cannot be recognized unless they
+// are marked as override or final. Test that check is not triggered on methods
+// marked with override or final.
+template 
+struct NegativeDependentTypeInterface {
+  virtual void Method(ExpensiveToCopyType E) = 0;
+};
+
+template 
+struct NegativOverrideImpl : public NegativeDependentTypeInterface {
+  void Method(ExpensiveToCopyType E) override {}
+};
+
+template 
+struct NegativFinalImpl : public NegativeDependentTypeInterface {
+  void Method(ExpensiveToCopyType E) final {}
+};
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -61,7 +61,8 @@
  unless(referenceType(),
   decl().bind("param"));
   Finder->addMatcher(
-  functionDecl(isDefinition(), unless(cxxMethodDecl(isOverride())),
+  functionDecl(isDefinition(),
+   unless(cxxMethodDecl(anyOf(isOverride(), isFinal(,
unless(isInstantiated()),
has(typeLoc(forEach(ExpensiveValueParamDecl))),
decl().bind("functionDecl")),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r288231 - Prospective GCC build fix: the unelaborated form of this friend

2016-11-29 Thread John McCall via cfe-commits
Author: rjmccall
Date: Tue Nov 29 22:18:19 2016
New Revision: 288231

URL: http://llvm.org/viewvc/llvm-project?rev=288231=rev
Log:
Prospective GCC build fix: the unelaborated form of this friend
declaration should find the right type, assuming it's supported
evenly across all our hosts.

Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=288231=288230=288231=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Nov 29 22:18:19 2016
@@ -1166,7 +1166,7 @@ public:
 
 class CGObjCMac : public CGObjCCommonMac {
 private:
-  friend class ProtocolMethodLists;
+  friend ProtocolMethodLists;
 
   ObjCTypesHelper ObjCTypes;
 
@@ -1356,7 +1356,7 @@ public:
 
 class CGObjCNonFragileABIMac : public CGObjCCommonMac {
 private:
-  friend class ProtocolMethodLists;
+  friend ProtocolMethodLists;
   ObjCNonFragileABITypesHelper ObjCTypes;
   llvm::GlobalVariable* ObjCEmptyCacheVar;
   llvm::Constant* ObjCEmptyVtableVar;


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


r288230 - make -fprofile-instr-generate and -fprofile-instr-use work with clang-cl

2016-11-29 Thread Bob Haarman via cfe-commits
Author: inglorion
Date: Tue Nov 29 21:25:36 2016
New Revision: 288230

URL: http://llvm.org/viewvc/llvm-project?rev=288230=rev
Log:
make -fprofile-instr-generate and -fprofile-instr-use work with clang-cl

Summary: Makes -fprofile-instr-generate and -fprofile-instr-use work
with clang-cl so that profile-guided optimization can be used.

Differential Revision: https://reviews.llvm.org/D27086

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/test/Driver/cl-options.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=288230=288229=288230=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Nov 29 21:25:36 2016
@@ -510,15 +510,15 @@ def fprofile_sample_use_EQ : Joined<["-"
 def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
 Alias;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
-Group, Flags<[DriverOption]>,
+Group, Flags<[CoreOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overriden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
 def fprofile_instr_generate_EQ : Joined<["-"], "fprofile-instr-generate=">,
-Group, Flags<[DriverOption]>, MetaVarName<"">,
+Group, Flags<[CoreOption]>, MetaVarName<"">,
 HelpText<"Generate instrumented code to collect execution counts into 
 (overridden by LLVM_PROFILE_FILE env var)">;
 def fprofile_instr_use : Flag<["-"], "fprofile-instr-use">, Group,
-Flags<[DriverOption]>;
+Flags<[CoreOption]>;
 def fprofile_instr_use_EQ : Joined<["-"], "fprofile-instr-use=">,
-Group, Flags<[DriverOption]>,
+Group, Flags<[CoreOption]>,
 HelpText<"Use instrumentation data for profile-guided optimization">;
 def fcoverage_mapping : Flag<["-"], "fcoverage-mapping">,
 Group, Flags<[CC1Option]>,

Modified: cfe/trunk/test/Driver/cl-options.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=288230=288229=288230=diff
==
--- cfe/trunk/test/Driver/cl-options.c (original)
+++ cfe/trunk/test/Driver/cl-options.c Tue Nov 29 21:25:36 2016
@@ -59,6 +59,19 @@
 // RUN: %clang_cl /Z7 -### -- %s 2>&1 | FileCheck -check-prefix=gdefcolumn %s
 // gdefcolumn-NOT: -dwarf-column-info
 
+// RUN: %clang_cl -### /FA -fprofile-instr-generate -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-GENERATE %s
+// RUN: %clang_cl -### /FA -fprofile-instr-generate=/tmp/somefile.profraw -- 
%s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-FILE %s
+// RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use -- %s 
2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s
+// RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use=file 
-- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s
+// CHECK-PROFILE-GENERATE: "-fprofile-instrument=clang"
+// CHECK-PROFILE-GENERATE-FILE: 
"-fprofile-instrument-path=/tmp/somefile.profraw"
+// CHECK-NO-MIX-GEN-USE: '{{[a-z=-]*}}' not allowed with '{{[a-z=-]*}}'
+
+// RUN: %clang_cl -### /FA -fprofile-instr-use -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-USE %s
+// RUN: %clang_cl -### /FA -fprofile-instr-use=/tmp/somefile.prof -- %s 2>&1 | 
FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s
+// CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata"
+// CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof"
+
 // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s
 // GA: -ftls-model=local-exec
 


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


[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-29 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Thanks for working on this! I'm happy with the direction of this patch. It 
makes sense that clang would have a tool to help test AST reconstruction from 
'external' sources. As you pointed out, it provides a good avenue for clients 
of the clang AST's to get better test coverage for their custom serialization 
formats. I haven't been paying much attention to the discussion about the 
clangDebuggerSupport library, but it sounds like your work will ultimately 
depend on it. Is that correct?

I've left some lower-level comments inline.

At a higher level, I'm concerned about the amount of covered-but-untested code 
this patch introduces. Since there are no CHECK lines, it's hard for me to 
verify that this tool is doing the right thing. What we really want to test 
right away is that the tool can "dump" the correct definition for `struct S` 
(since this implies that the importing went OK). A good way to go about this 
would be to add a hidden "debug" cl::opt, dump all imported struct decls when 
in -debug mode, and then add some CHECK lines for the expected struct decl.

Along with this change, I suggest stripping out a fair amount of code for the 
initial commit (probably PrintSourceForLocation, and maybe anything related to 
LogLookups).




Comment at: tools/clang-import-test/clang-import-test.cpp:238
+
+  CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.data(),
+ ()[ClangArgv.size()],

spyffe wrote:
> a.sidorin wrote:
> > `ClangArgv.begin(), ClangArgv.end()`
> ```
> .../llvm/tools/clang/tools/clang-import-test/clang-import-test.cpp:236:44: 
> error: no viable conversion from 'iterator' (aka '__wrap_iter **>') to 'const char *const *'
>   CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.begin(), ClangArgv.end(),
>^
> .../llvm/tools/clang/include/clang/Frontend/CompilerInvocation.h:139:49: 
> note: passing argument to parameter 'ArgBegin' here
>  const char* const *ArgBegin,
> ^
> ```
This should resolve it, but it seems less readable: `&*args.cbegin(), 
&*args.cend()`. I'd leave this as-is..



Comment at: tools/clang-import-test/clang-import-test.cpp:164
+  ExpressionCI.getASTContext(), ExpressionCI.getFileManager(),
+  ImportCI->getASTContext(), ImportCI->getFileManager(), 
MinimalImport);
+  ReverseImporters[ImportCI] = llvm::make_unique(

I think it's more idiomatic to say `/*MinimalImport=*/true` in clang.



Comment at: tools/clang-import-test/clang-import-test.cpp:282
+llvm::LLVMContext ) {
+  std::string ModuleName("$__module");
+  return std::unique_ptr(CreateLLVMCodeGen(

This might as well be constructed as a StringRef from the get-go, since it's 
eventually converted into one.



Comment at: tools/clang-import-test/clang-import-test.cpp:302
+bool Parse(const std::string , std::unique_ptr ,
+   llvm::ArrayRef Imports) {
+  CI = BuildCompilerInstance();

I suggest making this `Expected Parse(..., 
ArrayRef)`. This way, there's no way to 
mistake CI for an input param, there's no need for an extra step to convert 
std::unique_ptr to CompilerInstance *, and it's harder to 
drop an error from Parse without logging/handling it.


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


[PATCH] D27091: Add the way to extract SVals of arguments used in a call for a given StackFrameCtx

2016-11-29 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Hi!

Looks like this this is used by the Infinite recursion checker. Specifically, 
the checker not only needs to get Smalls for arguments of the current 
CallEvent, but it also looks for arguments of other calls on the stack. The 
checker walks the LocationContext and uses this new API to look up the 
arguments passed to the calls on the stack.

The two concerns I have with this patch is that it is extending the overloaded 
ProgramState API and also that this does not fully cover all the call types we 
have in C/ObjC/C++. The good news is that the CallEvent API was created 
specifically to encapsulate this complexity and it already contains the needed 
API to look up the SVal of the argument. Have you considered creating CallEvent 
for the calls on the stack and using that existing API to find the Smalls of 
the arguments.

Here is some documentation from CallEvent.h:
`
 /// CallEvents are created through the factory methods of CallEventManager.
 ///
 /// CallEvents should always be cheap to create and destroy. In order for
 /// CallEventManager to be able to re-use CallEvent-sized memory blocks,
 /// subclasses of CallEvent may not add any data members to the base class.
 /// Use the "Data" and "Location" fields instead.

`

It looks like this code from BugReporterVisitors.cpp is doing something similar:

  ` // Don't automatically suppress a report if one of the arguments is
   // known to be a null pointer. Instead, start tracking /that/ null
   // value back to its origin.
   ProgramStateManager  = BRC.getStateManager();
   CallEventManager  = StateMgr.getCallEventManager();
  
   ProgramStateRef State = N->getState();
   CallEventRef<> Call = CallMgr.getCaller(StackFrame, State);
   for (unsigned I = 0, E = Call->getNumArgs(); I != E; ++I) {
 Optional ArgV = Call->getArgSVal(I).getAs();
 if (!ArgV)
   continue;

`

 

I hope this approach works and you could just add that code to your checker. 
(If not, we can investigate other options.)


https://reviews.llvm.org/D27091



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


[PATCH] D27084: [OpenMP] Sema and parsing for 'teams distribute parallel for simd' pragma

2016-11-29 Thread Kelvin Li via Phabricator via cfe-commits
kkwli0 marked 2 inline comments as done.
kkwli0 added inline comments.



Comment at: test/OpenMP/nesting_of_regions.cpp:3326
   }
-#pragma omp ordered
   {

ABataev wrote:
> what about teams distribute parallel for simd inside the ordered directive? 
> Why this one is removed?
This is a typo (likely due to copy and paste error), it should be atomic as 
this section is to test constructs nested inside an atomic construct.  The 
testing of constructs nested inside an ordered construct is in line 2910-3149.


https://reviews.llvm.org/D27084



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


r288227 - Fix -Winconsistent-missing-override in CodeGenAction.cpp

2016-11-29 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Nov 29 19:32:53 2016
New Revision: 288227

URL: http://llvm.org/viewvc/llvm-project?rev=288227=rev
Log:
Fix -Winconsistent-missing-override in CodeGenAction.cpp

Modified:
cfe/trunk/lib/CodeGen/CodeGenAction.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=288227=288226=288227=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Tue Nov 29 19:32:53 2016
@@ -152,7 +152,7 @@ namespace clang {
 LLVMIRGeneration.stopTimer();
 }
 
-void HandleInterestingDecl(DeclGroupRef D) {
+void HandleInterestingDecl(DeclGroupRef D) override {
   // Ignore interesting decls from the AST reader after IRGen is finished.
   if (!IRGenFinished)
 HandleTopLevelDecl(D);


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


[PATCH] D27226: [MS ABI] Implement more of the Itanium mangling rules

2016-11-29 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: test/CodeGenCXX/mangle-ms-cxx11.cpp:337
+A a;
+}

This machinery is also supposed to kick in for lambdas in default arguments, 
right? Can you add that test case?


https://reviews.llvm.org/D27226



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


Re: r288207 - Don't try to merge DLL attributes on redeclaration of invalid decl (PR31069)

2016-11-29 Thread Hans Wennborg via cfe-commits
On Tue, Nov 29, 2016 at 4:37 PM, David Majnemer via cfe-commits
 wrote:
>
>
> On Tue, Nov 29, 2016 at 2:31 PM, Hans Wennborg via cfe-commits
>  wrote:
>>
>> Author: hans
>> Date: Tue Nov 29 16:31:00 2016
>> New Revision: 288207
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=288207=rev
>> Log:
>> Don't try to merge DLL attributes on redeclaration of invalid decl
>> (PR31069)
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaDecl.cpp
>> cfe/trunk/test/Sema/dllimport.c
>>
>> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=288207=288206=288207=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 16:31:00 2016
>> @@ -5651,6 +5651,9 @@ static void checkDLLAttributeRedeclarati
>> NamedDecl *NewDecl,
>> bool IsSpecialization,
>> bool IsDefinition) {
>> +  if(OldDecl->isInvalidDecl())
>> +return;
>> +
>
>
> Formatting looks weird here.

Should be fixed with r288223.

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


r288223 - Fix formatting issue from r288207

2016-11-29 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Tue Nov 29 18:31:39 2016
New Revision: 288223

URL: http://llvm.org/viewvc/llvm-project?rev=288223=rev
Log:
Fix formatting issue from r288207

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=288223=288222=288223=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 18:31:39 2016
@@ -5642,7 +5642,7 @@ static void checkDLLAttributeRedeclarati
NamedDecl *NewDecl,
bool IsSpecialization,
bool IsDefinition) {
-  if(OldDecl->isInvalidDecl())
+  if (OldDecl->isInvalidDecl())
 return;
 
   if (TemplateDecl *OldTD = dyn_cast(OldDecl)) {


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


r288222 - Give this test that uses Itanium mangling a triple

2016-11-29 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Nov 29 18:31:16 2016
New Revision: 288222

URL: http://llvm.org/viewvc/llvm-project?rev=288222=rev
Log:
Give this test that uses Itanium mangling a triple

Modified:
cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp

Modified: cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp?rev=288222=288221=288222=diff
==
--- cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp (original)
+++ cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp Tue Nov 29 18:31:16 2016
@@ -2,8 +2,10 @@
 // happens to use a RecursiveASTVisitor that forces deserialization of AST
 // files.
 //
-// RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -emit-pch -o %t.pch %s
-// RUN: %clang_cc1 -load %llvmshlibdir/PrintFunctionNames%pluginext \
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fdelayed-template-parsing \
+// RUN:  -std=c++14 -emit-pch -o %t.pch %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple \
+// RUN: -load %llvmshlibdir/PrintFunctionNames%pluginext \
 // RUN: -add-plugin print-fns -std=c++14 -include-pch %t.pch %s -emit-llvm 
\
 // RUN: -fdelayed-template-parsing -debug-info-kind=limited \
 // RUN: -o %t.ll 2>&1 | FileCheck --check-prefix=DECLS %s


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


Re: r288207 - Don't try to merge DLL attributes on redeclaration of invalid decl (PR31069)

2016-11-29 Thread David Majnemer via cfe-commits
On Tue, Nov 29, 2016 at 2:31 PM, Hans Wennborg via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: hans
> Date: Tue Nov 29 16:31:00 2016
> New Revision: 288207
>
> URL: http://llvm.org/viewvc/llvm-project?rev=288207=rev
> Log:
> Don't try to merge DLL attributes on redeclaration of invalid decl
> (PR31069)
>
> Modified:
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/Sema/dllimport.c
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaDecl.cpp?rev=288207=288206=288207=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 16:31:00 2016
> @@ -5651,6 +5651,9 @@ static void checkDLLAttributeRedeclarati
> NamedDecl *NewDecl,
> bool IsSpecialization,
> bool IsDefinition) {
> +  if(OldDecl->isInvalidDecl())
> +return;
> +
>

Formatting looks weird here.


>if (TemplateDecl *OldTD = dyn_cast(OldDecl)) {
>  OldDecl = OldTD->getTemplatedDecl();
>  if (!IsSpecialization)
>
> Modified: cfe/trunk/test/Sema/dllimport.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/
> dllimport.c?rev=288207=288206=288207=diff
> 
> ==
> --- cfe/trunk/test/Sema/dllimport.c (original)
> +++ cfe/trunk/test/Sema/dllimport.c Tue Nov 29 16:31:00 2016
> @@ -210,6 +210,10 @@ __declspec(dllimport) void redecl6();
>void redecl7();
>  __declspec(dllimport) inline void redecl7() {}
>
> +// PR31069: Don't crash trying to merge attributes for redeclaration of
> invalid decl.
> +void __declspec(dllimport) redecl8(unknowntype X); //
> expected-error{{unknown type name 'unknowntype'}}
> +void redecl8(unknowntype X) { } // expected-error{{unknown type name
> 'unknowntype'}}
> +
>  // External linkage is required.
>  __declspec(dllimport) static int staticFunc(); //
> expected-error{{'staticFunc' must have external linkage when declared
> 'dllimport'}}
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r288221 - Stop handling interesting deserialized decls after HandleTranslationUnit

2016-11-29 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Nov 29 18:25:36 2016
New Revision: 288221

URL: http://llvm.org/viewvc/llvm-project?rev=288221=rev
Log:
Stop handling interesting deserialized decls after HandleTranslationUnit

Other AST consumers can deserialize interesting decls that we might
codegen, but they won't make it to the final object file and can trigger
assertions in debug information generation after finalization.

Added:
cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp
Modified:
cfe/trunk/lib/CodeGen/CodeGenAction.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=288221=288220=288221=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Tue Nov 29 18:25:36 2016
@@ -53,6 +53,11 @@ namespace clang {
 Timer LLVMIRGeneration;
 unsigned LLVMIRGenerationRefCount;
 
+/// True if we've finished generating IR. This prevents us from generating
+/// additional LLVM IR after emitting output in HandleTranslationUnit. This
+/// can happen when Clang plugins trigger additional AST deserialization.
+bool IRGenFinished = false;
+
 std::unique_ptr Gen;
 
 SmallVector, 4>
@@ -147,6 +152,12 @@ namespace clang {
 LLVMIRGeneration.stopTimer();
 }
 
+void HandleInterestingDecl(DeclGroupRef D) {
+  // Ignore interesting decls from the AST reader after IRGen is finished.
+  if (!IRGenFinished)
+HandleTopLevelDecl(D);
+}
+
 void HandleTranslationUnit(ASTContext ) override {
   {
 PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
@@ -163,6 +174,8 @@ namespace clang {
   if (LLVMIRGenerationRefCount == 0)
 LLVMIRGeneration.stopTimer();
 }
+
+   IRGenFinished = true;
   }
 
   // Silently ignore if we weren't initialized for some reason.

Added: cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp?rev=288221=auto
==
--- cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp (added)
+++ cfe/trunk/test/Frontend/plugin-vs-debug-info.cpp Tue Nov 29 18:25:36 2016
@@ -0,0 +1,30 @@
+// This test uses PrintFunctionNames with -fdelayed-template-parsing because it
+// happens to use a RecursiveASTVisitor that forces deserialization of AST
+// files.
+//
+// RUN: %clang_cc1 -fdelayed-template-parsing -std=c++14 -emit-pch -o %t.pch %s
+// RUN: %clang_cc1 -load %llvmshlibdir/PrintFunctionNames%pluginext \
+// RUN: -add-plugin print-fns -std=c++14 -include-pch %t.pch %s -emit-llvm 
\
+// RUN: -fdelayed-template-parsing -debug-info-kind=limited \
+// RUN: -o %t.ll 2>&1 | FileCheck --check-prefix=DECLS %s
+// RUN: FileCheck --check-prefix=IR %s < %t.ll
+//
+// REQUIRES: plugins, examples
+
+// DECLS: top-level-decl: "func"
+
+// IR: define {{.*}}void @_Z4funcv()
+
+#ifndef HEADER
+#define HEADER
+
+struct nullopt_t {
+  constexpr explicit nullopt_t(int) {}
+};
+constexpr nullopt_t nullopt(0);
+
+#else
+
+void func() { }
+
+#endif


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


r288220 - [c++1z] Improve support for -fno-exceptions: we can't just ignore exception

2016-11-29 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Nov 29 18:13:55 2016
New Revision: 288220

URL: http://llvm.org/viewvc/llvm-project?rev=288220=rev
Log:
[c++1z] Improve support for -fno-exceptions: we can't just ignore exception
specifications in this mode in C++17, since they're part of the function type,
so check and diagnose them like we would if exceptions were enabled.

Better ideas welcome.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
cfe/trunk/test/SemaCXX/builtin-exception-spec.cpp
cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=288220=288219=288220=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Nov 29 18:13:55 
2016
@@ -1306,6 +1306,8 @@ def err_mismatched_exception_spec : Erro
   "exception specification in declaration does not match previous 
declaration">;
 def ext_mismatched_exception_spec : 
ExtWarn,
   InGroup;
+def warn_mismatched_exception_spec_no_exceptions : 
ExtWarn,
+  InGroup>;
 def err_override_exception_spec : Error<
   "exception specification of overriding function is more lax than "
   "base version">;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=288220=288219=288220=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Nov 29 18:13:55 2016
@@ -1330,11 +1330,7 @@ public:
   bool CheckEquivalentExceptionSpec(
   const PartialDiagnostic , const PartialDiagnostic & NoteID,
   const FunctionProtoType *Old, SourceLocation OldLoc,
-  const FunctionProtoType *New, SourceLocation NewLoc,
-  bool *MissingExceptionSpecification = nullptr,
-  bool *MissingEmptyExceptionSpecification = nullptr,
-  bool AllowNoexceptAllMatchWithNoSpec = false,
-  bool IsOperatorNew = false);
+  const FunctionProtoType *New, SourceLocation NewLoc);
   bool CheckExceptionSpecSubset(const PartialDiagnostic ,
 const PartialDiagnostic ,
 const PartialDiagnostic ,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=288220=288219=288220=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 18:13:55 2016
@@ -2949,15 +2949,6 @@ bool Sema::MergeFunctionDecl(FunctionDec
 // but do not necessarily update the type of New.
 if (CheckEquivalentExceptionSpec(Old, New))
   return true;
-// If exceptions are disabled, we might not have resolved the exception 
spec
-// of one or both declarations. Do so now in C++1z, so that we can properly
-// compare the types.
-if (getLangOpts().CPlusPlus1z) {
-  for (QualType T : {Old->getType(), New->getType()})
-if (auto *FPT = T->getAs())
-  if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType()))
-ResolveExceptionSpec(New->getLocation(), FPT);
-}
 OldQType = Context.getCanonicalType(Old->getType());
 NewQType = Context.getCanonicalType(New->getType());
 

Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=288220=288219=288220=diff
==
--- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Tue Nov 29 18:13:55 2016
@@ -207,6 +207,14 @@ Sema::UpdateExceptionSpec(FunctionDecl *
 Context.adjustExceptionSpec(cast(Redecl), ESI);
 }
 
+static bool CheckEquivalentExceptionSpecImpl(
+Sema , const PartialDiagnostic , const PartialDiagnostic ,
+const FunctionProtoType *Old, SourceLocation OldLoc,
+const FunctionProtoType *New, SourceLocation NewLoc,
+bool *MissingExceptionSpecification = nullptr,
+bool *MissingEmptyExceptionSpecification = nullptr,
+bool AllowNoexceptAllMatchWithNoSpec = false, bool IsOperatorNew = false);
+
 /// Determine whether a function has an implicitly-generated exception
 /// specification.
 static bool hasImplicitExceptionSpec(FunctionDecl *Decl) {
@@ -229,6 +237,12 @@ static bool hasImplicitExceptionSpec(Fun
 }
 
 bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
+  // Just completely ignore this under -fno-exceptions prior to C++1z.
+  // In C++1z 

[PATCH] D26657: [Sema] Respect DLL attributes more faithfully

2016-11-29 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Apologies for the delay. I was out last week.

In https://reviews.llvm.org/D26657#602083, @smeenai wrote:

> General coding style question. Over here, I'm creating a local helper 
> function. However, that helper needs to access member functions of Sema, 
> which is why I made it a private member function right now, which also 
> unfortunately makes the change somewhat non-local (since the header file 
> needs to be modified as well). I can think of two alternatives:
>
> - Define a local helper lambda (which will capture `this`) instead of a 
> private member function.
> - Define a local static helper function and pass the Sema instance as a 
> parameter so that it can call member functions on it.
>
>   Would either of those be preferable to what I currently have? I'm pretty 
> new when it comes to llvm/clang changes, so stylistic feedback is greatly 
> appreciated.


I usually prefer a static helper function and passing the Sema instance if it's 
possiblem, but that requires the Sema members we need to access to be public. 
If that's not the case, adding the helper as a member function is fine.




Comment at: include/clang/Sema/Sema.h:7494
 
+  /// \brief Make an existing DLL attribute on a class take effect.
+  void ActOnDLLAttr(ClassTemplateSpecializationDecl *Def,

Nit: I think `///` implies `\brief`, so we don't usually include it.



Comment at: include/clang/Sema/Sema.h:7495
+  /// \brief Make an existing DLL attribute on a class take effect.
+  void ActOnDLLAttr(ClassTemplateSpecializationDecl *Def,
+InheritableAttr *Attr);

I'd suggest making the function name more specific. It obviously doesn't apply 
to all DLL attributes, but only class templates.

Also, the "ActOn" methods in Sema are used as an interface to be called by the 
parser, so I would avoid that prefix.

Naming is hard :-/

Maybe `checkDllExportedTemplateSpecialization`



Comment at: lib/Sema/SemaTemplate.cpp:7439
+void Sema::ActOnDLLAttr(ClassTemplateSpecializationDecl *Def,
+InheritableAttr *Attr) {
+  // We reject explicit instantiations in class scope, so there should

This function only applies to dllexport, not dllimport, so it would be good if 
the name reflected that, and maybe we could also add an assert to check for it.



Comment at: lib/Sema/SemaTemplate.cpp:7710
+(Context.getTargetInfo().getCXXABI().isMicrosoft() ||
+ Context.getTargetInfo().getTriple().isWindowsItaniumEnvironment())) {
+  // In the MS ABI, an explicit instantiation definition can add a dll

Why the isWindowsItaniumEnvironment check? I'd expect checking for the MS ABI 
is sufficient?


https://reviews.llvm.org/D26657



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


r288213 - Fix some Clang-tidy and Include What You Use warnings; other minor fixes (NFC).

2016-11-29 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Tue Nov 29 16:44:24 2016
New Revision: 288213

URL: http://llvm.org/viewvc/llvm-project?rev=288213=rev
Log:
Fix some Clang-tidy and Include What You Use warnings; other minor fixes (NFC).

This preparation to remove SetVector.h dependency on SmallSet.h.

Modified:
cfe/trunk/include/clang/Lex/ModuleMap.h
cfe/trunk/utils/TableGen/NeonEmitter.cpp

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=288213=288212=288213=diff
==
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Tue Nov 29 16:44:24 2016
@@ -12,7 +12,6 @@
 //
 
//===--===//
 
-
 #ifndef LLVM_CLANG_LEX_MODULEMAP_H
 #define LLVM_CLANG_LEX_MODULEMAP_H
 
@@ -20,12 +19,18 @@
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include 
+#include 
 #include 
+#include 
 
 namespace clang {
 
@@ -41,7 +46,7 @@ class ModuleMapParser;
 /// reads module map files.
 class ModuleMapCallbacks {
 public:
-  virtual ~ModuleMapCallbacks() {}
+  virtual ~ModuleMapCallbacks() = default;
 
   /// \brief Called when a module map file has been read.
   ///
@@ -154,7 +159,7 @@ public:
   typedef llvm::SmallPtrSet AdditionalModMapsSet;
 
 private:
-  typedef llvm::DenseMap >
+  typedef llvm::DenseMap>
   HeadersMap;
 
   /// \brief Mapping from each header to the module that owns the contents of
@@ -549,5 +554,6 @@ public:
   module_iterator module_end()   const { return Modules.end(); }
 };
   
-}
-#endif
+} // end namespace clang
+
+#endif // LLVM_CLANG_LEX_MODULEMAP_H

Modified: cfe/trunk/utils/TableGen/NeonEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/NeonEmitter.cpp?rev=288213=288212=288213=diff
==
--- cfe/trunk/utils/TableGen/NeonEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/NeonEmitter.cpp Tue Nov 29 16:44:24 2016
@@ -24,22 +24,32 @@
 //
 
//===--===//
 
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/None.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.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/SetTheory.h"
-#include "llvm/TableGen/TableGenBackend.h"
 #include 
+#include 
+#include 
+#include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+
 using namespace llvm;
 
 namespace {
@@ -74,6 +84,7 @@ enum ClassKind {
 /// builtins.  These must be kept in sync with the flags in
 /// include/clang/Basic/TargetBuiltins.h.
 namespace NeonTypeFlags {
+
 enum { EltTypeMask = 0xf, UnsignedFlag = 0x10, QuadFlag = 0x20 };
 
 enum EltType {
@@ -89,12 +100,10 @@ enum EltType {
   Float32,
   Float64
 };
-}
 
-class Intrinsic;
+} // end namespace NeonTypeFlags
+
 class NeonEmitter;
-class Type;
-class Variable;
 
 
//===--===//
 // TypeSpec
@@ -190,6 +199,7 @@ public:
   //
   void makeUnsigned() { Signed = false; }
   void makeSigned() { Signed = true; }
+
   void makeInteger(unsigned ElemWidth, bool Sign) {
 Float = false;
 Poly = false;
@@ -197,6 +207,7 @@ public:
 Immediate = false;
 ElementBitwidth = ElemWidth;
   }
+
   void makeImmediate(unsigned ElemWidth) {
 Float = false;
 Poly = false;
@@ -204,18 +215,22 @@ public:
 Immediate = true;
 ElementBitwidth = ElemWidth;
   }
+
   void makeScalar() {
 Bitwidth = ElementBitwidth;
 NumVectors = 0;
   }
+
   void makeOneVector() {
 assert(isVector());
 NumVectors = 1;
   }
+
   void doubleLanes() {
 assert_with_loc(Bitwidth != 128, "Can't get bigger than 128!");
 Bitwidth = 128;
   }
+
   void halveLanes() {
 assert_with_loc(Bitwidth != 64, "Can't get smaller than 64!");
 Bitwidth = 64;
@@ -367,6 +382,7 @@ public:
   bool hasImmediate() const {
 return Proto.find('i') != std::string::npos;
   }
+
   /// Return the parameter index of the immediate operand.
   unsigned getImmediateIdx() const {
 assert(hasImmediate());
@@ -377,6 +393,7 @@ public:
 
   /// Return true if the 

r288208 - [c++1z] PR31210: ignore exception specification when matching the type of a

2016-11-29 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Nov 29 16:32:05 2016
New Revision: 288208

URL: http://llvm.org/viewvc/llvm-project?rev=288208=rev
Log:
[c++1z] PR31210: ignore exception specification when matching the type of a
builtin with the type of an explicit declaration of the same function.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=288208=288207=288208=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 16:32:05 2016
@@ -9028,9 +9028,25 @@ bool Sema::CheckFunctionDeclaration(Scop
   LookupPredefedObjCSuperType(*this, S, NewFD->getIdentifier());
   QualType T = Context.GetBuiltinType(BuiltinID, Error);
   if (!T.isNull() && !Context.hasSameType(T, NewFD->getType())) {
-// The type of this function differs from the type of the builtin,
-// so forget about the builtin entirely.
-Context.BuiltinInfo.forgetBuiltin(BuiltinID, Context.Idents);
+auto WithoutExceptionSpec = [&](QualType T) -> QualType {
+  auto *Proto = T->getAs();
+  if (!Proto)
+return T;
+  return Context.getFunctionType(
+  Proto->getReturnType(), Proto->getParamTypes(),
+  Proto->getExtProtoInfo().withExceptionSpec(EST_None));
+};
+
+// If the type of the builtin differs only in its exception
+// specification, that's OK.
+// FIXME: If the types do differ in this way, it would be better to
+// retain the 'noexcept' form of the type.
+if (!getLangOpts().CPlusPlus1z ||
+!Context.hasSameType(WithoutExceptionSpec(T),
+ WithoutExceptionSpec(NewFD->getType(
+  // The type of this function differs from the type of the builtin,
+  // so forget about the builtin entirely.
+  Context.BuiltinInfo.forgetBuiltin(BuiltinID, Context.Idents);
   }
 }
 

Modified: cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp?rev=288208=288207=288208=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp Tue Nov 29 16:32:05 
2016
@@ -97,3 +97,13 @@ namespace ImplicitExceptionSpec {
   };
   S::~S() {}
 }
+
+namespace Builtins {
+  // Pick two functions that ought to have the same noexceptness.
+  extern "C" int strcmp(const char *, const char *);
+  extern "C" int strncmp(const char *, const char *, decltype(sizeof(0))) 
noexcept;
+
+  // Check we recognized both as builtins.
+  typedef int arr[strcmp("bar", "foo") + 4 * strncmp("foo", "bar", 4)];
+  typedef int arr[3];
+}


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


r288207 - Don't try to merge DLL attributes on redeclaration of invalid decl (PR31069)

2016-11-29 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Tue Nov 29 16:31:00 2016
New Revision: 288207

URL: http://llvm.org/viewvc/llvm-project?rev=288207=rev
Log:
Don't try to merge DLL attributes on redeclaration of invalid decl (PR31069)

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/dllimport.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=288207=288206=288207=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 16:31:00 2016
@@ -5651,6 +5651,9 @@ static void checkDLLAttributeRedeclarati
NamedDecl *NewDecl,
bool IsSpecialization,
bool IsDefinition) {
+  if(OldDecl->isInvalidDecl())
+return;
+
   if (TemplateDecl *OldTD = dyn_cast(OldDecl)) {
 OldDecl = OldTD->getTemplatedDecl();
 if (!IsSpecialization)

Modified: cfe/trunk/test/Sema/dllimport.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/dllimport.c?rev=288207=288206=288207=diff
==
--- cfe/trunk/test/Sema/dllimport.c (original)
+++ cfe/trunk/test/Sema/dllimport.c Tue Nov 29 16:31:00 2016
@@ -210,6 +210,10 @@ __declspec(dllimport) void redecl6();
   void redecl7();
 __declspec(dllimport) inline void redecl7() {}
 
+// PR31069: Don't crash trying to merge attributes for redeclaration of 
invalid decl.
+void __declspec(dllimport) redecl8(unknowntype X); // expected-error{{unknown 
type name 'unknowntype'}}
+void redecl8(unknowntype X) { } // expected-error{{unknown type name 
'unknowntype'}}
+
 // External linkage is required.
 __declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' 
must have external linkage when declared 'dllimport'}}
 


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


[PATCH] D27207: Adds hasUnqualifiedDesugaredType to allow matching through type sugar.

2016-11-29 Thread Ɓukasz Anforowicz via Phabricator via cfe-commits
lukasza added inline comments.



Comment at: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:253
+  matches("struct A {}; using B = A; B b;",
+  varDecl(hasType(hasUnqualifiedDesugaredType(recordType());
+}

# deep testing suggestion

If we do end up landing the implementation of hasUnqualifiedDesugaredType from 
this CL, then I think it might be good to tweak the test so that it verifies 
that the matching here is "deep" (i.e. that the matcher doesn't just strip a 
single level of sugar).

matches("struct A {}; using B = A; using C = B; C c;", ...


# deep-vs-shallow-vs-everythingInBetween

At one point, when discussing the old implementation of hasDeclaration (before 
https://reviews.llvm.org/D27104) we were wondering whether it should match for 
all the cases below:

std::string input = "struct A {}; using B = A; using C = B; using D = C; D 
d;";
EXPECT_TRUE(matches(input,

varDecl(...something-hasDeclaration-something...(typeAliasDecl(hasName("B"));
EXPECT_TRUE(matches(input,

varDecl(...something-hasDeclaration-something...(typeAliasDecl(hasName("C"));
EXPECT_TRUE(matches(input,

varDecl(...something-hasDeclaration-something...(typeAliasDecl(hasName("D"));

This is not something I want or care about myself, but I wanted to check if the 
above is something to think about.  For example - maybe exposing a 
singleStepDesugarsTo(...) matcher is better (because it can be used to build 
the hasUnqualifiedDesugaredType).

As I said - this is not very important to me (I only care about full desugaring 
all the way to a tag type), but it might be something to ponder before 
committing to the current implementation of hasUnqualifiedDesugaredType.


https://reviews.llvm.org/D27207



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


[PATCH] D27207: Adds hasUnqualifiedDesugaredType to allow matching through type sugar.

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D27207#608433, @lukasza wrote:

> I think the above will work for my tool - thank you for providing the matcher 
> example (for some reason I incorrectly thought that desugaring would only be 
> done one step a time - this made me think that matching at an arbitrary depth 
> will require tricky things to build a recursive matcher out of a single-step 
> matcher).


clang-tidy's modernize-use-auto check has a matcher that desugars one step at a 
time:
https://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp;288204$69


https://reviews.llvm.org/D27207



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


[PATCH] D27207: Adds hasUnqualifiedDesugaredType to allow matching through type sugar.

2016-11-29 Thread Ɓukasz Anforowicz via Phabricator via cfe-commits
lukasza added a comment.

I've tried replicating the deep-matching by saying 
qualType(hasType(hasUnqualifiedDesugaredType(hasDeclaration(... but this 
doesn't work because hasDeclaration only returns a matcher for a specific type 
from a subset of subclasses of Type - this is incompatible with expectations of 
the proposed hasUnqualifiedDesugaredType which takes a Matcher.

FWIW, the following matcher worked for me:

  AST_MATCHER_P(Type, hasUnqualifiedDesugaredType, internal::Matcher,
InnerMatcher) {
const Type* type = Node.getUnqualifiedDesugaredType();
QualType qualType(type, 0);
return InnerMatcher.matches(qualType, Finder, Builder);
  }
  
  TEST(HasDeclaration, DeepTagType) {
std::string input =
"class Foo {};\n"
"using Bar = Foo;\n"
"using Baz = Bar;\n"
"void Function(Baz param) {}\n";
  
// Matcher for declaration of the Foo class.
auto param_type_decl_matcher = cxxRecordDecl(hasName("Foo"));
  
auto m1 = qualType(hasDeclaration(decl(param_type_decl_matcher)));
// hasDeclaration / qualType-flavour.
EXPECT_TRUE(matches(input, parmVarDecl(
hasName("param"),
hasType(hasUnqualifiedDesugaredType(m1);
  }

I think the above will work for my tool - thank you for providing the matcher 
example (for some reason I incorrectly thought that desugaring would only be 
done one step a time - this made me think that matching at an arbitrary depth 
will require tricky things to build a recursive matcher out of a single-step 
matcher).

BTW: Please note that I am fine with just copy the matcher above 
directly into my tool - I don't necessarily need this matcher to be part of the 
generic library of matchers.  I don't have high confidence that the matcher 
here is 1) applicable broadly (maybe) and 2) what to do about the Type vs 
QualType issue (yes, it says "unqualified" right in the name, but then it means 
that it cannot be used with hasDeclaration...).


https://reviews.llvm.org/D27207



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


r288203 - getObjCEncodingForMethodDecl cannot fail. Simplify. NFC.

2016-11-29 Thread John McCall via cfe-commits
Author: rjmccall
Date: Tue Nov 29 15:57:00 2016
New Revision: 288203

URL: http://llvm.org/viewvc/llvm-project?rev=288203=rev
Log:
getObjCEncodingForMethodDecl cannot fail.  Simplify.  NFC.

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=288203=288202=288203=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Nov 29 15:57:00 2016
@@ -1617,16 +1617,15 @@ public:
   ///
   /// \returns true if an error occurred (e.g., because one of the parameter
   /// types is incomplete), false otherwise.
-  bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& 
S);
+  std::string getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const;
 
   /// \brief Emit the encoded type for the method declaration \p Decl into
   /// \p S.
   ///
   /// \returns true if an error occurred (e.g., because one of the parameter
   /// types is incomplete), false otherwise.
-  bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string ,
-bool Extended = false)
-const;
+  std::string getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
+   bool Extended = false) const;
 
   /// \brief Return the encoded type for this block declaration.
   std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
@@ -1635,9 +1634,8 @@ public:
   /// this method declaration. If non-NULL, Container must be either
   /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
   /// only be NULL when getting encodings for protocol properties.
-  void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
-  const Decl *Container,
-  std::string ) const;
+  std::string getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
+ const Decl *Container) const;
 
   bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
   ObjCProtocolDecl *rProto) const;

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=288203=288202=288203=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Nov 29 15:57:00 2016
@@ -5578,8 +5578,9 @@ std::string ASTContext::getObjCEncodingF
   return S;
 }
 
-bool ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl,
-std::string& S) {
+std::string
+ASTContext::getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const {
+  std::string S;
   // Encode result type.
   getObjCEncodingForType(Decl->getReturnType(), S);
   CharUnits ParmOffset;
@@ -5590,8 +5591,8 @@ bool ASTContext::getObjCEncodingForFunct
 if (sz.isZero())
   continue;
  
-assert (sz.isPositive() && 
-"getObjCEncodingForFunctionDecl - Incomplete param type");
+assert(sz.isPositive() && 
+   "getObjCEncodingForFunctionDecl - Incomplete param type");
 ParmOffset += sz;
   }
   S += charUnitsToString(ParmOffset);
@@ -5613,7 +5614,7 @@ bool ASTContext::getObjCEncodingForFunct
 ParmOffset += getObjCEncodingTypeSize(PType);
   }
   
-  return false;
+  return S;
 }
 
 /// getObjCEncodingForMethodParameter - Return the encoded type for a single
@@ -5635,11 +5636,11 @@ void ASTContext::getObjCEncodingForMetho
 
 /// getObjCEncodingForMethodDecl - Return the encoded type for this method
 /// declaration.
-bool ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl,
-  std::string& S, 
-  bool Extended) const {
+std::string ASTContext::getObjCEncodingForMethodDecl(const ObjCMethodDecl 
*Decl,
+ bool Extended) const {
   // FIXME: This is not very efficient.
   // Encode return type.
+  std::string S;
   getObjCEncodingForMethodParameter(Decl->getObjCDeclQualifier(),
 Decl->getReturnType(), S, Extended);
   // Compute size of all parameters.
@@ -5685,7 +5686,7 @@ bool ASTContext::getObjCEncodingForMetho
 ParmOffset += getObjCEncodingTypeSize(PType);
   }
   
-  return false;
+  return S;
 }
 
 ObjCPropertyImplDecl *
@@ -5733,9 +5734,9 @@ 

[PATCH] D27104: Unify and simplify the behavior of the hasDeclaration matcher.

2016-11-29 Thread Ɓukasz Anforowicz via Phabricator via cfe-commits
lukasza added a comment.

Do we also need to update the documentation (e.g. to say that ElaboratedType is 
covered by hasDeclaration)?

Other than that, I think this CL LGTM, although I would like to have a 
specific, working equivalent of the old, deep-maching hasDeclaration (at least 
when the inner, deep match is for tag types).  Let's continue this discussion 
in https://reviews.llvm.org/D27207


https://reviews.llvm.org/D27104



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


Re: Embedded Bitcode in Object Files

2016-11-29 Thread Steven Wu via cfe-commits
Thanks for reviewing the patches. And yes, 3 and 4 are no longer useful. I am 
seeking better alternatives to achieve them.

Steven 

> On Nov 30, 2016, at 1:35 AM, Nico Weber  wrote:
> 
> It looks like patches 1 and  2 made it but 3 and 4 didn't. Do you no longer 
> need them?
> 
>> On Mon, Feb 29, 2016 at 2:08 PM, Steven Wu via cfe-commits 
>>  wrote:
>> Ping. I don't know who is the best review for the patches. Thanks for Rafael 
>> looking at the LLVM change. Richard, do you have any opinions on the clang 
>> changes?
>> 
>> Thanks
>> 
>> Steven
>> 
>> > On Feb 18, 2016, at 9:57 AM, Steven Wu  wrote:
>> >
>> > Hi all
>> >
>> > I put up some patches for embedding bitcode inside the object file 
>> > (-fembed-bitcode) option. As I described in the dev list before, the new 
>> > option can create normal object file with bitcode embedded in a special 
>> > section. You can easily recreate the same object file with the embedded 
>> > bitcode in it.
>> >
>> > I split the patch into several parts:
>> > llvm patch:
>> > http://reviews.llvm.org/D17388: Introduce the section for embedding 
>> > bitcode in MachO file.
>> >
>> > There are four clang patches:
>> > http://reviews.llvm.org/D17390: Implementing the clang driver for the new 
>> > option.
>> > http://reviews.llvm.org/D17392: Teach clang how to embed bitcode into the 
>> > object file.
>> > http://reviews.llvm.org/D17393: Slightly tweak the bitcode emitted in 
>> > embed bitcode stage 1.
>> > http://reviews.llvm.org/D17394: Reduce the amount of option gets embedded 
>> > in the bitcode by introducing a whitelist and a blacklist.
>> >
>> > Let me know if anyone is interested in helping reviewing these changes.
>> >
>> > Thanks
>> >
>> > Steven
>> >
>> >
>> >
>> 
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection

2016-11-29 Thread Greg Bedwell via Phabricator via cfe-commits
gbedwell added a comment.

In https://reviews.llvm.org/D25435#608348, @danielcdh wrote:

> Change the flag to -fprof-debug, which is more concise. The flag name is 
> still open for discussion.


Well, since I have permission to bikeshed... :)

I'd prefer to have 'profile' rather than 'prof' in the name.  This fits the 
established convention with -fprofile-sample-use etc.


https://reviews.llvm.org/D25435



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


[PATCH] D27226: [MS ABI] Implement more of the Itanium mangling rules

2016-11-29 Thread David Majnemer via Phabricator via cfe-commits
majnemer created this revision.
majnemer added a reviewer: rnk.
majnemer added a subscriber: cfe-commits.

We didn't implement one of the corner cases: a lambda which belongs to
an initializer for a field.  In this case, we need to mangle the field
name into the lambda.

This fixes PR31197.


https://reviews.llvm.org/D27226

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/mangle-ms-cxx11.cpp


Index: test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -318,3 +318,20 @@
 
 // CHECK-DAG: @"\01?unaligned_foo8@unaligned_foo8_S@@QFCEXXZ"
 
+namespace PR31197 {
+struct A {
+  // CHECK-DAG: define linkonce_odr x86_thiscallcc i32* 
@"\01??R@x@A@PR31197@@QBE@XZ"(
+  int *x = []() {
+static int white;
+// CHECK-DAG: @"\01?white@?1???R@x@A@PR31197@@QBE@XZ@4HA"
+return 
+  }();
+  // CHECK-DAG: define linkonce_odr x86_thiscallcc i32* 
@"\01??R@y@A@PR31197@@QBE@XZ"(
+  int *y = []() {
+static int black;
+// CHECK-DAG: @"\01?black@?1???R@y@A@PR31197@@QBE@XZ@4HA"
+return 
+  }();
+};
+A a;
+}
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -824,16 +824,28 @@
   if (const CXXRecordDecl *Record = dyn_cast(TD)) {
 if (Record->isLambda()) {
   llvm::SmallString<10> Name("getLambdaManglingNumber();
   unsigned LambdaId;
-  if (Record->getLambdaManglingNumber())
-LambdaId = Record->getLambdaManglingNumber();
+  if (LambdaManglingNumber)
+LambdaId = LambdaManglingNumber;
   else
 LambdaId = Context.getLambdaId(Record);
 
   Name += llvm::utostr(LambdaId);
   Name += ">";
 
   mangleSourceName(Name);
+
+  // If the context of a closure type is an initializer for a class
+  // member (static or nonstatic), it is encoded in a qualified name.
+  if (LambdaManglingNumber) {
+if (Decl *Context = Record->getLambdaContextDecl()) {
+  if ((isa(Context) || isa(Context)) &&
+  Context->getDeclContext()->isRecord()) {
+mangleUnqualifiedName(cast(Context));
+  }
+}
+  }
   break;
 }
   }


Index: test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -318,3 +318,20 @@
 
 // CHECK-DAG: @"\01?unaligned_foo8@unaligned_foo8_S@@QFCEXXZ"
 
+namespace PR31197 {
+struct A {
+  // CHECK-DAG: define linkonce_odr x86_thiscallcc i32* @"\01??R@x@A@PR31197@@QBE@XZ"(
+  int *x = []() {
+static int white;
+// CHECK-DAG: @"\01?white@?1???R@x@A@PR31197@@QBE@XZ@4HA"
+return 
+  }();
+  // CHECK-DAG: define linkonce_odr x86_thiscallcc i32* @"\01??R@y@A@PR31197@@QBE@XZ"(
+  int *y = []() {
+static int black;
+// CHECK-DAG: @"\01?black@?1???R@y@A@PR31197@@QBE@XZ@4HA"
+return 
+  }();
+};
+A a;
+}
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -824,16 +824,28 @@
   if (const CXXRecordDecl *Record = dyn_cast(TD)) {
 if (Record->isLambda()) {
   llvm::SmallString<10> Name("getLambdaManglingNumber();
   unsigned LambdaId;
-  if (Record->getLambdaManglingNumber())
-LambdaId = Record->getLambdaManglingNumber();
+  if (LambdaManglingNumber)
+LambdaId = LambdaManglingNumber;
   else
 LambdaId = Context.getLambdaId(Record);
 
   Name += llvm::utostr(LambdaId);
   Name += ">";
 
   mangleSourceName(Name);
+
+  // If the context of a closure type is an initializer for a class
+  // member (static or nonstatic), it is encoded in a qualified name.
+  if (LambdaManglingNumber) {
+if (Decl *Context = Record->getLambdaContextDecl()) {
+  if ((isa(Context) || isa(Context)) &&
+  Context->getDeclContext()->isRecord()) {
+mangleUnqualifiedName(cast(Context));
+  }
+}
+  }
   break;
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 79632.
malcolm.parsons added a comment.

Add to release notes


https://reviews.llvm.org/D27166

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- test/clang-tidy/modernize-use-auto-cast.cpp
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -138,3 +138,72 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U );
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T _reference_cast(U );
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T _const_reference_cast(const U );
+
+template 
+T template_value_get(StringRef s);
+
+struct S {
+  template 
+  const T *template_member_get();
+};
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = template_value_cast(a);
+  B  = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b3 = template_pointer_cast(a);
+  B  = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  = template_reference_cast(*a);
+  const B *b5 = template_const_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b5 = template_const_pointer_cast(a);
+  const B  = template_const_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto  = template_const_reference_cast(*a);
+  B *b7 = template_value_get("foo");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b7 = template_value_get("foo");
+
+  S s;
+  const B *b8 = s.template_member_get();
+
+  auto i2 = template_value_cast(d);
+  int i3 = max(i1, i2);
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -136,3 +136,64 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U );
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T _reference_cast(U );
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T _const_reference_cast(const U );
+
+template 
+T template_value_get(StringRef s);
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b1 = template_value_cast(a);
+  B  = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto   = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b3 = template_pointer_cast(a);
+  B  = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto   = template_reference_cast(*a);
+  const B *b5 = 

[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-11-29 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In https://reviews.llvm.org/D27166#608339, @malcolm.parsons wrote:

> In https://reviews.llvm.org/D27166#606772, @Eugene.Zelenko wrote:
>
> > It'll be worth to mention enhancement in Release Notes.
>
>
> They already say this:
>
> - The `modernize-use-auto 
> `_ 
> check now warns about variable declarations that are initialized with a cast.
>
>   Does that cover it?


I'm not very sure, because cats may be interpreted as C++ language constructs 
only, but not framework provided ones.


https://reviews.llvm.org/D27166



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


[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection

2016-11-29 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh updated this revision to Diff 79629.
danielcdh marked an inline comment as done.
danielcdh added a comment.

Change the flag to -fprof-debug, which is more concise. The flag name is still 
open for discussion.


https://reviews.llvm.org/D25435

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGDebugInfo.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_f_opts.c


Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -469,3 +469,8 @@
 // CHECK-WCHAR2: -fshort-wchar
 // CHECK-WCHAR2-NOT: -fno-short-wchar
 // DELIMITERS: {{^ *"}}
+
+// RUN: %clang -### -S -fno-prof-debug -fprof-debug %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROF-DEBUG %s
+// RUN: %clang -### -S -fprof-debug -fno-prof-debug %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-PROF-DEBUG %s
+// CHECK-PROF-DEBUG: -fprof-debug
+// CHECK-NO-PROF-DEBUG-NOT: -fprof-debug
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -538,6 +538,7 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
+  Opts.ProfDebug = Args.hasFlag(OPT_fprof_debug, OPT_fno_prof_debug, false);
 
   setPGOInstrumentor(Opts, Args, Diags);
   Opts.InstrProfileOutput =
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5508,6 +5508,10 @@
   A->render(Args, CmdArgs);
   }
 
+  if (Args.hasFlag(options::OPT_fprof_debug,
+   options::OPT_fno_prof_debug, false))
+CmdArgs.push_back("-fprof-debug");
+
   // -fbuiltin is default unless -mkernel is used.
   bool UseBuiltins =
   Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -2739,9 +2739,10 @@
   }
   // No need to replicate the linkage name if it isn't different from the
   // subprogram name, no need to have it at all unless coverage is enabled or
-  // debug is set to more than just line tables.
+  // debug is set to more than just line tables or extra debug info is needed.
   if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs &&
   !CGM.getCodeGenOpts().EmitGcovNotes &&
+  !CGM.getCodeGenOpts().ProfDebug &&
   DebugKind <= 
codegenoptions::DebugLineTablesOnly))
 LinkageName = StringRef();
 
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -256,6 +256,9 @@
 /// Whether copy relocations support is available when building as PIE.
 CODEGENOPT(PIECopyRelocations, 1, 0)
 
+/// Whether emit extra debug info for sample pgo profile collection.
+CODEGENOPT(ProfDebug, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -509,6 +509,12 @@
 HelpText<"Enable sample-based profile guided optimizations">;
 def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
 Alias;
+def fprof_debug : Flag<["-"], "fprof-debug">, Group,
+Flags<[CC1Option]>,
+HelpText<"Emit extra debug info to make sample profile more accurate.">;
+def fno_prof_debug : Flag<["-"], "fno-prof-debug">, Group,
+Flags<[DriverOption]>,
+HelpText<"Do not emit extra debug info for sample profiler.">;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Flags<[DriverOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overriden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -469,3 +469,8 @@
 // CHECK-WCHAR2: -fshort-wchar
 // CHECK-WCHAR2-NOT: -fno-short-wchar
 // DELIMITERS: {{^ *"}}
+
+// RUN: %clang -### -S -fno-prof-debug -fprof-debug %s 2>&1 | FileCheck -check-prefix=CHECK-PROF-DEBUG %s
+// RUN: %clang -### -S -fprof-debug -fno-prof-debug %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROF-DEBUG %s
+// CHECK-PROF-DEBUG: -fprof-debug
+// CHECK-NO-PROF-DEBUG-NOT: -fprof-debug
Index: lib/Frontend/CompilerInvocation.cpp

[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons marked an inline comment as done.
malcolm.parsons added a comment.

In https://reviews.llvm.org/D27166#606772, @Eugene.Zelenko wrote:

> It'll be worth to mention enhancement in Release Notes.


They already say this:

- The `modernize-use-auto 
`_ check 
now warns about variable declarations that are initialized with a cast.

Does that cover it?


https://reviews.llvm.org/D27166



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


[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 79627.
malcolm.parsons added a comment.

Handle templated member functions too.


https://reviews.llvm.org/D27166

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- test/clang-tidy/modernize-use-auto-cast.cpp
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -138,3 +138,72 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U );
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T _reference_cast(U );
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T _const_reference_cast(const U );
+
+template 
+T template_value_get(StringRef s);
+
+struct S {
+  template 
+  const T *template_member_get();
+};
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = template_value_cast(a);
+  B  = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b3 = template_pointer_cast(a);
+  B  = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  = template_reference_cast(*a);
+  const B *b5 = template_const_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b5 = template_const_pointer_cast(a);
+  const B  = template_const_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto  = template_const_reference_cast(*a);
+  B *b7 = template_value_get("foo");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b7 = template_value_get("foo");
+
+  S s;
+  const B *b8 = s.template_member_get();
+
+  auto i2 = template_value_cast(d);
+  int i3 = max(i1, i2);
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -136,3 +136,64 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U );
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T _reference_cast(U );
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T _const_reference_cast(const U );
+
+template 
+T template_value_get(StringRef s);
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b1 = template_value_cast(a);
+  B  = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto   = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b3 = template_pointer_cast(a);
+  B  = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto   = template_reference_cast(*a);
+  const B *b5 = template_const_pointer_cast(a);

[PATCH] D26979: Do not hard-code locale data in unit tests: get it from the OS instead

2016-11-29 Thread Eric van Gyzen via Phabricator via cfe-commits
vangyzen added a comment.

@EricWF Do you have time and interest to review this again?


https://reviews.llvm.org/D26979



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 79624.
madsravn added a comment.

Updated per comments


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringCompareCheck.cpp
  clang-tidy/misc/StringCompareCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,29 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+#include 
+
+void Test() {
+  std::string str1{"a"};
+  std::string str2{"b"};
+
+  if(str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(!str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) == 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) != 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(0 == str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(0 != str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+
+}
+
+void Valid() {
+std::string str1{"a"};
+std::string str2{"b"};
+if(str1 == str2) {}
+if(str1 != str2) {}
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===
+
+Finds string comparisons using the compare method.
+
+A common mistake is to use the string's ``compare`` method instead of using the 
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns ``-1``, ``0`` or ``1`` depending on the lexicographical 
+relationship between the strings compared. If an equality or inequality check
+can suffice, that is recommended.
+
+Examples:
+
+.. code-block:: c++
+
+  std::string str1{"a"};
+  std::string str2{"b"};
+  
+  if(str1.compare(str2)) {} // use str1 != str2 instead
+  
+  if(!str1.compare(str2)) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) == 0) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) != 0) {} // use str1 != str2 instead
+
+  if(0 == str1.compare(str2)) {} // use str1 == str2 instead
+
+  if(0 != str1.compare(str2)) {} // use str1 != str2 instead
+
+The above code examples shows the list of if-statements that this check will
+give a warning for. All of them uses ``compare`` to check if equality or 
+inequality of two strings instead of using the correct operators.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -80,6 +80,7 @@
misc-sizeof-container
misc-sizeof-expression
misc-static-assert
+   misc-string-compare
misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -75,6 +75,11 @@
 
 - `misc-pointer-and-integral-operation` check was removed.
 
+- New `misc-string-compare
+  `_ check
+
+  Warns about using ``compare`` to test for string equality or ineqaulity.
+
 - New `misc-use-after-move
   `_ check
 
Index: clang-tidy/misc/StringCompareCheck.h
===
--- clang-tidy/misc/StringCompareCheck.h
+++ clang-tidy/misc/StringCompareCheck.h
@@ -0,0 +1,36 @@
+//===--- StringCompareCheck.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.
+//

[PATCH] D26920: [libc++] Add validation to Stage 2 of num_get

2016-11-29 Thread Eric van Gyzen via Phabricator via cfe-commits
vangyzen updated this revision to Diff 79625.
vangyzen added a comment.
Herald added a subscriber: emaste.

Restore support for a sign character preceding a "nan"

I accidentally broke +nan and -nan.  Add unit test cases for these,
and update my change to support them.


https://reviews.llvm.org/D26920

Files:
  include/locale
  
test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_double.pass.cpp

Index: test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_double.pass.cpp
===
--- test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_double.pass.cpp
+++ test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_double.pass.cpp
@@ -136,6 +136,30 @@
 assert(v == INFINITY);
 }
 {
+const char str[] = "+Inf";
+hex(ios);
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(iter.base() == str+sizeof(str)-1);
+assert(err == ios.goodbit);
+assert(v == INFINITY);
+}
+{
+const char str[] = "+iNF";
+hex(ios);
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(iter.base() == str+sizeof(str)-1);
+assert(err == ios.goodbit);
+assert(v == INFINITY);
+}
+{
 const char str[] = "-inf";
 hex(ios);
 std::ios_base::iostate err = ios.goodbit;
@@ -184,6 +208,30 @@
 assert(std::isnan(v));
 }
 {
+const char str[] = "+NaN";
+hex(ios);
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(iter.base() == str+sizeof(str)-1);
+assert(err == ios.goodbit);
+assert(std::isnan(v));
+}
+{
+const char str[] = "-nAn";
+hex(ios);
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(iter.base() == str+sizeof(str)-1);
+assert(err == ios.goodbit);
+assert(std::isnan(v));
+}
+{
 v = -1;
 const char str[] = "123_456_78_9;125";
 std::ios_base::iostate err = ios.goodbit;
@@ -208,6 +256,19 @@
 assert(v == 2);
 }
 {
+// http://cplusplus.github.io/LWG/lwg-active.html#2381
+v = -1;
+const char str[] = "0x1a.bp+07p";
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(err == ios.goodbit);
+assert(iter.base() == str+sizeof(str)-2);
+assert(v == 0x1a.bp+07);
+}
+{
 v = -1;
 const char str[] = "1.79779e+309"; // unrepresentable
 std::ios_base::iostate err = ios.goodbit;
Index: include/locale
===
--- include/locale
+++ include/locale
@@ -505,17 +505,67 @@
 return -1;
 }
 if (__x == 'x' || __x == 'X')
-__exp = 'P';
+{
+unsigned __sign = (*__a == '-') + (*__a == '+');
+if (__a_end == __a + __sign + 1 && __a[__sign] == '0')
+__exp = 'P';
+else
+return -1;
+}
 else if ((__x & 0x5F) == __exp)
 {
+if (__exp & 0x80)
+return -1;
 __exp |= 0x80;
 if (__in_units)
 {
 __in_units = false;
 if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
 *__g_end++ = __dc;
 }
 }
+else if (__f > 9)
+{
+if (__x == 'P' || __x == 'p')
+return -1;
+unsigned __sign = (*__a == '-') + (*__a == '+');
+if (__x == 'I' || __x == 'i')
+{
+if (__a_end != __a + __sign)// start of Inf
+return -1;
+}
+else if (__x == 'N' || __x == 'n')
+{
+bool __ok =
+(__a_end == __a + __sign)   // start of NaN
+||
+(__a_end == __a + __sign + 2 && // end of NaN
+(__a[__sign  ] & 0x5F) == 'N' &&
+(__a[__sign+1] & 0x5F) == 'A')
+||
+(__a_end == __a + __sign + 1 && // middle of Inf
+

r288197 - Don't declare IsEnumDeclComplete as extern

2016-11-29 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Nov 29 14:46:24 2016
New Revision: 288197

URL: http://llvm.org/viewvc/llvm-project?rev=288197=rev
Log:
Don't declare IsEnumDeclComplete as extern

Otherwise MSVC and clang-cl will see "extern inline" after merging
redeclarations and emit it in all TUs that include Type.h and Decl.h.

Noticed by inspection, since it's always the first thing to get emitted.

Modified:
cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=288197=288196=288197=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Nov 29 14:46:24 2016
@@ -5805,8 +5805,8 @@ inline bool Type::isNullPtrType() const
   return false;
 }
 
-extern bool IsEnumDeclComplete(EnumDecl *);
-extern bool IsEnumDeclScoped(EnumDecl *);
+bool IsEnumDeclComplete(EnumDecl *);
+bool IsEnumDeclScoped(EnumDecl *);
 
 inline bool Type::isIntegerType() const {
   if (const BuiltinType *BT = dyn_cast(CanonicalType))


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


[PATCH] D27049: [OpenCL] Refactor out ReadPipe/WritePipe

2016-11-29 Thread Yaron Keren via Phabricator via cfe-commits
yaron.keren accepted this revision.
yaron.keren added a comment.
This revision is now accepted and ready to land.

LGTM after fixing the inline comment




Comment at: lib/Serialization/ASTReader.cpp:5804
 QualType ElementType = readType(*Loc.F, Record, Idx);
-return Context.getReadPipeType(ElementType);
+unsigned ReadOnly = Record[1];
+if (ReadOnly)

  return Context,getPipeType(ElementType, ReadOnly)



Repository:
  rL LLVM

https://reviews.llvm.org/D27049



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

Please run clang-format on all new files.




Comment at: test/clang-tidy/misc-string-compare.cpp:3
+
+#include 
+

clang-tidy tests don't #include system headers.
Declare the bits you need instead.
See test/clang-tidy/misc-string-constructor.cpp for an example.



Comment at: test/clang-tidy/misc-string-compare.cpp:9
+
+  if(str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test 
equality of strings; use the string equality operator instead 
[misc-string-compare]

Some other test ideas:

```
if (str1.compare("foo")) {}

return str1.compare(str2) == 0;

func(str1.compare(str2) != 0);

if (str2.empty() || str1.compare(str2) != 0) {}
```


https://reviews.llvm.org/D27210



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


r288193 - Support constant expression evaluation for wchar_t versions of simple string

2016-11-29 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Nov 29 13:45:17 2016
New Revision: 288193

URL: http://llvm.org/viewvc/llvm-project?rev=288193=rev
Log:
Support constant expression evaluation for wchar_t versions of simple string
functions, in order to support constexpr std::char_traits.

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constexpr-string.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=288193=288192=288193=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Nov 29 13:45:17 2016
@@ -29,6 +29,7 @@
 //  f -> float
 //  d -> double
 //  z -> size_t
+//  w -> wchar_t
 //  F -> constant CFString
 //  G -> id
 //  H -> SEL
@@ -456,6 +457,12 @@ BUILTIN(__builtin_strpbrk, "c*cC*cC*", "
 BUILTIN(__builtin_strrchr, "c*cC*i", "nF")
 BUILTIN(__builtin_strspn, "zcC*cC*", "nF")
 BUILTIN(__builtin_strstr, "c*cC*cC*", "nF")
+BUILTIN(__builtin_wcschr, "w*wC*w", "nF")
+BUILTIN(__builtin_wcscmp, "iwC*wC*", "nF")
+BUILTIN(__builtin_wcslen, "zwC*", "nF")
+BUILTIN(__builtin_wcsncmp, "iwC*wC*z", "nF")
+BUILTIN(__builtin_wmemchr, "w*wC*wz", "nF")
+BUILTIN(__builtin_wmemcmp, "iwC*wC*z", "nF")
 BUILTIN(__builtin_return_address, "v*IUi", "n")
 BUILTIN(__builtin_extract_return_addr, "v*v*", "n")
 BUILTIN(__builtin_frame_address, "v*IUi", "n")
@@ -830,6 +837,15 @@ LIBBUILTIN(isupper, "ii", "fnU", "ctype.
 LIBBUILTIN(isxdigit, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
 LIBBUILTIN(tolower, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
 LIBBUILTIN(toupper, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
+// C99 wchar.h
+// FIXME: This list is incomplete. We should cover at least the functions that
+// take format strings.
+LIBBUILTIN(wcschr,  "w*wC*w",   "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wcscmp,  "iwC*wC*",  "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wcslen,  "zwC*", "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wcsncmp, "iwC*wC*z", "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wmemchr, "w*wC*wz",  "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wmemcmp, "iwC*wC*z", "f", "wchar.h", ALL_LANGUAGES)
 
 // C99
 // In some systems setjmp is a macro that expands to _setjmp. We undefine

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=288193=288192=288193=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Nov 29 13:45:17 2016
@@ -8554,6 +8554,10 @@ static QualType DecodeTypeFromStr(const
 assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'z'!");
 Type = Context.getSizeType();
 break;
+  case 'w':  // wchar_t.
+assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'w'!");
+Type = Context.getWideCharType();
+break;
   case 'F':
 Type = Context.getCFConstantStringType();
 break;

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=288193=288192=288193=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Nov 29 13:45:17 2016
@@ -5346,16 +5346,20 @@ bool PointerExprEvaluator::VisitBuiltinC
   }
 
   case Builtin::BIstrchr:
+  case Builtin::BIwcschr:
   case Builtin::BImemchr:
+  case Builtin::BIwmemchr:
 if (Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_constexpr_invalid_function)
 << /*isConstexpr*/0 << /*isConstructor*/0
-<< (BuiltinOp == Builtin::BIstrchr ? "'strchr'" : "'memchr'");
+<< (std::string("'") + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'");
 else
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 // Fall through.
   case Builtin::BI__builtin_strchr:
-  case Builtin::BI__builtin_memchr: {
+  case Builtin::BI__builtin_wcschr:
+  case Builtin::BI__builtin_memchr:
+  case Builtin::BI__builtin_wmemchr: {
 if (!Visit(E->getArg(0)))
   return false;
 APSInt Desired;
@@ -5363,29 +5367,51 @@ bool PointerExprEvaluator::VisitBuiltinC
   return false;
 uint64_t MaxLength = uint64_t(-1);
 if (BuiltinOp != Builtin::BIstrchr &&
-BuiltinOp != Builtin::BI__builtin_strchr) {
+BuiltinOp != Builtin::BIwcschr &&
+BuiltinOp != Builtin::BI__builtin_strchr &&
+BuiltinOp != Builtin::BI__builtin_wcschr) {
   APSInt N;
   if (!EvaluateInteger(E->getArg(2), N, Info))
 return false;
   MaxLength = N.getExtValue();
 }
 
-QualType CharTy = Info.Ctx.CharTy;
-bool IsStrchr = (BuiltinOp != Builtin::BImemchr &&
- BuiltinOp != 

[PATCH] D21695: [clang] Version support for UBSan handlers

2016-11-29 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a reviewer: vsk.
vsk added a comment.
This revision is now accepted and ready to land.

Thanks for working on this. LGTM with a nit.




Comment at: lib/CodeGen/CGExpr.cpp:2506
+  assert(CheckHandler >= 0 &&
+ CheckHandler < sizeof(SanitizerHandlers) / 
sizeof(*SanitizerHandlers));
+  const StringRef CheckName = SanitizerHandlers[CheckHandler].Name;

Use llvm::array_lengthof? Also, I don't think the >= 0 check is really 
necessary, but I'll leave it up to you to decide.


https://reviews.llvm.org/D21695



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Mads Ravn via Phabricator via cfe-commits
madsravn removed rL LLVM as the repository for this revision.
madsravn updated this revision to Diff 79610.
madsravn added a comment.

Updated the patch to include changes suggested by comments.


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscStringCompareCheck.cpp
  clang-tidy/misc/MiscStringCompareCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+#include 
+
+void Test() {
+  std::string str1{"a"};
+  std::string str2{"b"};
+
+  if(str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(!str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) == 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) != 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+}
+
+void Valid() {
+std::string str1{"a"};
+std::string str2{"b"};
+if(str1 == str2) {}
+if(str1 != str2) {}
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===
+
+Finds string comparisons using the compare method.
+
+A common mistake is to use the string's compare method instead of using the 
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns -1, 0 or 1 depending on the lexicographical 
+relationship between the strings compared. If an equality or inequality check
+can suffice, that is recommended.
+
+Examples:
+
+.. code-block:: c++
+
+  std::string str1{"a"};
+  std::string str2{"b"};
+  
+  if(str1.compare(str2)) {} // use str1 != str2 instead
+  
+  if(!str1.compare(str2)) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) == 0) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) != 0) {} // use str1 != str2 instead
+
+The above code examples shows the list of if-statements that this check will
+give a warning for. All of them uses compare to check if equality or 
+inequality of two strings instead of using the correct operators.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -80,6 +80,7 @@
misc-sizeof-container
misc-sizeof-expression
misc-static-assert
+   misc-string-compare
misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
Index: clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tidy/misc/MiscTidyModule.cpp
@@ -22,6 +22,7 @@
 #include "InefficientAlgorithmCheck.h"
 #include "MacroParenthesesCheck.h"
 #include "MacroRepeatedSideEffectsCheck.h"
+#include "MiscStringCompareCheck.h"
 #include "MisplacedConstCheck.h"
 #include "MisplacedWideningCastCheck.h"
 #include "MoveConstantArgumentCheck.h"
@@ -105,6 +106,7 @@
 CheckFactories.registerCheck(
 "misc-sizeof-expression");
 CheckFactories.registerCheck("misc-static-assert");
+CheckFactories.registerCheck("misc-string-compare");
 CheckFactories.registerCheck(
 "misc-string-constructor");
 CheckFactories.registerCheck(
Index: clang-tidy/misc/MiscStringCompareCheck.h
===
--- clang-tidy/misc/MiscStringCompareCheck.h
+++ clang-tidy/misc/MiscStringCompareCheck.h
@@ -0,0 +1,36 @@
+//===--- MiscStringCompareCheck.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 MISC_STRING_COMPARE_CHECK_H
+#define MISC_STRING_COMPARE_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace 

[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please mention this check in docs/ReleaseNotes.rst (in alphabetical order).




Comment at: docs/clang-tidy/checks/misc-string-compare.rst:8
+
+A common mistake is to use the string's compare method instead of using the 
+equality or inequality operators. The compare method is intended for sorting

Please enclose compare in ``. Probably will be good idea to add (). Same below.



Comment at: docs/clang-tidy/checks/misc-string-compare.rst:10
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns -1, 0 or 1 depending on the lexicographical 
+relationship between the strings compared. If an equality or inequality check

Please enclose -1, 0 and 1 in `.


Repository:
  rL LLVM

https://reviews.llvm.org/D27210



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


[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe updated this revision to Diff 79605.
spyffe marked 2 inline comments as done.
spyffe added a comment.

Updated to reflect Aleksei's comments.


Repository:
  rL LLVM

https://reviews.llvm.org/D27180

Files:
  test/Import/empty-struct/Inputs/S.c
  test/Import/empty-struct/test.c
  tools/CMakeLists.txt
  tools/clang-import-test/CMakeLists.txt
  tools/clang-import-test/clang-import-test.cpp

Index: tools/clang-import-test/clang-import-test.cpp
===
--- tools/clang-import-test/clang-import-test.cpp
+++ tools/clang-import-test/clang-import-test.cpp
@@ -0,0 +1,342 @@
+//===-- import-test.cpp - ASTImporter/ExternalASTSource testbed ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTImporter.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/ParseAST.h"
+
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/Signals.h"
+
+#include 
+#include 
+
+using namespace clang;
+
+static llvm::cl::opt Expression(
+"expression", llvm::cl::Required,
+llvm::cl::desc("Path to a file containing the expression to parse"));
+
+static llvm::cl::list
+Imports("import", llvm::cl::ZeroOrMore,
+llvm::cl::desc("Path to a file containing declarations to import"));
+
+static llvm::cl::list
+ClangArgs("-Xcc", llvm::cl::ZeroOrMore,
+  llvm::cl::desc("Argument to pass to the CompilerInvocation"),
+  llvm::cl::CommaSeparated);
+
+static llvm::cl::opt LogLookups(
+"log-lookups",
+llvm::cl::desc("Print each lookup performed on behalf of the expression"));
+
+namespace {
+
+class TestDiagnosticConsumer : public DiagnosticConsumer {
+private:
+  std::unique_ptr Passthrough;
+  const LangOptions *LangOpts = nullptr;
+
+public:
+  TestDiagnosticConsumer()
+  : Passthrough(llvm::make_unique()) {}
+
+  virtual void BeginSourceFile(const LangOptions ,
+   const Preprocessor *PP = nullptr) override {
+this->LangOpts = 
+return Passthrough->BeginSourceFile(LangOpts, PP);
+  }
+
+  virtual void EndSourceFile() override {
+this->LangOpts = nullptr;
+Passthrough->EndSourceFile();
+  }
+
+  virtual void finish() override { Passthrough->finish(); }
+
+  virtual bool IncludeInDiagnosticCounts() const override {
+return Passthrough->IncludeInDiagnosticCounts();
+  }
+
+private:
+  static void PrintSourceForLocation(const SourceLocation ,
+ SourceManager ) {
+bool Invalid = true;
+const char *LocData = SM.getCharacterData(Loc, );
+if (Invalid) {
+  return;
+}
+unsigned LocColumn = SM.getSpellingColumnNumber(Loc, ) - 1;
+if (Invalid) {
+  return;
+}
+FileID FID = SM.getFileID(Loc);
+llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, Loc, );
+if (Invalid) {
+  return;
+}
+
+assert(LocData >= Buffer->getBufferStart() &&
+   LocData < Buffer->getBufferEnd());
+
+const char *LineBegin = LocData - LocColumn;
+
+if (LineBegin < Buffer->getBufferStart()) {
+  LineBegin = Buffer->getBufferStart();
+}
+
+const char *LineEnd = nullptr;
+
+for (LineEnd = LineBegin; *LineEnd != '\n' && *LineEnd != '\r' &&
+  LineEnd < Buffer->getBufferEnd();
+ ++LineEnd)
+  ;
+
+llvm::StringRef LineString(LineBegin, LineEnd - LineBegin);
+
+llvm::errs() << LineString << '\n';
+std::string Space(LocColumn, ' ');
+llvm::errs() << Space.c_str() << '\n';
+  }
+
+  virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic ) override {
+if (Info.hasSourceManager() && LangOpts) {
+  SourceManager  = Info.getSourceManager();
+
+  if (Info.getLocation().isValid()) {
+Info.getLocation().print(llvm::errs(), SM);
+llvm::errs() << ": ";
+  }
+
+  SmallString<16> DiagText;
+  Info.FormatDiagnostic(DiagText);
+  llvm::errs() << DiagText << '\n';
+
+  if (Info.getLocation().isValid()) {
+PrintSourceForLocation(Info.getLocation(), SM);
+  }
+
+  for (const CharSourceRange  : Info.getRanges()) {
+bool Invalid = true;
+StringRef Ref = Lexer::getSourceText(Range, SM, *LangOpts, );
+

[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe marked 11 inline comments as done.
spyffe added a comment.

Thank you, Alex!  I've responded in a few places inline below, and will update 
this patch momentarily.




Comment at: tools/clang-import-test/clang-import-test.cpp:106
+
+const char *LineEnd = nullptr;
+

a.sidorin wrote:
> How about something like this:
> ```
> StringRef Remain(LineBegin, Buffer->getBufferEnd() - LineBegin);
> size_t EndPos = Remain.find_first_of("\r\n");
> StringRef Line = (EndPos == StringRef::npos) ? Remain : StringRef(LineBegin, 
> EndPos);
> llvm::errs() << Line << "\n";
> llvm::errs().indent(LocColumn) << "^\n";
> ```
> ?
I'm going to think about this a little more.  Personally I find the loop more 
readable.
That said StringRef instead of std::string seems an obvious win:
```
llvm::StringRef LineString(LineBegin, LineEnd - LineBegin);
``` 



Comment at: tools/clang-import-test/clang-import-test.cpp:152
+class TestExternalASTSource : public ExternalASTSource {
+private:  llvm::ArrayRef ImportCIs;
+  std::map> ForwardImporters;

a.sidorin wrote:
> Please add a newline here.
I just ran clang-format on the whole file.  Sorry for the noise.



Comment at: tools/clang-import-test/clang-import-test.cpp:222
+   SmallVectorImpl ) override {
+
+  }

a.sidorin wrote:
> Extra spaces.
Sigh.  Yes, I had a preliminary implementation of this in mind, but decided to 
split that out into a separate patch.



Comment at: tools/clang-import-test/clang-import-test.cpp:238
+
+  CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.data(),
+ ()[ClangArgv.size()],

a.sidorin wrote:
> `ClangArgv.begin(), ClangArgv.end()`
```
.../llvm/tools/clang/tools/clang-import-test/clang-import-test.cpp:236:44: 
error: no viable conversion from 'iterator' (aka '__wrap_iter') 
to 'const char *const *'
  CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.begin(), ClangArgv.end(),
   ^
.../llvm/tools/clang/include/clang/Frontend/CompilerInvocation.h:139:49: note: 
passing argument to parameter 'ArgBegin' here
 const char* const *ArgBegin,
^
```


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


Re: Upgrade and fix clang-format-vs

2016-11-29 Thread Hans Wennborg via cfe-commits
Very nice! I've tried this out and confirmed that the built plugin
also works with older Visual Studio versions.

Some comments below:

> --- /dev/null
> +++ b/tools/clang-format-vs/.gitignore
> @@ -0,0 +1,11 @@
> +# Visual Studio files
> +.vs/
> +/packages/
> +/ClangFormat/obj/
> +/ClangFormat/bin/

Should there really be a leading slash in these paths? Same below.

> +
> +# Generated and copied files
> +/ClangFormat/Key.snk
> +/ClangFormat/license.txt
> +/ClangFormat/clang-format.exe
> +/ClangFormat/source.extension.vsixmanifest
> diff --git a/tools/clang-format-vs/CMakeLists.txt 
> b/tools/clang-format-vs/CMakeLists.txt
> index fd0d6b0..90f89d8 100644
> --- a/tools/clang-format-vs/CMakeLists.txt
> +++ b/tools/clang-format-vs/CMakeLists.txt
> @@ -18,8 +18,13 @@ if (BUILD_CLANG_FORMAT_VS_PLUGIN)
>configure_file("source.extension.vsixmanifest.in"
>
> "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/source.extension.vsixmanifest")
>
> -  add_custom_target(clang_format_vsix ALL
> -  devenv "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" /Build Release
> +  find_program(NUGET_EXE nuget PATHS ${NUGET_EXE_PATH})
> +  if (NOT NUGET_EXE)
> + message(FATAL_ERROR "Could not find nuget.exe. Download from 
> https://www.nuget.org/nuget.exe and add to PATH or pass path via 
> NUGET_EXE_PATH var")

Can you break this string over multiple lines? I know there are pretty
long lines in this file already, but it would be good to not make it
worse.

Maybe it could be clarified that NUGET_EXE_PATH is the path to a
directory containing nuget.exe, not to the file itself (I ran into
this). Maybe NUGET_EXE_DIR would be a better name?

> +  endif()
> +
> +  add_custom_target(clang_format_vsix ALL
> +  ${NUGET_EXE} restore "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" & 
> devenv "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" /Build Release

Is '&' a CMake thing, or should that be '&&'? Also, any chance of
breaking these long lines?

>DEPENDS clang_format_exe_for_vsix 
> "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/source.extension.vsixmanifest"
>COMMAND ${CMAKE_COMMAND} -E copy_if_different
>"${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/bin/Release/ClangFormat.vsix"
> diff --git a/tools/clang-format-vs/README.txt 
> b/tools/clang-format-vs/README.txt
> index b23355d..44a071b 100644
> --- a/tools/clang-format-vs/README.txt
> +++ b/tools/clang-format-vs/README.txt
> @@ -2,13 +2,23 @@ This directory contains a VSPackage project to generate a 
> Visual Studio extensio
>  for clang-format.
>
>  Build prerequisites are:
> -- Visual Studio 2013 Professional
> -- Visual Studio 2013 SDK
> -- Visual Studio 2010 Professional (?)
> -- Visual Studio 2010 SDK (?)
> +- Visual Studio 2015
> +- Extensions SDK (you'll be prompted to install it if you open 
> ClangFormat.sln)

A very nice simplification :-)

>
> -The extension is built using CMake by setting BUILD_CLANG_FORMAT_VS_PLUGIN=ON
> -when configuring a Clang build, and building the clang_format_vsix target.
> +The extension is built using CMake to generate the usual LLLVM.sln by setting

An L too much in LLLVM.sln?


On Mon, Nov 28, 2016 at 8:00 PM, Antonio Maiorano  wrote:
> I've attached a patch that works as discussed. When running CMake with
> -DBUILD_CLANG_FORMAT_VS_PLUGIN=ON, it will look for nuget.exe in PATH, or
> you can pass in DNUGET_EXE_PATH=C:\nuget, for e.g.
>
>
> On Mon, 28 Nov 2016 at 14:31 Antonio Maiorano  wrote:
>>
>> Great, I'll get this working soon and attach a new patch :)
>>
>> On Mon, 28 Nov 2016 at 14:27 Hans Wennborg  wrote:
>>>
>>> On Mon, Nov 28, 2016 at 11:11 AM, Antonio Maiorano 
>>> wrote:
>>> >> It's built with the script in utils/release/build_llvm_package.bat
>>> > which I run manually on my machine once every few weeks.
>>> >
>>> > Okay, that's good news. So the simplest path to success would be to
>>> > require
>>> > the user to either pass the path to CMake via an arg like
>>> > -DNUGET_EXE_PATH,
>>> > or if it's not defined, to assume it's already in PATH. This is the
>>> > most
>>> > future-proof solution as it will work with future versions of VS (2017
>>> > RC
>>> > just came out).
>>> >
>>> > I can still look into whether a vsix built with VS 2015 references will
>>> > continue to work in older versions of VS, but even if this works, I
>>> > feel
>>> > like it's a temporary solution at best. There are other advantages to
>>> > using
>>> > NuGet here: it would allow us to more easily pin/upgrade which
>>> > assemblies we
>>> > want to use over time.
>>> >
>>> > If you're okay with it, I'll make the changes necessary to use
>>> > -DNUGET_EXE_PATH, if defined, otherwise assume it's on PATH. This
>>> > should be
>>> > a simple change at this point.
>>>
>>> That sounds good to me. There are already a bunch of prerequisites for
>>> building the plugin, so adding this one doesn't seem unreasonable.
>>> Especially since it seems it will simplify things to 

[clang-tools-extra] r288175 - Fix some Clang-tidy modernize-use-default and Include What You Use warnings; other minor fixes (NFC).

2016-11-29 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Tue Nov 29 12:24:01 2016
New Revision: 288175

URL: http://llvm.org/viewvc/llvm-project?rev=288175=rev
Log:
Fix some Clang-tidy modernize-use-default and Include What You Use warnings; 
other minor fixes (NFC).

This preparation to remove SetVector.h dependency on SmallSet.h.

Modified:
clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h
clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.h

Modified: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp?rev=288175=288174=288175=diff
==
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Tue Nov 29 12:24:01 
2016
@@ -18,10 +18,16 @@
 #include "USRFinder.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Index/USRGeneration.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
-#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+#include 
+#include 
 
 using namespace llvm;
 
@@ -29,6 +35,7 @@ namespace clang {
 namespace rename {
 
 namespace {
+
 // \brief This visitor recursively searches for all instances of a USR in a
 // translation unit and stores them for later usage.
 class USRLocFindingASTVisitor
@@ -140,6 +147,7 @@ private:
   std::vector LocationsFound;
   const ASTContext 
 };
+
 } // namespace
 
 std::vector

Modified: clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp?rev=288175=288174=288175=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp Tue Nov 29 
12:24:01 2016
@@ -1,4 +1,4 @@
-//===--- AvoidBindCheck.cpp - clang-tidy===//
+//===--- AvoidBindCheck.cpp - 
clang-tidy---===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -6,12 +6,25 @@
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
+
 #include "AvoidBindCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Lexer.h"
-#include 
-#include 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Regex.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -20,6 +33,7 @@ namespace tidy {
 namespace modernize {
 
 namespace {
+
 enum BindArgumentKind { BK_Temporary, BK_Placeholder, BK_CallExpr, BK_Other };
 
 struct BindArgument {

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=288175=288174=288175=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Tue Nov 
29 12:24:01 2016
@@ -8,11 +8,21 @@
 
//===--===//
 
 #include "LoopConvertCheck.h"
-#include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h" 
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+#include 
 
-using namespace clang;
 using namespace clang::ast_matchers;
 using namespace llvm;
 

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=288175=288174=288175=diff

[PATCH] D21695: [clang] Version support for UBSan handlers

2016-11-29 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab added a comment.

Ping!


https://reviews.llvm.org/D21695



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


[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe added a comment.

In https://reviews.llvm.org/D27180#607433, @hfinkel wrote:

> This seems like a great idea. btw, do you know about Cling 
> (https://root.cern.ch/cling)?


Hal, thank you for your interest!  Yes, Cling is what I was referring to when I 
mentioned the ROOT project.  Vassil Vassilev, the developer of Cling, is also 
on the reviewer list.  I had the pleasure of talking to Vassil a few years ago 
at a LLVM Developer Meeting and the idea of creating common infrastructure 
between LLDB and Cling has been rolling around in the back of my head since 
then.


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


[PATCH] D26916: [ObjC] Avoid a @try/@finally/@autoreleasepool fixit when parsing an expression

2016-11-29 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Thanks for the explanation, LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D26916



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


[PATCH] D27033: [ASTImporter] Support importing UnresolvedLookupExpr nodes

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe added a comment.

Marked the place I was talking about in D27181 




Comment at: lib/AST/ASTImporter.cpp:6489
+  DeclarationNameInfo NameInfo(E->getName(), E->getNameLoc());
+  ImportDeclarationNameLoc(E->getNameInfo(), NameInfo);
+

Commented in [[ https://reviews.llvm.org/D27181 | D27181 ]] that usage of 
`ImportDeclarationNameLoc` look different in different places.


https://reviews.llvm.org/D27033



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


[PATCH] D27181: [ASTImporter] Support for importing UsingDecl and UsingShadowDecl

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe added a comment.

Looks good, but I have a concern about the underlying branch's apparently 
inconsistent initialization of `DeclarationNameInfo`.  Aleksei, could you 
clarify how that code works?  Should we have a helper function so we don't have 
to carefully repeat this pattern everywhere?




Comment at: lib/AST/ASTImporter.cpp:4305
+  DeclarationNameInfo NameInfo(Name, 
Importer.Import(D->getNameInfo().getLoc()));
+  ImportDeclarationNameLoc(D->getNameInfo(), NameInfo);
+

I've seen this pattern before, in [[ https://reviews.llvm.org/D27033 | D20733 
]], at ASTImporter.cpp:6488:
```
  DeclarationNameInfo NameInfo(E->getName(), E->getNameLoc());
  ImportDeclarationNameLoc(E->getNameInfo(), NameInfo);
```
That code didn't do the `Import` during the initialization of the 
`DeclarationNameInfo`.  Is either of these incorrect?


https://reviews.llvm.org/D27181



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


[PATCH] D26991: Remove unused code

2016-11-29 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added inline comments.



Comment at: libcxx/include/algorithm:1499
+// Load the first element from __first2 outside the loop because it is 
loop invariant
+typename iterator_traits<_RandomAccessIterator1>::value_type 
__firstElement2 = *__first2;
+

hiraditya wrote:
> mclow.lists wrote:
> > I just realized that we can't do this.
> > This imposes a requirement that the `value_type` be copy-constructible.
> > 
> > With this in place, we can't search a sequence of move-only types.
> Ok, I'll remove this change while pushing. I'll change the subject as well, 
> because now this patch is just removing the unused code.
> Thanks for the review.
Are we allowed to call __search on a type which is not copy-constructible?


Repository:
  rL LLVM

https://reviews.llvm.org/D26991



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


Re: Embedded Bitcode in Object Files

2016-11-29 Thread Nico Weber via cfe-commits
It looks like patches 1 and  2 made it but 3 and 4 didn't. Do you no longer
need them?

On Mon, Feb 29, 2016 at 2:08 PM, Steven Wu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Ping. I don't know who is the best review for the patches. Thanks for
> Rafael looking at the LLVM change. Richard, do you have any opinions on the
> clang changes?
>
> Thanks
>
> Steven
>
> > On Feb 18, 2016, at 9:57 AM, Steven Wu  wrote:
> >
> > Hi all
> >
> > I put up some patches for embedding bitcode inside the object file
> (-fembed-bitcode) option. As I described in the dev list before, the new
> option can create normal object file with bitcode embedded in a special
> section. You can easily recreate the same object file with the embedded
> bitcode in it.
> >
> > I split the patch into several parts:
> > llvm patch:
> > http://reviews.llvm.org/D17388: Introduce the section for embedding
> bitcode in MachO file.
> >
> > There are four clang patches:
> > http://reviews.llvm.org/D17390: Implementing the clang driver for the
> new option.
> > http://reviews.llvm.org/D17392: Teach clang how to embed bitcode into
> the object file.
> > http://reviews.llvm.org/D17393: Slightly tweak the bitcode emitted in
> embed bitcode stage 1.
> > http://reviews.llvm.org/D17394: Reduce the amount of option gets
> embedded in the bitcode by introducing a whitelist and a blacklist.
> >
> > Let me know if anyone is interested in helping reviewing these changes.
> >
> > Thanks
> >
> > Steven
> >
> >
> >
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r288165 - Protect std::array tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 11:10:29 2016
New Revision: 288165

URL: http://llvm.org/viewvc/llvm-project?rev=288165=rev
Log:
Protect std::array tests under noexceptions

Skip tests that expect exceptions be thrown. Also add missing asserts.

Differential Revision: https://reviews.llvm.org/D27095


Modified:
libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp

Modified: libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp?rev=288165=288164=288165=diff
==
--- libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp Tue Nov 29 
11:10:29 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@ int main()
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@ int main()
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11


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


[PATCH] D27095: Protect std::array tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288165: Protect std::array tests under noexceptions 
(authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D27095?vs=79589=79591#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27095

Files:
  libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp


Index: libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
===
--- libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
+++ libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11


Index: libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
===
--- libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
+++ libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26960: [docs] Use x86_64 and i386 instead of x86 as arch for triples.

2016-11-29 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

Ping. This is a two-line documentation fix, but I want to make sure x86_64 and 
i386 are valid for arch in target triples in all cases.


https://reviews.llvm.org/D26960



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


[PATCH] D27095: Protect std::array tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 updated this revision to Diff 79589.
rogfer01 added a comment.

Add missing assertions in the original test.


https://reviews.llvm.org/D27095

Files:
  test/std/containers/sequences/array/at.pass.cpp


Index: test/std/containers/sequences/array/at.pass.cpp
===
--- test/std/containers/sequences/array/at.pass.cpp
+++ test/std/containers/sequences/array/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11


Index: test/std/containers/sequences/array/at.pass.cpp
===
--- test/std/containers/sequences/array/at.pass.cpp
+++ test/std/containers/sequences/array/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r288163 - [OpenCL] Prevent generation of globals in non-constant AS for OpenCL.

2016-11-29 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Nov 29 11:01:19 2016
New Revision: 288163

URL: http://llvm.org/viewvc/llvm-project?rev=288163=rev
Log:
[OpenCL] Prevent generation of globals in non-constant AS for OpenCL.

Avoid using shortcut for const qualified non-constant address space
aggregate variables while generating them on the stack such that
the alloca object is used instead of a global variable containing
initializer.

Review: https://reviews.llvm.org/D27109


Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=288163=288162=288163=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Nov 29 11:01:19 2016
@@ -948,8 +948,12 @@ CodeGenFunction::EmitAutoVarAlloca(const
   // If the variable's a const type, and it's neither an NRVO
   // candidate nor a __block variable and has no mutable members,
   // emit it as a global instead.
-  if (CGM.getCodeGenOpts().MergeAllConstants && !NRVO && !isByRef &&
-  CGM.isTypeConstant(Ty, true)) {
+  // Exception is if a variable is located in non-constant address space
+  // in OpenCL.
+  if ((!getLangOpts().OpenCL ||
+   Ty.getAddressSpace() == LangAS::opencl_constant) &&
+  (CGM.getCodeGenOpts().MergeAllConstants && !NRVO && !isByRef &&
+   CGM.isTypeConstant(Ty, true))) {
 EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage);
 
 // Signal this condition to later callbacks.

Modified: cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl?rev=288163=288162=288163=diff
==
--- cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl Tue Nov 29 
11:01:19 2016
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -cl-opt-disable -ffake-address-space-map -emit-llvm -o - 
| FileCheck %s
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -cl-opt-disable 
-ffake-address-space-map -emit-llvm -o - | FileCheck %s
 
 // CHECK: @array = addrspace({{[0-9]+}}) constant
 __constant float array[2] = {0.0f, 1.0f};
@@ -6,3 +6,22 @@ __constant float array[2] = {0.0f, 1.0f}
 kernel void test(global float *out) {
   *out = array[0];
 }
+
+// Test that we don't use directly initializers for const aggregates
+// but create a copy in the original address space (unless a variable itself is
+// in the constant address space).
+
+void foo(constant const int *p1, const int *p2, const int *p3);
+// CHECK: @k.arr1 = internal addrspace(3) constant [3 x i32] [i32 1, i32 2, 
i32 3]
+// CHECK: @k.arr2 = private unnamed_addr addrspace(3) constant [3 x i32] [i32 
4, i32 5, i32 6]
+// CHECK: @k.arr3 = private unnamed_addr addrspace(3) constant [3 x i32] [i32 
7, i32 8, i32 9]
+kernel void k(void) {
+  // CHECK-NOT: %arr1 = alloca [3 x i32]
+  constant const int arr1[] = {1, 2, 3};
+  // CHECK: %arr2 = alloca [3 x i32]
+  const int arr2[] = {4, 5, 6};
+  // CHECK: %arr3 = alloca [3 x i32]
+  int arr3[] = {7, 8, 9};
+
+  foo(arr1, arr2, arr3);
+}


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


[PATCH] D27181: [ASTImporter] Support for importing UsingDecl and UsingShadowDecl

2016-11-29 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Thank you Kareem, It looks mostly good, but I'd like to have some functional 
tests in ASTMerge for this patch.




Comment at: lib/AST/ASTImporter.cpp:4299
+  if (ImportDeclParts(D, DC, LexicalDC, Name, AlreadyImported, Loc))
+return NULL;
+  assert(DC && "Null DeclContext after importing decl parts");

nullptr



Comment at: lib/AST/ASTImporter.cpp:4323
+  for (UsingShadowDecl *I : D->shadows()) {
+UsingShadowDecl *SD = cast(Importer.Import(I));
+ToD->addShadowDecl(SD);

This will assert if import fails. We need to use `cast_or_null` and check for 
null returns. (If this is the result of my misleading code, sorry for this.)



Comment at: lib/AST/ASTImporter.cpp:4335
+  if (ImportDeclParts(D, DC, LexicalDC, Name, AlreadyImported, Loc))
+return NULL;
+  assert(DC && "Null DeclContext after importing decl parts");

nullptr



Comment at: lib/AST/ASTImporter.cpp:4342
+Importer.getToContext(), DC, Loc,
+cast(Importer.Import(D->getUsingDecl())),
+cast_or_null(Importer.Import(D->getTargetDecl(;

This will assert if import fails. We need to use cast_or_null and check for 
null returns.


https://reviews.llvm.org/D27181



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


[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-29 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

That's excellent. Thank you for this work, Sean!




Comment at: tools/clang-import-test/CMakeLists.txt:19
+  )
\ No newline at end of file


Please add a newline here.



Comment at: tools/clang-import-test/clang-import-test.cpp:106
+
+const char *LineEnd = nullptr;
+

How about something like this:
```
StringRef Remain(LineBegin, Buffer->getBufferEnd() - LineBegin);
size_t EndPos = Remain.find_first_of("\r\n");
StringRef Line = (EndPos == StringRef::npos) ? Remain : StringRef(LineBegin, 
EndPos);
llvm::errs() << Line << "\n";
llvm::errs().indent(LocColumn) << "^\n";
```
?



Comment at: tools/clang-import-test/clang-import-test.cpp:115
+
+fprintf(stderr, "%s\n", LineString.c_str());
+std::string Space(LocColumn, ' ');

Why do we use `fprintf` instead of `llvm::errs()`?



Comment at: tools/clang-import-test/clang-import-test.cpp:130
+
+  SmallVector DiagText;
+  Info.FormatDiagnostic(DiagText);

SmallString? So, you will not need to push_back.



Comment at: tools/clang-import-test/clang-import-test.cpp:143
+if (!Invalid) {
+  llvm::errs() << Ref.str().c_str() << '\n';
+}

No need in `c_str()` here.



Comment at: tools/clang-import-test/clang-import-test.cpp:152
+class TestExternalASTSource : public ExternalASTSource {
+private:  llvm::ArrayRef ImportCIs;
+  std::map> ForwardImporters;

Please add a newline here.



Comment at: tools/clang-import-test/clang-import-test.cpp:162
+  const bool MinimalImport = true;
+  ForwardImporters.emplace(std::make_pair(
+  ImportCI,

`ForwardImporters[ImportCI] = ...llvm::make_unique<>`?



Comment at: tools/clang-import-test/clang-import-test.cpp:179
+  DeclarationName Name) override {
+std::vector Decls;
+

SmallVector?



Comment at: tools/clang-import-test/clang-import-test.cpp:181
+
+if (llvm::isa(DC)) {
+  for (CompilerInstance *I : ImportCIs) {

In LLVM code, qualifiers for llvm-style casts are not commonly used.



Comment at: tools/clang-import-test/clang-import-test.cpp:222
+   SmallVectorImpl ) override {
+
+  }

Extra spaces.



Comment at: tools/clang-import-test/clang-import-test.cpp:236
+  std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
+ [](std::string ) -> const char * { return s.data(); });
+

`[](const std::string )`



Comment at: tools/clang-import-test/clang-import-test.cpp:238
+
+  CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.data(),
+ ()[ClangArgv.size()],

`ClangArgv.begin(), ClangArgv.end()`



Comment at: tools/clang-import-test/clang-import-test.cpp:327
+}
+}
+

// end namespace


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


[PATCH] D26612: Protect std::string tests under libcpp-no-exceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288158: Protect std::string tests under libcpp-no-exceptions 
(authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D26612?vs=78012=79583#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26612

Files:
  libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp


Index: 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
===
--- 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
+++ 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // basic_string substr(size_type pos = 0, size_type n = npos) const;
@@ -24,19 +23,29 @@
 void
 test(const S& s, typename S::size_type pos, typename S::size_type n)
 {
-try
+if (pos <= s.size())
 {
 S str = s.substr(pos, n);
 LIBCPP_ASSERT(str.__invariants());
 assert(pos <= s.size());
 typename S::size_type rlen = std::min(n, s.size() - pos);
 assert(str.size() == rlen);
 assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0);
 }
-catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(pos > s.size());
+try
+{
+S str = s.substr(pos, n);
+assert(false);
+}
+catch (std::out_of_range&)
+{
+assert(pos > s.size());
+}
 }
+#endif
 }
 
 int main()
Index: 
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
===
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // size_type capacity() const;
@@ -18,21 +17,27 @@
 #include "test_allocator.h"
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 template 
 void
 test(S s)
 {
 S::allocator_type::throw_after = 0;
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
+#endif
 {
 while (s.size() < s.capacity())
 s.push_back(typename S::value_type());
 assert(s.size() == s.capacity());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 catch (...)
 {
 assert(false);
 }
+#endif
 S::allocator_type::throw_after = INT_MAX;
 }
 


Index: libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
===
--- libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
+++ libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // basic_string substr(size_type pos = 0, size_type n = npos) const;
@@ -24,19 +23,29 @@
 void
 test(const S& s, typename S::size_type pos, typename S::size_type n)
 {
-try
+if (pos <= s.size())
 {
 S str = s.substr(pos, n);
 LIBCPP_ASSERT(str.__invariants());
 assert(pos <= s.size());
 typename S::size_type rlen = std::min(n, s.size() - pos);
 assert(str.size() == rlen);
 assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0);
 }
-catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(pos > s.size());
+try
+{
+S str = s.substr(pos, n);
+assert(false);
+}
+catch (std::out_of_range&)
+{
+assert(pos > s.size());
+}
 }
+#endif
 }
 
 int main()
Index: libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
===
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // size_type capacity() const;
@@ -18,21 +17,27 @@
 #include "test_allocator.h"
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 template 
 void
 test(S s)
 {
 S::allocator_type::throw_after = 0;
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
+#endif
 {
 while (s.size() < s.capacity())
 s.push_back(typename S::value_type());

[libcxx] r288158 - Protect std::string tests under libcpp-no-exceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 10:40:19 2016
New Revision: 288158

URL: http://llvm.org/viewvc/llvm-project?rev=288158=rev
Log:
Protect std::string tests under libcpp-no-exceptions

Skip tests that expect an exception be thrown and/or disable
unreachable catch handlers.

Differential Revision: https://reviews.llvm.org/D26612


Modified:
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp?rev=288158=288157=288158=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp 
Tue Nov 29 10:40:19 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // size_type capacity() const;
@@ -18,21 +17,27 @@
 #include "test_allocator.h"
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 template 
 void
 test(S s)
 {
 S::allocator_type::throw_after = 0;
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
+#endif
 {
 while (s.size() < s.capacity())
 s.push_back(typename S::value_type());
 assert(s.size() == s.capacity());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 catch (...)
 {
 assert(false);
 }
+#endif
 S::allocator_type::throw_after = INT_MAX;
 }
 

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp?rev=288158=288157=288158=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
 Tue Nov 29 10:40:19 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // basic_string substr(size_type pos = 0, size_type n = npos) const;
@@ -24,7 +23,7 @@ template 
 void
 test(const S& s, typename S::size_type pos, typename S::size_type n)
 {
-try
+if (pos <= s.size())
 {
 S str = s.substr(pos, n);
 LIBCPP_ASSERT(str.__invariants());
@@ -33,10 +32,20 @@ test(const S& s, typename S::size_type p
 assert(str.size() == rlen);
 assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0);
 }
-catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(pos > s.size());
+try
+{
+S str = s.substr(pos, n);
+assert(false);
+}
+catch (std::out_of_range&)
+{
+assert(pos > s.size());
+}
 }
+#endif
 }
 
 int main()


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


[PATCH] D27096: Protect locale tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288156: Protect locale tests under noexceptions (authored by 
rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D27096?vs=79219=79581#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27096

Files:
  
libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
  
libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
  
libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
  
libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp

Index: libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp
===
--- libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp
+++ libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template  locale combine(const locale& other) const;
@@ -18,6 +17,8 @@
 
 #include "count_new.hpp"
 
+#include "test_macros.h"
+
 void check(const std::locale& loc)
 {
 assert(std::has_facet(loc));
@@ -78,6 +79,7 @@
 }
 assert(globalMemCounter.checkOutstandingNewEq(0));
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 {
 std::locale loc;
@@ -93,4 +95,5 @@
 }
 assert(globalMemCounter.checkOutstandingNewEq(0));
 }
+#endif
 }
Index: libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
===
--- libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
+++ libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // REQUIRES: locale.ru_RU.UTF-8
 // REQUIRES: locale.zh_CN.UTF-8
 
@@ -22,6 +21,8 @@
 #include "count_new.hpp"
 #include "platform_support.h" // locale name macros
 
+#include "test_macros.h"
+
 
 void check(const std::locale& loc)
 {
@@ -70,6 +71,7 @@
 check(loc3);
 assert(!(loc == loc3));
 assert(loc != loc3);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 std::locale((const char*)0);
@@ -86,6 +88,7 @@
 catch (std::runtime_error&)
 {
 }
+#endif
 std::locale ok("");
 }
 assert(globalMemCounter.checkOutstandingNewEq(0));
Index: libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
===
--- libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
+++ libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
@@ -7,14 +7,15 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template  const Facet& use_facet(const locale& loc);
 
 #include 
 #include 
 
+#include "test_macros.h"
+
 int facet_count = 0;
 
 struct my_facet
@@ -32,6 +33,7 @@
 
 int main()
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 const my_facet& f = std::use_facet(std::locale());
@@ -41,6 +43,7 @@
 catch (std::bad_cast&)
 {
 }
+#endif
 const my_facet* fp = 0;
 {
 std::locale loc(std::locale(), new my_facet);
Index: libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
===
--- libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
+++ libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // wstring_convert
@@ -29,6 +28,7 @@
 static_assert(!std::is_convertible::value, "");
 static_assert( std::is_constructible::value, "");
 #endif
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 Myconv myconv;
 try
@@ -48,18 +48,21 @@
 {
 }
 }
+#endif
 {
 Myconv myconv("byte error");
 std::string bs = myconv.to_bytes(L"\xDA83");
 assert(bs == "byte error");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 myconv.from_bytes('\xA5');
 assert(false);
 }
 catch (const std::range_error&)
 {
 }
+#endif
 }
 {
 Myconv myconv("byte error", 

[libcxx] r288156 - Protect locale tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 10:31:40 2016
New Revision: 288156

URL: http://llvm.org/viewvc/llvm-project?rev=288156=rev
Log:
Protect locale tests under noexceptions

Skip tests that expect exceptions be thrown.

Differential Revision: https://reviews.llvm.org/D27096


Modified:

libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp

libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp

libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp

libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp

Modified: 
libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp?rev=288156=288155=288156=diff
==
--- 
libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
 Tue Nov 29 10:31:40 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // wstring_convert
@@ -29,6 +28,7 @@ int main()
 static_assert(!std::is_convertible::value, "");
 static_assert( std::is_constructible::value, "");
 #endif
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 Myconv myconv;
 try
@@ -48,10 +48,12 @@ int main()
 {
 }
 }
+#endif
 {
 Myconv myconv("byte error");
 std::string bs = myconv.to_bytes(L"\xDA83");
 assert(bs == "byte error");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 myconv.from_bytes('\xA5');
@@ -60,6 +62,7 @@ int main()
 catch (const std::range_error&)
 {
 }
+#endif
 }
 {
 Myconv myconv("byte error", L"wide error");

Modified: 
libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp?rev=288156=288155=288156=diff
==
--- 
libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
 Tue Nov 29 10:31:40 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template  const Facet& use_facet(const locale& loc);
@@ -15,6 +14,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 int facet_count = 0;
 
 struct my_facet
@@ -32,6 +33,7 @@ std::locale::id my_facet::id;
 
 int main()
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 const my_facet& f = std::use_facet(std::locale());
@@ -41,6 +43,7 @@ int main()
 catch (std::bad_cast&)
 {
 }
+#endif
 const my_facet* fp = 0;
 {
 std::locale loc(std::locale(), new my_facet);

Modified: 
libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp?rev=288156=288155=288156=diff
==
--- 
libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
 Tue Nov 29 10:31:40 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // REQUIRES: locale.ru_RU.UTF-8
 // REQUIRES: locale.zh_CN.UTF-8
 
@@ -22,6 +21,8 @@
 #include "count_new.hpp"
 #include "platform_support.h" // locale name macros
 
+#include "test_macros.h"
+
 
 void check(const std::locale& loc)
 {
@@ -70,6 +71,7 @@ int main()
 check(loc3);
 assert(!(loc == loc3));
 assert(loc != loc3);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 std::locale((const char*)0);
@@ -86,6 +88,7 @@ int main()
 catch (std::runtime_error&)
 {
 }
+#endif
 std::locale ok("");
 }
 assert(globalMemCounter.checkOutstandingNewEq(0));

Modified: 
libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp
URL: 

[PATCH] D27093: Protect std::{, unordered_}map tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288157: Protect std::{,unordered_}map tests under 
noexceptions (authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D27093?vs=79212=79582#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27093

Files:
  libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp
  libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp

Index: libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp
===
--- libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp
+++ libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template , class Pred = equal_to,
@@ -23,6 +22,7 @@
 
 #include "MoveOnly.h"
 #include "min_allocator.h"
+#include "test_macros.h"
 
 int main()
 {
@@ -42,6 +42,7 @@
 assert(c.size() == 4);
 c.at(1) = "ONE";
 assert(c.at(1) == "ONE");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11) = "eleven";
@@ -51,6 +52,7 @@
 {
 }
 assert(c.size() == 4);
+#endif
 }
 {
 typedef std::unordered_map C;
@@ -67,6 +69,7 @@
 const C c(a, a + sizeof(a)/sizeof(a[0]));
 assert(c.size() == 4);
 assert(c.at(1) == "one");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11);
@@ -76,6 +79,7 @@
 {
 }
 assert(c.size() == 4);
+#endif
 }
 #if TEST_STD_VER >= 11
 {
@@ -95,6 +99,7 @@
 assert(c.size() == 4);
 c.at(1) = "ONE";
 assert(c.at(1) == "ONE");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11) = "eleven";
@@ -104,6 +109,7 @@
 {
 }
 assert(c.size() == 4);
+#endif
 }
 {
 typedef std::unordered_map

[libcxx] r288157 - Protect std::{, unordered_}map tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 10:37:48 2016
New Revision: 288157

URL: http://llvm.org/viewvc/llvm-project?rev=288157=rev
Log:
Protect std::{,unordered_}map tests under noexceptions

Skip tests that use exceptions

Differential Revision: https://reviews.llvm.org/D27093


Modified:
libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp

Modified: 
libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp?rev=288157=288156=288157=diff
==
--- libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp 
(original)
+++ libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp Tue 
Nov 29 10:37:48 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // class map
@@ -19,6 +18,7 @@
 #include 
 
 #include "min_allocator.h"
+#include "test_macros.h"
 
 int main()
 {
@@ -43,6 +43,7 @@ int main()
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
@@ -51,6 +52,7 @@ int main()
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
@@ -74,6 +76,7 @@ int main()
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
@@ -82,6 +85,7 @@ int main()
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
@@ -108,6 +112,7 @@ int main()
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
@@ -116,6 +121,7 @@ int main()
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
@@ -139,6 +145,7 @@ int main()
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
@@ -147,6 +154,7 @@ int main()
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);

Modified: 
libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp?rev=288157=288156=288157=diff
==
--- libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp 
(original)
+++ libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp 
Tue Nov 29 10:37:48 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template , class Pred = 
equal_to,
@@ -23,6 +22,7 @@
 
 #include "MoveOnly.h"
 #include "min_allocator.h"
+#include "test_macros.h"
 
 int main()
 {
@@ -42,6 +42,7 @@ int main()
 assert(c.size() == 4);
 c.at(1) = "ONE";
 assert(c.at(1) == "ONE");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11) = "eleven";
@@ -51,6 +52,7 @@ int main()
 {
 }
 assert(c.size() == 4);
+#endif
 }
 {
 typedef std::unordered_map C;
@@ -67,6 +69,7 @@ int main()
 const C c(a, a + sizeof(a)/sizeof(a[0]));
 assert(c.size() == 4);
 assert(c.at(1) == "one");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11);
@@ -76,6 +79,7 @@ int main()
 {
 }
 assert(c.size() == 4);
+#endif
 }
 #if TEST_STD_VER >= 11
 {
@@ -95,6 +99,7 @@ int main()
 assert(c.size() == 4);
 c.at(1) = "ONE";
 assert(c.at(1) == "ONE");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11) = "eleven";
@@ -104,6 +109,7 @@ int main()
 {
 }
 assert(c.size() == 4);
+#endif
 }
 {
 typedef std::unordered_map

[libcxx] r288155 - Protect test for dynarray under libcpp-no-exceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 10:27:45 2016
New Revision: 288155

URL: http://llvm.org/viewvc/llvm-project?rev=288155=rev
Log:
Protect test for dynarray under libcpp-no-exceptions

This test expects an exception be thrown.

Differential Revision: https://reviews.llvm.org/D26611


Modified:

libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp

Modified: 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp?rev=288155=288154=288155=diff
==
--- 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
 Tue Nov 29 10:27:45 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: c++98, c++03, c++11
 
 // dynarray.cons
@@ -29,6 +28,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 
 using std::experimental::dynarray;
 
@@ -61,12 +62,14 @@ void test ( const T , bool DefaultVa
 assert ( std::all_of ( d3.begin (), d3.end (), []( const T  ){ 
return item == val; } ));
 }
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 void test_bad_length () {
 try { dynarray ( std::numeric_limits::max() / sizeof ( int ) 
+ 1 ); }
 catch ( std::bad_array_length & ) { return ; }
 catch (...) { assert(false); }
 assert ( false );
 }
+#endif
 
 
 int main()
@@ -87,5 +90,7 @@ int main()
 assert ( d1.size() == 20 );
 assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return 
item == 3L; } ));
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 test_bad_length ();
+#endif
 }


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


[PATCH] D26611: Protect test for dynarray under libcpp-no-exceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288155: Protect test for dynarray under libcpp-no-exceptions 
(authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D26611?vs=77809=79580#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26611

Files:
  
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp


Index: 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
===
--- 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
+++ 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: c++98, c++03, c++11
 
 // dynarray.cons
@@ -29,6 +28,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 
 using std::experimental::dynarray;
 
@@ -61,12 +62,14 @@
 assert ( std::all_of ( d3.begin (), d3.end (), []( const T  ){ 
return item == val; } ));
 }
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 void test_bad_length () {
 try { dynarray ( std::numeric_limits::max() / sizeof ( int ) 
+ 1 ); }
 catch ( std::bad_array_length & ) { return ; }
 catch (...) { assert(false); }
 assert ( false );
 }
+#endif
 
 
 int main()
@@ -87,5 +90,7 @@
 assert ( d1.size() == 20 );
 assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return 
item == 3L; } ));
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 test_bad_length ();
+#endif
 }


Index: libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
===
--- libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
+++ libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: c++98, c++03, c++11
 
 // dynarray.cons
@@ -29,6 +28,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 
 using std::experimental::dynarray;
 
@@ -61,12 +62,14 @@
 assert ( std::all_of ( d3.begin (), d3.end (), []( const T  ){ return item == val; } ));
 }
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 void test_bad_length () {
 try { dynarray ( std::numeric_limits::max() / sizeof ( int ) + 1 ); }
 catch ( std::bad_array_length & ) { return ; }
 catch (...) { assert(false); }
 assert ( false );
 }
+#endif
 
 
 int main()
@@ -87,5 +90,7 @@
 assert ( d1.size() == 20 );
 assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return item == 3L; } ));
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 test_bad_length ();
+#endif
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27214: [ObjC] Encode type arguments in property information string constants

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: rjmccall, ahatanak.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch ensures that Objective-C type arguments are included in the string 
constants that have encoded information about `@property` declarations.


Repository:
  rL LLVM

https://reviews.llvm.org/D27214

Files:
  lib/AST/ASTContext.cpp
  test/CodeGenObjC/objc2-property-encode.m


Index: test/CodeGenObjC/objc2-property-encode.m
===
--- test/CodeGenObjC/objc2-property-encode.m
+++ test/CodeGenObjC/objc2-property-encode.m
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm -o %t %s
 // RUN: grep -e "T@22NSString22" %t
+// RUN: FileCheck %s -input-file=%t
 @interface NSString @end
 
 typedef NSString StoreVersionID ;
@@ -11,3 +12,30 @@
 @implementation Parent
 @dynamic foo;
 @end
+
+// rdar://22496485
+@interface TypeParameters<__covariant ObjectType>
+
+@end
+
+@interface TypeParameters2<__covariant A, __covariant B>
+
+@end
+
+@protocol MyProtocol;
+@class MyClass;
+
+@interface Bar
+
+@property(copy) TypeParameters *p1;
+
+@property(copy) TypeParameters2 *p2;
+
+@end
+
+@implementation Bar
+
+@end
+
+// CHECK: @OBJC_PROP_NAME_ATTR_{{.*}} = {{.*}} 
c"T@\22TypeParameters<@\22MyClass\22>\22,C,V_p1\00"
+// CHECK: @OBJC_PROP_NAME_ATTR_{{.*}} = {{.*}} 
c"T@\22TypeParameters2<@\22MyClass\22,@\22MyClass\22>\22,C,V_p2\00"
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -34,6 +34,7 @@
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/Capacity.h"
@@ -6275,6 +6276,18 @@
 (FD || EncodingProperty || EncodeClassNames)) {
   S += '"';
   S += OPT->getInterfaceDecl()->getObjCRuntimeNameAsString();
+  ArrayRef TypeArgs = OPT->getTypeArgs();
+  if (!TypeArgs.empty()) {
+S += '<';
+for (const auto  : llvm::enumerate(TypeArgs)) {
+  if (I.Index)
+S += ',';
+  getObjCEncodingForTypeImpl(I.Value, S, ExpandPointedToStructures,
+ ExpandStructures, nullptr, false,
+ EncodingProperty);
+}
+S += '>';
+  }
   for (const auto *I : OPT->quals()) {
 S += '<';
 S += I->getObjCRuntimeNameAsString();


Index: test/CodeGenObjC/objc2-property-encode.m
===
--- test/CodeGenObjC/objc2-property-encode.m
+++ test/CodeGenObjC/objc2-property-encode.m
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm -o %t %s
 // RUN: grep -e "T@22NSString22" %t
+// RUN: FileCheck %s -input-file=%t
 @interface NSString @end
 
 typedef NSString StoreVersionID ;
@@ -11,3 +12,30 @@
 @implementation Parent
 @dynamic foo;
 @end
+
+// rdar://22496485
+@interface TypeParameters<__covariant ObjectType>
+
+@end
+
+@interface TypeParameters2<__covariant A, __covariant B>
+
+@end
+
+@protocol MyProtocol;
+@class MyClass;
+
+@interface Bar
+
+@property(copy) TypeParameters *p1;
+
+@property(copy) TypeParameters2 *p2;
+
+@end
+
+@implementation Bar
+
+@end
+
+// CHECK: @OBJC_PROP_NAME_ATTR_{{.*}} = {{.*}} c"T@\22TypeParameters<@\22MyClass\22>\22,C,V_p1\00"
+// CHECK: @OBJC_PROP_NAME_ATTR_{{.*}} = {{.*}} c"T@\22TypeParameters2<@\22MyClass\22,@\22MyClass\22>\22,C,V_p2\00"
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -34,6 +34,7 @@
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/Capacity.h"
@@ -6275,6 +6276,18 @@
 (FD || EncodingProperty || EncodeClassNames)) {
   S += '"';
   S += OPT->getInterfaceDecl()->getObjCRuntimeNameAsString();
+  ArrayRef TypeArgs = OPT->getTypeArgs();
+  if (!TypeArgs.empty()) {
+S += '<';
+for (const auto  : llvm::enumerate(TypeArgs)) {
+  if (I.Index)
+S += ',';
+  getObjCEncodingForTypeImpl(I.Value, S, ExpandPointedToStructures,
+ ExpandStructures, nullptr, false,
+ EncodingProperty);
+}
+S += '>';
+  }
   for (const auto *I : OPT->quals()) {
 S += '<';
 S += I->getObjCRuntimeNameAsString();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

I think you could add fixits for this.




Comment at: clang-tidy/misc/MiscStringCompareCheck.cpp:48
+  Finder->addMatcher(ifStmt(hasCondition(binaryOperator(hasOperatorName("=="),
+hasLHS(strCompare
+ .bind("match"),

Doesn't test RHS.



Comment at: clang-tidy/misc/MiscStringCompareCheck.cpp:54
+  Finder->addMatcher(ifStmt(hasCondition(binaryOperator(hasOperatorName("!="),
+hasLHS(strCompare
+ .bind("match"),

Doesn't test RHS.
Could be combined with the previous case.



Comment at: clang-tidy/misc/MiscStringCompareCheck.h:24
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/misc-string-compare-check.html
+class MiscStringCompareCheck : public ClangTidyCheck {
+public:

Remove `Misc`.

Did you use add_new_check.py to add this check?



Comment at: docs/clang-tidy/checks/misc-string-compare.rst:4
+misc-string-compare
+===
+

Too many `=`.


Repository:
  rL LLVM

https://reviews.llvm.org/D27210



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


[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

2016-11-29 Thread Felix Berger via Phabricator via cfe-commits
flx added inline comments.



Comment at: clang-tidy/utils/DeclRefExprUtils.cpp:127
+  match(findAll(declRefExpr(equalsNode(),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),

alexfh wrote:
> flx wrote:
> > alexfh wrote:
> > > How will this work with lambdas / local classes declared inside a loop? 
> > > Not sure if this case is going to happen in real code, but we'd better be 
> > > clear about the limitations of the implementation.
> > Why would this not work? Could you give an example? The way the function is 
> > written it handles my the use case for identifying when moving the 
> > parameter is not safe, so I could also just move it into the 
> > UnnecessaryValueParamCheck.
> I was thinking about a case where a loop this matcher finds is outside of the 
> function definition and shouldn't be considered:
> 
>   void F() {
> for (;;) {
>   struct C {
> void f(ExpensiveMovableType E) {
>   auto F = E;
> }
>   };
> }
>   }
> 
This case is not an issue in the check as we're passing f's body statement to 
the hasLoopStmtAncestor function, so the search is scoped to f's body.

If you're concerned about the case where someone calls this with  F's body but 
expects it to be scoped to f I can just move this function into the check and 
make it an implementation detail.


https://reviews.llvm.org/D27187



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


[clang-tools-extra] r288145 - [include-fixer] Don't eat one token too many when replacing a block of includes.

2016-11-29 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Tue Nov 29 09:15:26 2016
New Revision: 288145

URL: http://llvm.org/viewvc/llvm-project?rev=288145=rev
Log:
[include-fixer] Don't eat one token too many when replacing a block of includes.

SourceRanges are inclusive token ranges, this was trying to form an
exclusive char range.

Modified:
clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp

Modified: clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp?rev=288145=288144=288145=diff
==
--- clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp Tue Nov 29 09:15:26 
2016
@@ -136,10 +136,10 @@ static void addDiagnosticsForContext(Typ
   const tooling::Replacement  = *Reps->begin();
 
   auto Begin = StartOfFile.getLocWithOffset(Placed.getOffset());
-  auto End = Begin.getLocWithOffset(Placed.getLength());
+  auto End = Begin.getLocWithOffset(std::max(0, (int)Placed.getLength() - 1));
   PartialDiagnostic PD(DiagID, Ctx.getDiagAllocator());
   PD << Context.getHeaderInfos().front().Header
- << FixItHint::CreateReplacement(SourceRange(Begin, End),
+ << FixItHint::CreateReplacement(CharSourceRange::getCharRange(Begin, End),
  Placed.getReplacementText());
   Correction.addExtraDiagnostic(std::move(PD));
 }

Modified: clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp?rev=288145=288144=288145=diff
==
--- clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp (original)
+++ clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp Tue Nov 29 
09:15:26 2016
@@ -8,7 +8,8 @@ unknown u;
 // CHECK: FIX-IT: Replace [3:1 - 3:4] with "foo"
 // CHECK: yamldb_plugin.cpp:3:1: note: Add '#include "foo.h"' to provide the 
missing declaration [clang-include-fixer]
 // CHECK: Number FIX-ITs = 1
-// CHECK: FIX-IT: Replace [3:1 - 3:4] with "#include "foo.h"
+// CHECK: FIX-IT: Insert "#include "foo.h"
+// CHECK: " at 3:1
 // CHECK: yamldb_plugin.cpp:4:1:
 // CHECK: error: unknown type name 'unknown'
 // CHECK: Number FIX-ITs = 0


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


[PATCH] D26465: [Diag] Optimize DiagnosticIDs::getDiagnosticSeverity

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Is there any way to test this change?

> This saves more than 5% of the parsing time according to perf.

That sounds great. What did you test the parsing on? Will this patch get 
similar improvements for code that compiles without errors and warnings?




Comment at: lib/Basic/DiagnosticIDs.cpp:423
+Mapping = >State->getOrAddMapping((diag::kind)DiagID);
+  }
 

I think it would be better if you wrap this piece of code in a static function 
that returns `DiagnosticMapping &`, as it should allow you to get rid of all 
these `.` to `->` changes below.


https://reviews.llvm.org/D26465



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


[PATCH] D27138: Extend CompilationDatabase by a field for the output filename

2016-11-29 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

Which struct are we talking about, `CompileCommandRef` or `CompileCommand`? It 
is a pointer in the former and a plain StringRef in the latter. I don't think 
making it a pointer in both is an advantage, i.e. distinguishing empty input 
from missing field is not valuable in my opinion.


Repository:
  rL LLVM

https://reviews.llvm.org/D27138



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


[PATCH] D26991: Remove unused code

2016-11-29 Thread Aditya Kumar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288143: [libcxx] remove unused code (authored by hiraditya).

Changed prior to commit:
  https://reviews.llvm.org/D26991?vs=79565=79566#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26991

Files:
  libcxx/trunk/include/algorithm

Index: libcxx/trunk/include/algorithm
===
--- libcxx/trunk/include/algorithm
+++ libcxx/trunk/include/algorithm
@@ -1494,51 +1494,20 @@
 if (__len1 < __len2)
 return make_pair(__last1, __last1);
 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of pattern match can't go beyond here
+
 while (true)
 {
-#if !_LIBCPP_UNROLL_LOOPS
 while (true)
 {
 if (__first1 == __s)
 return make_pair(__last1, __last1);
 if (__pred(*__first1, *__first2))
 break;
 ++__first1;
 }
-#else  // !_LIBCPP_UNROLL_LOOPS
-for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; --__loop_unroll)
-{
-if (__pred(*__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-++__first1;
-}
-switch (__s - __first1)
-{
-case 3:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 2:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 1:
-if (__pred(*__first1, *__first2))
-break;
-case 0:
-return make_pair(__last1, __last1);
-}
-__phase2:
-#endif  // !_LIBCPP_UNROLL_LOOPS
+
 _RandomAccessIterator1 __m1 = __first1;
 _RandomAccessIterator2 __m2 = __first2;
-#if !_LIBCPP_UNROLL_LOOPS
  while (true)
  {
  if (++__m2 == __last2)
@@ -1550,43 +1519,6 @@
  break;
  }
  }
-#else  // !_LIBCPP_UNROLL_LOOPS
-++__m2;
-++__m1;
-for (_D2 __loop_unroll = (__last2 - __m2) / 4; __loop_unroll > 0; --__loop_unroll)
-{
-if (!__pred(*__m1, *__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-++__m1;
-++__m2;
-}
-switch (__last2 - __m2)
-{
-case 3:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 2:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 1:
-if (!__pred(*__m1, *__m2))
-break;
-case 0:
-return make_pair(__first1, __first1 + __len2);
-}
-__continue:
-++__first1;
-#endif  // !_LIBCPP_UNROLL_LOOPS
 }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

2016-11-29 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/utils/DeclRefExprUtils.cpp:127
+  match(findAll(declRefExpr(equalsNode(),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),

flx wrote:
> alexfh wrote:
> > How will this work with lambdas / local classes declared inside a loop? Not 
> > sure if this case is going to happen in real code, but we'd better be clear 
> > about the limitations of the implementation.
> Why would this not work? Could you give an example? The way the function is 
> written it handles my the use case for identifying when moving the parameter 
> is not safe, so I could also just move it into the UnnecessaryValueParamCheck.
I was thinking about a case where a loop this matcher finds is outside of the 
function definition and shouldn't be considered:

  void F() {
for (;;) {
  struct C {
void f(ExpensiveMovableType E) {
  auto F = E;
}
  };
}
  }



https://reviews.llvm.org/D27187



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


[libcxx] r288143 - [libcxx] remove unused code

2016-11-29 Thread Aditya Kumar via cfe-commits
Author: hiraditya
Date: Tue Nov 29 08:43:42 2016
New Revision: 288143

URL: http://llvm.org/viewvc/llvm-project?rev=288143=rev
Log:
[libcxx] remove unused code

The macro _LIBCPP_UNROLL_LOOPS isn't used anywhere
so the code was dead.

Differential Revision: https://reviews.llvm.org/D26991

Modified:
libcxx/trunk/include/algorithm

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=288143=288142=288143=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Tue Nov 29 08:43:42 2016
@@ -1494,9 +1494,9 @@ __search(_RandomAccessIterator1 __first1
 if (__len1 < __len2)
 return make_pair(__last1, __last1);
 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of 
pattern match can't go beyond here
+
 while (true)
 {
-#if !_LIBCPP_UNROLL_LOOPS
 while (true)
 {
 if (__first1 == __s)
@@ -1505,40 +1505,9 @@ __search(_RandomAccessIterator1 __first1
 break;
 ++__first1;
 }
-#else  // !_LIBCPP_UNROLL_LOOPS
-for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; 
--__loop_unroll)
-{
-if (__pred(*__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-++__first1;
-}
-switch (__s - __first1)
-{
-case 3:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 2:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 1:
-if (__pred(*__first1, *__first2))
-break;
-case 0:
-return make_pair(__last1, __last1);
-}
-__phase2:
-#endif  // !_LIBCPP_UNROLL_LOOPS
+
 _RandomAccessIterator1 __m1 = __first1;
 _RandomAccessIterator2 __m2 = __first2;
-#if !_LIBCPP_UNROLL_LOOPS
  while (true)
  {
  if (++__m2 == __last2)
@@ -1550,43 +1519,6 @@ __search(_RandomAccessIterator1 __first1
  break;
  }
  }
-#else  // !_LIBCPP_UNROLL_LOOPS
-++__m2;
-++__m1;
-for (_D2 __loop_unroll = (__last2 - __m2) / 4; __loop_unroll > 0; 
--__loop_unroll)
-{
-if (!__pred(*__m1, *__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-++__m1;
-++__m2;
-}
-switch (__last2 - __m2)
-{
-case 3:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 2:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 1:
-if (!__pred(*__m1, *__m2))
-break;
-case 0:
-return make_pair(__first1, __first1 + __len2);
-}
-__continue:
-++__first1;
-#endif  // !_LIBCPP_UNROLL_LOOPS
 }
 }
 


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


[PATCH] D26465: [Diag] Optimize DiagnosticIDs::getDiagnosticSeverity

2016-11-29 Thread Olivier Goffart via Phabricator via cfe-commits
ogoffart added a comment.

Ping 2


https://reviews.llvm.org/D26465



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


[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.



In https://reviews.llvm.org/D27163#607078, @rsmith wrote:

> A target-specific default for this, simply because there's a lot of code on 
> Darwin that happens to violate this language rule, doesn't make sense to me.
>
> Basing the behavior on whether a `-Wreturn-type` warning would have been 
> emitted seems like an extremely strange heuristic: only optimizing in the 
> cases where we provide the user no hint that we will do so seems incredibly 
> user-hostile.
>
> Regardless of anything else, it does not make any sense to "return" stack 
> garbage when the return type is a C++ class type, particularly one with a 
> non-trivial copy constructor or destructor. A trap at `-O0` is the kindest 
> thing we can do in that case.


Thanks, that makes sense. The updated patch avoids the trap and unreachable 
only for types that are trivially copyable and removes the Darwin specific code.

> In summary, I think it could be reasonable to have such a flag to disable the 
> trap/unreachable *only* for scalar types (or, at a push, trivially-copyable 
> types). But it seems unreasonable to have different defaults for Darwin, or 
> to look at whether a `-Wreturn-type` warning would have fired.

I understand that basing the optimisation avoidance on the analysis done for 
the `-Wreturn-type` warning might not be the best option, and a straightforward 
`-fno-strict-return` might be better as it doesn't use such hidden heuristics. 
However, AFAIK we only had problems with code that would've hit the 
`-Wreturn-type` warning, so it seemed like a good idea to keep the optimisation 
in functions where the analyser has determined that the flow with the no return 
is very unlikely (like in the `alwaysOptimizedReturn` function in the test 
case).  I kept it in this version of the patch, but if you think that the 
`-Wreturn-type` heuristic shouldn't be used I would be willing to remove it and 
go for the straightforward behaviour.

> Alternatively, since it seems you're only interested in the behavior of cases 
> where `-Wreturn-type` would have fired, how about using Clang's tooling 
> support to write a utility to add a return statement to the end of every 
> function where it would fire, and give that to your users to fix their code?

That's an interesting idea, but as John mentioned, some of the code that has 
these issues isn't written by Apple and it seems that it would be very 
difficult to convince code owners to run tooling and to fix such issues. But it 
still sounds like something that we should look into.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D25475: [analyzer] Add a new SVal to support pointer-to-member operations.

2016-11-29 Thread Kirill Romanenkov via Phabricator via cfe-commits
kromanenkov marked an inline comment as done.
kromanenkov added inline comments.



Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:217
+
+  llvm::ImmutableList consCXXBase(
+  const CXXBaseSpecifier *CBS,

NoQ wrote:
> Hmm, is it "construct"? Or "constrain"? I think a verbose name wouldn't hurt.
> In fact, i suspect that `consVals` are rather `conSVals`, where `con` stands 
> for "concatenate".
In fact I thought that this entails "consume" :)



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:882
+return UndefinedVal();
+  if (const FieldDecl *FD = PTMSV->getDeclAs())
+return state->getLValue(FD, lhs);

NoQ wrote:
> Hmm, do we need to cover `CXXMethodDecl` here? Or is it modeled as a function 
> pointer anyway, so no action is needed? Worth commenting, i think.
AFAIU CXXMethodDecl is processed in SVal::getAsFunctionDecl() so i'm for no 
action.


https://reviews.llvm.org/D25475



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


[PATCH] D27138: Extend CompilationDatabase by a field for the output filename

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D27138#607786, @joerg wrote:

> It's not the directory, but the output file. That's optional since it is a 
> new addition and I don't want to invalidate all existing JSON databases.


It seems like we're talking past each other. I'm not suggesting to invalidate 
all existing JSON databases. I'm suggesting:

1. if it doesn't exist, have nullptr in the struct
2. if it exists and is empty (""), have the empty string in the struct (and 
potentially give the user an error)
3. if it exists and is non-empty, all is good


Repository:
  rL LLVM

https://reviews.llvm.org/D27138



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


[PATCH] D25475: [analyzer] Add a new SVal to support pointer-to-member operations.

2016-11-29 Thread Kirill Romanenkov via Phabricator via cfe-commits
kromanenkov updated this revision to Diff 79560.
kromanenkov added a comment.

Thanks for your comments, Artem! Make function name less ambiguous. Also I take 
liberty to update analogical function name.


https://reviews.llvm.org/D25475

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SVals.def
  include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  lib/StaticAnalyzer/Core/BasicValueFactory.cpp
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  lib/StaticAnalyzer/Core/SValBuilder.cpp
  lib/StaticAnalyzer/Core/SVals.cpp
  lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/pointer-to-member.cpp

Index: test/Analysis/pointer-to-member.cpp
===
--- test/Analysis/pointer-to-member.cpp
+++ test/Analysis/pointer-to-member.cpp
@@ -35,8 +35,7 @@
   clang_analyzer_eval(::getPtr == ::getPtr); // expected-warning{{TRUE}}
   clang_analyzer_eval(::getPtr == 0); // expected-warning{{FALSE}}
 
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(::m_ptr == ::m_ptr); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(::m_ptr == ::m_ptr); // expected-warning{{TRUE}}
 }
 
 namespace PR15742 {
@@ -62,21 +61,114 @@
   }
 }
 
-// ---
-// FALSE NEGATIVES
-// ---
-
 bool testDereferencing() {
   A obj;
   obj.m_ptr = 0;
 
   A::MemberPointer member = ::m_ptr;
 
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(obj.*member == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(obj.*member == 0); // expected-warning{{TRUE}}
 
   member = 0;
 
-  // FIXME: Should emit a null dereference.
-  return obj.*member; // no-warning
+  return obj.*member; // expected-warning{{}}
+}
+
+namespace testPointerToMemberFunction {
+  struct A {
+virtual int foo() { return 1; }
+int bar() { return 2;  }
+  };
+
+  struct B : public A {
+virtual int foo() { return 3; }
+  };
+
+  typedef int (A::*AFnPointer)();
+  typedef int (B::*BFnPointer)();
+
+  void testPointerToMemberCasts() {
+AFnPointer AFP = ::bar;
+BFnPointer StaticCastedBase2Derived = static_cast(::bar),
+   CCastedBase2Derived = (BFnPointer) (::bar);
+A a;
+B b;
+
+clang_analyzer_eval((a.*AFP)() == 2); // expected-warning{{TRUE}}
+clang_analyzer_eval((b.*StaticCastedBase2Derived)() == 2); // expected-warning{{TRUE}}
+clang_analyzer_eval(((b.*CCastedBase2Derived)() == 2)); // expected-warning{{TRUE}}
+  }
+
+  void testPointerToMemberVirtualCall() {
+A a;
+B b;
+A *APtr = 
+AFnPointer AFP = ::foo;
+
+clang_analyzer_eval((APtr->*AFP)() == 1); // expected-warning{{TRUE}}
+
+APtr = 
+
+clang_analyzer_eval((APtr->*AFP)() == 3); // expected-warning{{TRUE}}
+  }
+} // end of testPointerToMemberFunction namespace
+
+namespace testPointerToMemberData {
+  struct A {
+int i;
+  };
+
+  void testPointerToMemberData() {
+int A::*AMdPointer = ::i;
+A a;
+
+a.i = 42;
+a.*AMdPointer += 1;
+
+clang_analyzer_eval(a.i == 43); // expected-warning{{TRUE}}
+  }
+} // end of testPointerToMemberData namespace
+
+namespace testPointerToMemberMiscCasts {
+struct B {
+  int f;
+};
+
+struct D : public B {
+  int g;
+};
+
+void foo() {
+  D d;
+  d.f = 7;
+
+  int B::* pfb = ::f;
+  int D::* pfd = pfb;
+  int v = d.*pfd;
+
+  clang_analyzer_eval(v == 7); // expected-warning{{TRUE}}
+}
+} // end of testPointerToMemberMiscCasts namespace
+
+namespace testPointerToMemberMiscCasts2 {
+struct B {
+  int f;
+};
+struct L : public B { };
+struct R : public B { };
+struct D : public L, R { };
+
+void foo() {
+  D d;
+
+  int B::* pb = ::f;
+  int L::* pl = pb;
+  int R::* pr = pb;
+
+  int D::* pdl = pl;
+  int D::* pdr = pr;
+
+  clang_analyzer_eval(pdl == pdr); // expected-warning{{FALSE}}
+  clang_analyzer_eval(pb == pl); // expected-warning{{TRUE}}
 }
+} // end of testPointerToMemberMiscCasts2 namespace
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -69,6 +69,9 @@
 
   bool isLocType = Loc::isLocType(castTy);
 
+  if (val.getAs())
+return val;
+
   if (Optional LI = val.getAs()) {
 if (isLocType)
   return LI->getLoc();
@@ -335,6 +338,21 @@
 switch (lhs.getSubKind()) {
 default:
   return makeSymExprValNN(state, op, lhs, rhs, resultTy);
+case nonloc::PointerToMemberKind: {
+  assert(rhs.getSubKind() == nonloc::PointerToMemberKind &&
+ "Both SVals should have pointer-to-member-type");
+  auto LPTM = lhs.castAs(),
+   RPTM = rhs.castAs();
+  auto LPTMD = LPTM.getPTMData(), RPTMD = RPTM.getPTMData();
+  switch (op) {
+case BO_EQ:
+  return makeTruthVal(LPTMD == RPTMD, 

[PATCH] D26991: Hoist redundant load

2016-11-29 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added inline comments.



Comment at: libcxx/include/algorithm:1499
+// Load the first element from __first2 outside the loop because it is 
loop invariant
+typename iterator_traits<_RandomAccessIterator1>::value_type 
__firstElement2 = *__first2;
+

mclow.lists wrote:
> I just realized that we can't do this.
> This imposes a requirement that the `value_type` be copy-constructible.
> 
> With this in place, we can't search a sequence of move-only types.
Ok, I'll remove this change while pushing. I'll change the subject as well, 
because now this patch is just removing the unused code.
Thanks for the review.


https://reviews.llvm.org/D26991



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


[PATCH] D27138: Extend CompilationDatabase by a field for the output filename

2016-11-29 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

It's not the directory, but the output file. That's optional since it is a new 
addition and I don't want to invalidate all existing JSON databases.


Repository:
  rL LLVM

https://reviews.llvm.org/D27138



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


[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: test/CodeGenCXX/return.cpp:47
+  // CHECK-NOSTRICT-OPT-NEXT: zext
+  // CHECK-NOSTRICT-OPT-NEXT: ret i32
+}

mehdi_amini wrote:
> Document what's going on in the tests please.
> 
I added some comments that help explain what's being tested. I also removed the 
`-fno-strict-return` checks with `-O` (except for the checks in the first 
function) as the non-optimised `-fno-strict-return` tests should be sufficient.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288139: [change-namespace] fix non-calling function 
references. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D27208?vs=79558=79559#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27208

Files:
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
  clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Index: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -457,6 +457,40 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, FixNonCallingFunctionReferences) {
+  std::string Code = "namespace na {\n"
+ "class A {\n"
+ "public:\n"
+ "  static void f() {}\n"
+ "};\n"
+ "void a_f() {}\n"
+ "static void s_f() {}\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "auto *ref1 = A::f; auto *ref2 = a_f; auto *ref3 = s_f;\n"
+ "}\n"
+ "}  // namespace nb\n"
+ "}  // namespace na\n";
+  std::string Expected =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "\n"
+  "}  // namespace na\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "void f() {\n"
+  "auto *ref1 = na::A::f; auto *ref2 = na::a_f; auto *ref3 = na::s_f;\n"
+  "}\n"
+  "}  // namespace y\n"
+  "}  // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveAndFixGlobalVariables) {
   std::string Code = "namespace na {\n"
  "int GlobA;\n"
Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
@@ -369,11 +369,13 @@
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of-line static methods since they will be handled by nested
 // name specifiers.
 if (Func->getCanonicalDecl()->getStorageClass() ==
-clang::StorageClass::SC_Static &&
+StorageClass::SC_Static &&
 Func->isOutOfLine())
   return;
-const clang::Decl 

[clang-tools-extra] r288139 - [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Nov 29 08:15:14 2016
New Revision: 288139

URL: http://llvm.org/viewvc/llvm-project?rev=288139=rev
Log:
[change-namespace] fix non-calling function references.

Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27208

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=288139=288138=288139=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Tue Nov 29 
08:15:14 2016
@@ -369,11 +369,13 @@ void ChangeNamespaceTool::registerMatche
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@ void ChangeNamespaceTool::run(
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of-line static methods since they will be handled by nested
 // name specifiers.
 if (Func->getCanonicalDecl()->getStorageClass() ==
-clang::StorageClass::SC_Static &&
+StorageClass::SC_Static &&
 Func->isOutOfLine())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange CalleeRange = Call->getCallee()->getSourceRange();
+SourceRange CalleeRange = Call->getCallee()->getSourceRange();
 replaceQualifiedSymbolInDeclContext(
 Result, Context->getDeclContext(), CalleeRange.getBegin(),
 CalleeRange.getEnd(), llvm::cast(Func));
@@ -698,6 +706,15 @@ void ChangeNamespaceTool::fixUsingShadow
 llvm_unreachable(llvm::toString(std::move(Err)).c_str());
 }
 
+void ChangeNamespaceTool::fixDeclRefExpr(
+const ast_matchers::MatchFinder::MatchResult ,
+const DeclContext *UseContext, const NamedDecl *From,
+const DeclRefExpr *Ref) {
+  SourceRange RefRange = Ref->getSourceRange();
+  replaceQualifiedSymbolInDeclContext(Result, UseContext, RefRange.getBegin(),
+  RefRange.getEnd(), From);
+}
+
 void ChangeNamespaceTool::onEndOfTranslationUnit() {
   // Move namespace blocks and insert forward declaration to old namespace.
   for (const auto  : MoveNamespaces) {

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.h?rev=288139=288138=288139=diff
==
--- 

[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 79558.
ioeric added a comment.

- Format code.


https://reviews.llvm.org/D27208

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -457,6 +457,40 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, FixNonCallingFunctionReferences) {
+  std::string Code = "namespace na {\n"
+ "class A {\n"
+ "public:\n"
+ "  static void f() {}\n"
+ "};\n"
+ "void a_f() {}\n"
+ "static void s_f() {}\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "auto *ref1 = A::f; auto *ref2 = a_f; auto *ref3 = s_f;\n"
+ "}\n"
+ "}  // namespace nb\n"
+ "}  // namespace na\n";
+  std::string Expected =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "\n"
+  "}  // namespace na\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "void f() {\n"
+  "auto *ref1 = na::A::f; auto *ref2 = na::a_f; auto *ref3 = na::s_f;\n"
+  "}\n"
+  "}  // namespace y\n"
+  "}  // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveAndFixGlobalVariables) {
   std::string Code = "namespace na {\n"
  "int GlobA;\n"
Index: change-namespace/ChangeNamespace.h
===
--- change-namespace/ChangeNamespace.h
+++ change-namespace/ChangeNamespace.h
@@ -76,6 +76,10 @@
   void fixUsingShadowDecl(const ast_matchers::MatchFinder::MatchResult ,
   const UsingDecl *UsingDeclaration);
 
+  void fixDeclRefExpr(const ast_matchers::MatchFinder::MatchResult ,
+  const DeclContext *UseContext, const NamedDecl *From,
+  const DeclRefExpr *Ref);
+
   // Information about moving an old namespace.
   struct MoveNamespace {
 // The start offset of the namespace block being moved in the original
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -369,11 +369,13 @@
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of-line static 

[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Sema/AnalysisBasedWarnings.cpp:530
+  // Don't need to mark Objective-C methods or blocks since the undefined
+  // behaviour optimization isn't used for them.
+}

mehdi_amini wrote:
> Quuxplusone wrote:
> > This seems like a trap waiting to spring on someone, unless there's a 
> > technical reason that methods and blocks cannot possibly use the same 
> > optimization paths as regular functions. ("Nobody's gotten around to 
> > implementing it yet" is the most obvious nontechnical reason for the 
> > current difference.) Either way, I'd expect this patch to include test 
> > cases for both methods and blocks, to verify that the behavior you expect 
> > is actually the behavior that happens. Basically, it ought to have a 
> > regression test targeting the regression that I'm predicting is going to 
> > spring on someone as soon as they implement optimizations for methods and 
> > blocks.
> > 
> > Also, one dumb question: what about C++ lambdas? are they FunctionDecls 
> > too? test case?
> > This seems like a trap waiting to spring on someone, unless there's a 
> > technical reason that methods and blocks cannot possibly use the same 
> > optimization paths as regular functions.
> 
> The optimization path in LLVM is the same. I think the difference lies in 
> clang IRGen: there is no "unreachable" generated for these so the optimizer 
> can't be aggressive. So this patch is not changing anything for Objective-C 
> methods and blocks, and I expect that we *already* have a test that covers 
> this behavior (if not we should add one).
Mehdi is right, the difference is in IRGen - methods and blocks never get the 
trap and unreachable IR return optmisation. I don't think we have a test for 
this though, so I added a regression test case that verifies this.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 79556.
arphaman added a comment.

The updated diff has the following changes:

- The default value for '-fstrict-return' is now the same across all platforms, 
the Darwin specific -fno-strict-return was removed.
- The 'fno-strict-return' optimisation avoidance can only be done by functions 
that return trivially copyable types.
- A new test verifies that Objective-C++ methods and blocks never get the 
return optimisation regardless of the '-fstrict-return' flag.
- The updated test adds explanation comments and uses Mehdi's advice for LABEL 
checks and common prefix.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Sema/AnalysisBasedWarnings.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/AnalysisBasedWarnings.cpp
  lib/Sema/Sema.cpp
  test/CodeGenCXX/return.cpp
  test/CodeGenObjCXX/return.mm
  test/Driver/clang_f_opts.c

Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -469,3 +469,8 @@
 // CHECK-WCHAR2: -fshort-wchar
 // CHECK-WCHAR2-NOT: -fno-short-wchar
 // DELIMITERS: {{^ *"}}
+
+// RUN: %clang -### -S -fstrict-return %s 2>&1 | FileCheck -check-prefix=CHECK-STRICT-RETURN %s
+// RUN: %clang -### -S -fno-strict-return %s 2>&1 | FileCheck -check-prefix=CHECK-NO-STRICT-RETURN %s
+// CHECK-STRICT-RETURN-NOT: "-fno-strict-return"
+// CHECK-NO-STRICT-RETURN: "-fno-strict-return"
Index: test/CodeGenObjCXX/return.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/return.mm
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -emit-llvm -fblocks -triple x86_64-apple-darwin -fstrict-return -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -fblocks -triple x86_64-apple-darwin -fstrict-return -O -o - %s | FileCheck %s
+
+@interface I
+@end
+
+@implementation I
+
+- (int)method {
+}
+
+@end
+
+enum Enum {
+  a
+};
+
+int (^block)(Enum) = ^int(Enum e) {
+  switch (e) {
+  case a:
+return 1;
+  }
+};
+
+// Ensure that both methods and blocks don't use the -fstrict-return undefined
+// behaviour optimization.
+
+// CHECK-NOT: call void @llvm.trap
+// CHECK-NOT: unreachable
Index: test/CodeGenCXX/return.cpp
===
--- test/CodeGenCXX/return.cpp
+++ test/CodeGenCXX/return.cpp
@@ -1,12 +1,105 @@
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -O -o - %s | FileCheck %s --check-prefix=CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -o - %s | FileCheck --check-prefixes=CHECK,CHECK-COMMON %s
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -O -o - %s | FileCheck %s --check-prefixes=CHECK-OPT,CHECK-COMMON
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -fno-strict-return -o - %s | FileCheck %s --check-prefixes=CHECK-NOSTRICT,CHECK-COMMON
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -fno-strict-return -Wno-return-type -o - %s | FileCheck %s --check-prefixes=CHECK-NOSTRICT,CHECK-COMMON
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -fno-strict-return -O -o - %s | FileCheck %s --check-prefixes=CHECK-NOSTRICT-OPT,CHECK-COMMON
 
-// CHECK: @_Z9no_return
-// CHECK-OPT: @_Z9no_return
+// CHECK-COMMON-LABEL: @_Z9no_return
 int no_return() {
   // CHECK:  call void @llvm.trap
   // CHECK-NEXT: unreachable
 
   // CHECK-OPT-NOT: call void @llvm.trap
   // CHECK-OPT: unreachable
+
+  // -fno-strict-return should not emit trap + unreachable but it should return
+  // an undefined value instead.
+
+  // CHECK-NOSTRICT: entry:
+  // CHECK-NOSTRICT-NEXT: alloca
+  // CHECK-NOSTRICT-NEXT: load
+  // CHECK-NOSTRICT-NEXT: ret i32
+  // CHECK-NOSTRICT-NEXT: }
+
+  // CHECK-NOSTRICT-OPT: entry:
+  // CHECK-NOSTRICT-OPT: ret i32 undef
+}
+
+enum Enum {
+  A, B
+};
+
+// CHECK-COMMON-LABEL: @_Z21alwaysOptimizedReturn4Enum
+int alwaysOptimizedReturn(Enum e) {
+  switch (e) {
+  case A: return 1;
+  case B: return 2;
+  }
+  // This function covers all the cases of 'Enum', so the undefined behaviour
+  // optimization is allowed even if -fno-strict-return is used.
+
+  // CHECK-NOSTRICT:  call void @llvm.trap()
+  // CHECK-NOSTRICT-NEXT: unreachable
+}
+
+// CHECK-NOSTRICT-LABEL: @_Z23strictlyOptimizedReturn4Enum
+int strictlyOptimizedReturn(Enum e) {
+  switch (e) {
+  case A: return 22;
+  }
+  // Undefined behaviour optimization shouldn't be used when -fno-strict-return
+  // is turned on, as not all enum cases are covered in this function.
+
+  // CHECK-NOSTRICT-NOT: call void @llvm.trap
+  // 

[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 79555.
ioeric marked 3 inline comments as done.
ioeric added a comment.

- Address comments.


https://reviews.llvm.org/D27208

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -457,6 +457,41 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, FixNonCallingFunctionReferences) {
+  std::string Code =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "namespace nb {\n"
+  "void f() {\n"
+  "auto *ref1 = A::f; auto *ref2 = a_f; auto *ref3 = s_f;\n"
+  "}\n"
+  "}  // namespace nb\n"
+  "}  // namespace na\n";
+  std::string Expected =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "\n"
+  "}  // namespace na\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "void f() {\n"
+  "auto *ref1 = na::A::f; auto *ref2 = na::a_f; auto *ref3 = na::s_f;\n"
+  "}\n"
+  "}  // namespace y\n"
+  "}  // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveAndFixGlobalVariables) {
   std::string Code = "namespace na {\n"
  "int GlobA;\n"
Index: change-namespace/ChangeNamespace.h
===
--- change-namespace/ChangeNamespace.h
+++ change-namespace/ChangeNamespace.h
@@ -76,6 +76,10 @@
   void fixUsingShadowDecl(const ast_matchers::MatchFinder::MatchResult ,
   const UsingDecl *UsingDeclaration);
 
+  void fixDeclRefExpr(const ast_matchers::MatchFinder::MatchResult ,
+  const DeclContext *UseContext, const NamedDecl *From,
+  const DeclRefExpr *Ref);
+
   // Information about moving an old namespace.
   struct MoveNamespace {
 // The start offset of the namespace block being moved in the original
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -369,11 +369,13 @@
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of-line static methods since they will be handled by nested
 // name specifiers.
 if (Func->getCanonicalDecl()->getStorageClass() ==
- 

[PATCH] D27211: [clang-format] Implement comment reflowing

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

> for these cases the
>  original Breakable{Line,Block}Comment still breaks the long lines.

Do you intend for this to continue to be the case?


https://reviews.llvm.org/D27211



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


[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM with few nits.




Comment at: change-namespace/ChangeNamespace.cpp:434
+assert(Func);
+const Decl *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");

auto



Comment at: change-namespace/ChangeNamespace.cpp:449
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const Decl *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");

auto.



Comment at: change-namespace/ChangeNamespace.cpp:713
+const DeclRefExpr *Ref) {
+SourceRange RefRange = Ref->getSourceRange();
+replaceQualifiedSymbolInDeclContext(Result, UseContext, 
RefRange.getBegin(),

nits: incorrect indentation. Should be two space.


https://reviews.llvm.org/D27208



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


[PATCH] D26991: Hoist redundant load

2016-11-29 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists requested changes to this revision.
mclow.lists added inline comments.
This revision now requires changes to proceed.



Comment at: libcxx/include/algorithm:1499
+// Load the first element from __first2 outside the loop because it is 
loop invariant
+typename iterator_traits<_RandomAccessIterator1>::value_type 
__firstElement2 = *__first2;
+

I just realized that we can't do this.
This imposes a requirement that the `value_type` be copy-constructible.

With this in place, we can't search a sequence of move-only types.


https://reviews.llvm.org/D26991



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


[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

2016-11-29 Thread Felix Berger via Phabricator via cfe-commits
flx marked an inline comment as done.
flx added inline comments.



Comment at: clang-tidy/utils/DeclRefExprUtils.cpp:127
+  match(findAll(declRefExpr(equalsNode(),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),

alexfh wrote:
> How will this work with lambdas / local classes declared inside a loop? Not 
> sure if this case is going to happen in real code, but we'd better be clear 
> about the limitations of the implementation.
Why would this not work? Could you give an example? The way the function is 
written it handles my the use case for identifying when moving the parameter is 
not safe, so I could also just move it into the UnnecessaryValueParamCheck.


https://reviews.llvm.org/D27187



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


[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

2016-11-29 Thread Felix Berger via Phabricator via cfe-commits
flx removed rL LLVM as the repository for this revision.
flx updated this revision to Diff 79550.

https://reviews.llvm.org/D27187

Files:
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tidy/utils/DeclRefExprUtils.h
  test/clang-tidy/performance-unnecessary-value-param.cpp


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -225,6 +225,15 @@
   // CHECK-FIXES: F = std::move(E);
 }
 
+// The argument could be moved but is not since copy statement is inside a 
loop.
+void PositiveNoMoveInsideLoop(ExpensiveMovableType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the parameter 'E' is copied
+  // CHECK-FIXES: void PositiveNoMoveInsideLoop(const ExpensiveMovableType& E) 
{
+  for (;;) {
+auto F = E;
+  }
+}
+
 void PositiveConstRefNotMoveConstructible(ExpensiveToCopyType T) {
   // CHECK-MESSAGES: [[@LINE-1]]:63: warning: the parameter 'T' is copied
   // CHECK-FIXES: void PositiveConstRefNotMoveConstructible(const 
ExpensiveToCopyType& T) {
Index: clang-tidy/utils/DeclRefExprUtils.h
===
--- clang-tidy/utils/DeclRefExprUtils.h
+++ clang-tidy/utils/DeclRefExprUtils.h
@@ -47,6 +47,11 @@
 bool isCopyAssignmentArgument(const DeclRefExpr , const Stmt ,
   ASTContext );
 
+// Returns true if DeclRefExpr has a loop statement (ForStmt, CXXForRangeStmt,
+// WhileStmt, DoStmt) as ancestor.
+bool hasLoopStmtAncestor(const DeclRefExpr , const Stmt ,
+ ASTContext );
+
 } // namespace decl_ref_expr
 } // namespace utils
 } // namespace tidy
Index: clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tidy/utils/DeclRefExprUtils.cpp
@@ -120,6 +120,17 @@
   return !Matches.empty();
 }
 
+bool hasLoopStmtAncestor(const DeclRefExpr , const Stmt ,
+ ASTContext ) {
+  auto Matches =
+  match(findAll(declRefExpr(equalsNode(),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),
+doStmt())),
+Stmt, Context);
+  return Matches.empty();
+}
+
 } // namespace decl_ref_expr
 } // namespace utils
 } // namespace tidy
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -104,6 +104,8 @@
   if (!IsConstQualified) {
 auto CanonicalType = Param->getType().getCanonicalType();
 if (AllDeclRefExprs.size() == 1 &&
+!utils::decl_ref_expr::hasLoopStmtAncestor(
+**AllDeclRefExprs.begin(), *Function->getBody(), *Result.Context) 
&&
 ((utils::type_traits::hasNonTrivialMoveConstructor(CanonicalType) &&
   utils::decl_ref_expr::isCopyConstructorArgument(
   **AllDeclRefExprs.begin(), *Function->getBody(),


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -225,6 +225,15 @@
   // CHECK-FIXES: F = std::move(E);
 }
 
+// The argument could be moved but is not since copy statement is inside a loop.
+void PositiveNoMoveInsideLoop(ExpensiveMovableType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the parameter 'E' is copied
+  // CHECK-FIXES: void PositiveNoMoveInsideLoop(const ExpensiveMovableType& E) {
+  for (;;) {
+auto F = E;
+  }
+}
+
 void PositiveConstRefNotMoveConstructible(ExpensiveToCopyType T) {
   // CHECK-MESSAGES: [[@LINE-1]]:63: warning: the parameter 'T' is copied
   // CHECK-FIXES: void PositiveConstRefNotMoveConstructible(const ExpensiveToCopyType& T) {
Index: clang-tidy/utils/DeclRefExprUtils.h
===
--- clang-tidy/utils/DeclRefExprUtils.h
+++ clang-tidy/utils/DeclRefExprUtils.h
@@ -47,6 +47,11 @@
 bool isCopyAssignmentArgument(const DeclRefExpr , const Stmt ,
   ASTContext );
 
+// Returns true if DeclRefExpr has a loop statement (ForStmt, CXXForRangeStmt,
+// WhileStmt, DoStmt) as ancestor.
+bool hasLoopStmtAncestor(const DeclRefExpr , const Stmt ,
+ ASTContext );
+
 } // namespace decl_ref_expr
 } // namespace utils
 } // namespace tidy
Index: clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tidy/utils/DeclRefExprUtils.cpp
+++ 

[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: hokein.
ioeric added a subscriber: cfe-commits.

https://reviews.llvm.org/D27208

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -457,6 +457,41 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, FixNonCallingFunctionReferences) {
+  std::string Code =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "namespace nb {\n"
+  "void f() {\n"
+  "auto *ref1 = A::f; auto *ref2 = a_f; auto *ref3 = s_f;\n"
+  "}\n"
+  "}  // namespace nb\n"
+  "}  // namespace na\n";
+  std::string Expected =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "\n"
+  "}  // namespace na\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "void f() {\n"
+  "auto *ref1 = na::A::f; auto *ref2 = na::a_f; auto *ref3 = na::s_f;\n"
+  "}\n"
+  "}  // namespace y\n"
+  "}  // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveAndFixGlobalVariables) {
   std::string Code = "namespace na {\n"
  "int GlobA;\n"
Index: change-namespace/ChangeNamespace.h
===
--- change-namespace/ChangeNamespace.h
+++ change-namespace/ChangeNamespace.h
@@ -76,6 +76,10 @@
   void fixUsingShadowDecl(const ast_matchers::MatchFinder::MatchResult ,
   const UsingDecl *UsingDeclaration);
 
+  void fixDeclRefExpr(const ast_matchers::MatchFinder::MatchResult ,
+  const DeclContext *UseContext, const NamedDecl *From,
+  const DeclRefExpr *Ref);
+
   // Information about moving an old namespace.
   struct MoveNamespace {
 // The start offset of the namespace block being moved in the original
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -369,11 +369,13 @@
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const Decl *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const Decl *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of-line static methods since they will be handled by nested
 // name specifiers.
 if (Func->getCanonicalDecl()->getStorageClass() ==
-

[PATCH] D27138: Extend CompilationDatabase by a field for the output filename

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: lib/Tooling/JSONCompilationDatabase.cpp:266
+nodeToCommandLine(Syntax, std::get<2>(CommandsRef[I])),
+Output ? Output->getValue(OutputStorage) : "");
   }

joerg wrote:
> klimek wrote:
> > joerg wrote:
> > > klimek wrote:
> > > > joerg wrote:
> > > > > klimek wrote:
> > > > > > Optional: I'd probably let the nodeToCommandLine handle the null 
> > > > > > value and make this code more straight forward?
> > > > > I couldn't find a way to create a synthetic node without changing the 
> > > > > YAML API.
> > > > I'm probably missing something - why would we need a synthetic node? 
> > > > Can't we just put nullptr into the vector?
> > > That's what I am doing and why this line checks output :)
> > Ok, let's ask differently: why is it a problem if we put a nullptr into the 
> > array?
> I think it just adds unnecessary complexity. An empty file name is not a 
> valid output, so "" vs Optional has the same result. I'd have prefered to 
> keep this complexity inside the JSON parser, but that would have meant 
> creating a synthetic node with value "" and there is no API for that at the 
> moment.
Don't we thus want to actually be able to err out on a higher level when 
getting an empty output dir, but be OK with an unspecified (-> nullptr) one?


Repository:
  rL LLVM

https://reviews.llvm.org/D27138



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


  1   2   >