Re: [PATCH] D12955: Fix assertion in inline assembler IR gen

2015-09-22 Thread Alexander Musman via cfe-commits
amusman closed this revision.
amusman added a comment.

Thanks, I've commited the changes in revision 248158 (but forgot to add link in 
svn commit message).
Alexander


http://reviews.llvm.org/D12955



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


[PATCH] D13048: Fix for merging decls in pragma weak

2015-09-22 Thread Alexander Musman via cfe-commits
amusman created this revision.
amusman added reviewers: rsmith, aaron.ballman, ABataev.
amusman added a subscriber: cfe-commits.

In the following example, we have a declaration of weakfoo before #pragma weak. 
extern void weakfoo();
void localfoo() { }
#pragma weak weakfoo=localfoo
There are two decls for weakfoo, this leads to assertion failure later (during 
search a decl for a call to weakfoo):
lib/Sema/SemaOverload.cpp:5583: void 
clang::Sema::AddOverloadCandidate(clang::FunctionDecl*, clang::DeclAccessPair, 
llvm::ArrayRef, clang::OverloadCandidateSet&, bool, bool, bool): 
Assertion `Proto && "Functions without a prototype cannot be overloaded"' 
failed.
I suggest to call CheckFunctionDeclaration so that 2 decls for the weakfoo are 
merged.


http://reviews.llvm.org/D13048

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/pragma-weak.c
  test/Sema/pragma-weak.c

Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5198,17 +5198,22 @@
   assert(isa(ND) || isa(ND));
   NamedDecl *NewD = nullptr;
   if (FunctionDecl *FD = dyn_cast(ND)) {
-FunctionDecl *NewFD;
-// FIXME: Missing call to CheckFunctionDeclaration().
 // FIXME: Mangling?
 // FIXME: Is the qualifier info correct?
 // FIXME: Is the DeclContext correct?
-NewFD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(),
- Loc, Loc, DeclarationName(II),
- FD->getType(), FD->getTypeSourceInfo(),
- SC_None, false/*isInlineSpecified*/,
- FD->hasPrototype(),
- false/*isConstexprSpecified*/);
+
+LookupResult Previous(*this, II, Loc, LookupOrdinaryName);
+LookupParsedName(Previous, TUScope, nullptr, true);
+
+auto NewFD = FunctionDecl::Create(
+FD->getASTContext(), FD->getDeclContext(), Loc, Loc,
+DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None,
+false /*isInlineSpecified*/, FD->hasPrototype(),
+false /*isConstexprSpecified*/);
+
+CheckFunctionDeclaration(TUScope, NewFD, Previous,
+ false /*IsExplicitSpecialization*/);
+
 NewD = NewFD;
 
 if (FD->getQualifier())
Index: test/CodeGen/pragma-weak.c
===
--- test/CodeGen/pragma-weak.c
+++ test/CodeGen/pragma-weak.c
@@ -17,6 +17,7 @@
 // CHECK-DAG: @mix2 = weak alias void (), void ()* @__mix2
 // CHECK-DAG: @a1 = weak alias void (), void ()* @__a1
 // CHECK-DAG: @xxx = weak alias void (), void ()* @__xxx
+// CHECK-DAG: @weakfoo = weak alias void {{.*}} @localfoo
 
 
 
@@ -173,6 +174,14 @@
 // CHECK: declare extern_weak i32 @PR16705b()
 // CHECK: declare extern_weak i32 @PR16705c()
 
+// In this test case, we have a declaration of weakfoo before #pragma weak.
+// Test that 2 decls for the weakfoo are merged.
+extern void weakfoo();
+void localfoo() { }
+#pragma weak weakfoo=localfoo
+extern void externmain() { return weakfoo(); }
+// CHECK-LABEL: define void @externmain()
+// CHECK: call{{.*}}@weakfoo
 
 / TODO: stuff that still doesn't work
 
Index: test/Sema/pragma-weak.c
===
--- test/Sema/pragma-weak.c
+++ test/Sema/pragma-weak.c
@@ -9,3 +9,9 @@
 #pragma weak a3 = __a3 // expected-note {{previous definition}}
 void a3(void) __attribute((alias("__a3"))); // expected-error {{redefinition 
of 'a3'}}
 void __a3(void) {}
+
+extern void weak2foo(int); // expected-note {{previous declaration is here}} 
expected-note {{'weak2foo' declared here}}
+void local2foo(double d1, double d2) { }
+#pragma weak weak2foo=local2foo // expected-error {{conflicting types for 
'weak2foo'}}
+extern void extern2main() { return weak2foo(); } // expected-error {{too few 
arguments to function call, expected 1, have 0}}
+


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5198,17 +5198,22 @@
   assert(isa(ND) || isa(ND));
   NamedDecl *NewD = nullptr;
   if (FunctionDecl *FD = dyn_cast(ND)) {
-FunctionDecl *NewFD;
-// FIXME: Missing call to CheckFunctionDeclaration().
 // FIXME: Mangling?
 // FIXME: Is the qualifier info correct?
 // FIXME: Is the DeclContext correct?
-NewFD = FunctionDecl::Create(FD->getASTContext(), FD->getDeclContext(),
- Loc, Loc, DeclarationName(II),
- FD->getType(), FD->getTypeSourceInfo(),
- SC_None, false/*isInlineSpecified*/,
- FD->hasPrototype(),
- false/*isConstexprSpecified*/);
+
+LookupResult Previous(*this, II, Loc, Look

Re: [PATCH] D10305: [Clang Static Analyzer] Bug identification

2015-09-22 Thread Daniel Krupp via cfe-commits
dkrupp added a comment.

Hi,

Regarding testing:
I think we should create a RecursiveASTvistor based "test checker" that matches 
every statement and declaration and reports a bug there.
Then we could create a test file similar to what we have in 
/tools/clang/test/Analysis/diagnostics/report-issues-within-main-file.cpp
where the expected plist output can be written at the end of the file.

I am not sure though where to register this test "test checker". Should it be a 
dynamically loadable checker similar to 
/tools/clang/examples/analyzer-plugin/MainCallChecker.cpp or it should be a 
debug checker like (debug.DumpCalls)?

The advantage of the dynamic lib based solution is that we would not need to 
statically add it to clang-sa.

What do you think?

Regards,
Daniel


http://reviews.llvm.org/D10305



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


[clang-tools-extra] r248252 - misc-unused-parameter: Ignore lambda static invokers.

2015-09-22 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Sep 22 04:20:20 2015
New Revision: 248252

URL: http://llvm.org/viewvc/llvm-project?rev=248252&view=rev
Log:
misc-unused-parameter: Ignore lambda static invokers.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp?rev=248252&r1=248251&r2=248252&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp Tue Sep 
22 04:20:20 2015
@@ -101,6 +101,9 @@ void UnusedParametersCheck::check(const
   if (!Function->doesThisDeclarationHaveABody() ||
   !Function->hasWrittenPrototype())
 return;
+  if (const auto *Method = dyn_cast(Function))
+if (Method->isLambdaStaticInvoker())
+  return;
   for (unsigned i = 0, e = Function->getNumParams(); i != e; ++i) {
 const auto *Param = Function->getParamDecl(i);
 if (Param->isUsed() || Param->isReferenced() || !Param->getDeclName() ||

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp?rev=248252&r1=248251&r2=248252&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp Tue Sep 
22 04:20:20 2015
@@ -1,6 +1,6 @@
 // RUN: echo "static void staticFunctionHeader(int i) {}" > %T/header.h
 // RUN: echo "static void staticFunctionHeader(int  /*i*/) {}" > 
%T/header-fixed.h
-// RUN: %python %S/check_clang_tidy.py %s misc-unused-parameters %t 
-header-filter='.*' -- -fno-delayed-template-parsing
+// RUN: %python %S/check_clang_tidy.py %s misc-unused-parameters %t 
-header-filter='.*' -- -std=c++11 -fno-delayed-template-parsing
 // RUN: diff %T/header.h %T/header-fixed.h
 
 #include "header.h"
@@ -25,6 +25,9 @@ void c(int *i) {}
 void g(int i); // Don't remove stuff in declarations
 void h(int i) { (void)i; } // Don't remove used parameters
 
+bool useLambda(int (*fn)(int));
+static bool static_var = useLambda([] (int a) { return a; });
+
 // Remove parameters of local functions
 // 
 static void staticFunctionA(int i);


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


r248254 - clang-format: Fix alignConsecutiveAssignments.

2015-09-22 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Sep 22 04:32:00 2015
New Revision: 248254

URL: http://llvm.org/viewvc/llvm-project?rev=248254&view=rev
Log:
clang-format: Fix alignConsecutiveAssignments.

It wasn't correctly handling this case:

  int oneTwoThree = 123;
  int oneTwo  = 12;
  method();

Review: http://reviews.llvm.org/D12369
Patch by Beren Minor. Thank you!

Modified:
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=248254&r1=248253&r2=248254&view=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Tue Sep 22 04:32:00 2015
@@ -156,41 +156,53 @@ void WhitespaceManager::alignConsecutive
   unsigned EndOfSequence = 0;
   bool FoundAssignmentOnLine = false;
   bool FoundLeftParenOnLine = false;
-  unsigned CurrentLine = 0;
 
+  // Aligns a sequence of assignment tokens, on the MinColumn column.
+  //
+  // Sequences start from the first assignment token to align, and end at the
+  // first token of the first line that doesn't need to be aligned.
+  //
+  // We need to adjust the StartOfTokenColumn of each Change that is on a line
+  // containing any assignment to be aligned and located after such assignment
   auto AlignSequence = [&] {
-alignConsecutiveAssignments(StartOfSequence, EndOfSequence, MinColumn);
+if (StartOfSequence > 0 && StartOfSequence < EndOfSequence)
+  alignConsecutiveAssignments(StartOfSequence, EndOfSequence, MinColumn);
 MinColumn = 0;
 StartOfSequence = 0;
 EndOfSequence = 0;
   };
 
   for (unsigned i = 0, e = Changes.size(); i != e; ++i) {
-if (Changes[i].NewlinesBefore != 0) {
-  CurrentLine += Changes[i].NewlinesBefore;
-  if (StartOfSequence > 0 &&
-  (Changes[i].NewlinesBefore > 1 || !FoundAssignmentOnLine)) {
-EndOfSequence = i;
+if (Changes[i].NewlinesBefore > 0) {
+  EndOfSequence = i;
+  // If there is a blank line or if the last line didn't contain any
+  // assignment, the sequence ends here.
+  if (Changes[i].NewlinesBefore > 1 || !FoundAssignmentOnLine) {
+// NB: In the latter case, the sequence should end at the beggining of
+// the previous line, but it doesn't really matter as there is no
+// assignment on it
 AlignSequence();
   }
+
   FoundAssignmentOnLine = false;
   FoundLeftParenOnLine = false;
 }
 
-if ((Changes[i].Kind == tok::equal &&
- (FoundAssignmentOnLine || ((Changes[i].NewlinesBefore > 0 ||
- Changes[i + 1].NewlinesBefore > 0 ||
-(!FoundLeftParenOnLine && Changes[i].Kind == tok::r_paren)) {
-  if (StartOfSequence > 0)
-AlignSequence();
+// If there is more than one "=" per line, or if the "=" appears first on
+// the line of if it appears last, end the sequence
+if (Changes[i].Kind == tok::equal &&
+(FoundAssignmentOnLine || Changes[i].NewlinesBefore > 0 ||
+ Changes[i + 1].NewlinesBefore > 0)) {
+  AlignSequence();
+} else if (!FoundLeftParenOnLine && Changes[i].Kind == tok::r_paren) {
+  AlignSequence();
 } else if (Changes[i].Kind == tok::l_paren) {
   FoundLeftParenOnLine = true;
-  if (!FoundAssignmentOnLine && StartOfSequence > 0)
+  if (!FoundAssignmentOnLine)
 AlignSequence();
 } else if (!FoundAssignmentOnLine && !FoundLeftParenOnLine &&
Changes[i].Kind == tok::equal) {
   FoundAssignmentOnLine = true;
-  EndOfSequence = i;
   if (StartOfSequence == 0)
 StartOfSequence = i;
 
@@ -199,36 +211,34 @@ void WhitespaceManager::alignConsecutive
 }
   }
 
-  if (StartOfSequence > 0) {
-EndOfSequence = Changes.size();
-AlignSequence();
-  }
+  EndOfSequence = Changes.size();
+  AlignSequence();
 }
 
 void WhitespaceManager::alignConsecutiveAssignments(unsigned Start,
 unsigned End,
 unsigned Column) {
-  bool AlignedAssignment = false;
-  int PreviousShift = 0;
+  bool FoundAssignmentOnLine = false;
+  int Shift = 0;
   for (unsigned i = Start; i != End; ++i) {
-int Shift = 0;
-if (Changes[i].NewlinesBefore > 0)
-  AlignedAssignment = false;
-if (!AlignedAssignment && Changes[i].Kind == tok::equal) {
+if (Changes[i].NewlinesBefore > 0) {
+  FoundAssignmentOnLine = false;
+  Shift = 0;
+}
+
+// If this is the first assignment to be aligned, remember by how many
+// spaces it has to be shifted, so the rest of the changes on the line are
+// shifted by the same amount
+if (!FoundAssignmentOnLine && Changes[i].Kind == tok::equal) {
+  FoundAssignmentOnLine = true;
   Shift = Column - C

Re: [PATCH] D12369: [clang-format] Fix alignConsecutiveAssignments not working properly

2015-09-22 Thread Daniel Jasper via cfe-commits
djasper closed this revision.
djasper added a comment.

Submitted as r248254, thank you!


http://reviews.llvm.org/D12369



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


Re: [PATCH] D12501: [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key

2015-09-22 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good. Do you have commit access?



Comment at: lib/Format/TokenAnnotator.cpp:377
@@ -376,1 +376,3 @@
+(!Contexts.back().ColonIsDictLiteral ||
+ Style.Language != FormatStyle::LK_Cpp)) ||
Style.Language == FormatStyle::LK_Proto) &&

ksuther wrote:
> djasper wrote:
> > Why the language check? If it is needed, can you add a test?
> The language check is so that this only applies to Objective-C literals. 
> Protocol Buffers already have a test suite that tests the conditional here 
> (FormatTestProto.cpp). The reason for the check is that the tree for 
> Objective-C literals and Protocol Buffers looks the same in this situation, 
> but the format behavior needs to differ.
Ah, I see, thank you.


http://reviews.llvm.org/D12501



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


Re: [PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch

2015-09-22 Thread Daniel Jasper via cfe-commits
djasper added a comment.

If that's ok for you, I'd like to try and restructure the existing options 
first. I'll try to complete that this week. Will update this review once I am 
done.


http://reviews.llvm.org/D12492



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


Re: [PATCH] D11693: clang-format: Support generalized lambda captures.

2015-09-22 Thread Daniel Jasper via cfe-commits
djasper added inline comments.


Comment at: lib/Format/UnwrappedLineParser.cpp:1064
@@ +1063,3 @@
+// parseBracedList. For now, parsing matching braces ([], (), {}) is
+// good enough.
+if (FormatTok->is(tok::l_paren)) {

strager wrote:
> djasper wrote:
> > Ah, parseAngle doesn't exist here. I was thinking about the TokenAnnotator.
> > 
> > I don't understand your comment about mid-stream. This is precisely about 
> > the case where the input is corrupt so that clang-format can recover and 
> > doesn't just parse the reset of the file input the lambda introducer.
> > This is precisely about the case where the input is corrupt so that 
> > clang-format can recover and doesn't just parse the reset of the file input 
> > the lambda introducer.
> 
> If I write this test:
> 
> ```
> verifyFormat("return [}] {};\n");
> ```
> 
> I get this output:
> 
> ```
> /Users/strager/Projects/llvm/tools/clang/unittests/Format/FormatTest.cpp:42: 
> Failure
> Value of: IncompleteFormat
>   Actual: true
> Expected: ExpectedIncompleteFormat
> Which is: false
> return [}] {};
> 
> 
> 
> /Users/strager/Projects/llvm/tools/clang/unittests/Format/FormatTest.cpp:65: 
> Failure
> Value of: format(test::messUp(Code), Style)
>   Actual: "return [\n}] {};\n"
> Expected: Code.str()
> Which is: "return [}] {};\n"
> ```
> 
> How can I fix this?
So, there are two errors in the test.

1. clang-format detects that there is a syntax error and reports this. Use 
verifyIncompleteFormat instead of verifyFormat.

2. clang-format adds a '\n' after the opening square bracket. Add that in your 
test string.


http://reviews.llvm.org/D11693



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


Re: [PATCH] D12489: [clang-format] Fixed missing space between Obj-C for/in and a typecast

2015-09-22 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good. Do you have commit access?


http://reviews.llvm.org/D12489



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


Re: [PATCH] D10833: Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface

2015-09-22 Thread guibufolo+l...@gmail.com via cfe-commits
RedX2501 added a comment.

Ping


http://reviews.llvm.org/D10833



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


Re: [PATCH] D10834: Added functions to retrieve information about variable storage in libclang and its python bindings.

2015-09-22 Thread guibufolo+l...@gmail.com via cfe-commits
RedX2501 added a comment.

Ping


http://reviews.llvm.org/D10834



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


Re: [PATCH] D12761: MPI-Checker patch for Clang Static Analyzer

2015-09-22 Thread Alexander Droste via cfe-commits
Alexander_Droste added a comment.

In http://reviews.llvm.org/D12761#250296, @zaks.anna wrote:

> > Sorry, I should have been more precise. The check tests if a request is in 
> > use by a nonblocking 
>
> >  call at the end of a function. But the request can still be alive after 
> > return. You can think of it as
>
> >  a pointer for which the memory must be freed in the function it was 
> > allocated. But the pointer 
>
> >  can exist in global space outside a function. Multiple functions can use 
> > the same request.
>
> >  So the symbol is not necessarily dead at the end of a function.
>
>
> Is it the API requirement that the wait is performed in the same function?


That's a good catch. It is no API requirement that a nonblocking call is 
matched by a wait within
the scope of a function. I think for C this would be reasonable but for CPP it 
is not sufficient,
as the matching could be realised with RAII or lambdas. I will change the check 
so that
it makes use of the `checkDeadSymbols` callback.



Comment at: 
tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIBugReporter.cpp:137
@@ +136,3 @@
+
+  // This is never reached...
+  llvm::outs() << ""

zaks.anna wrote:
> Alexander_Droste wrote:
> > Alexander_Droste wrote:
> > > I figured out what the problem about the request retrieval is:
> > > `REGISTER_MAP_WITH_PROGRAMSTATE(RequestMap, const 
> > > clang::ento::clang::mpi::Request)`
> > > The documentation states: "The macro should not be used inside 
> > > namespaces, or for traits that must
> > > be accessible from more than one translation unit." I think I need some 
> > > advice here, how to make the  
> > > same RequestMap accessible in multiple translation units.
> > How about this: 
> > We could capture the `PathDiagnosticLocation` of the LastUser in each 
> > `mpi::Request` as a member. The `RequestMap` could then be local to 
> > `MPICheckerPathSensitive.cpp` and no visitors would be needed. The bug 
> > reporter class would then not need to know anything about the request map. 
> > The only function I can't find to realise this concept would be something 
> > like: `Report->addPathDiagnosticLocation()`.
> Almost all other checkers occupy a single file per checker. This is not much 
> more complicated than the others so you could do the same. This would 
> probably be better for consistency, but I do not have such a strong opinion 
> about it and see why you might want to have separate files. 
> 
> See TaintManager.h for the example of how to share the program state maps 
> across translation units.
Thanks for pointing out `TaintManager.h`. I'll try to derive a solution from 
that.


Comment at: tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPITypes.h:66
@@ +65,3 @@
+// Register data structure for path-sensitive analysis. The map stores MPI
+// requests which are identified by their memory region. Requests are used in
+// MPI to complete nonblocking operations with wait operations. Requests can be

zaks.anna wrote:
> Look at the ways the other checkers reference a node that occurred earlier 
> along the symbolic execution path. For example, malloc checker tracks the 
> state of each pointer, which could be "Allocated", "Freed"... When we report 
> a leak, for example, the state would be "Allocated" and the symbol would be 
> dead. The BugReporterVisitor walks up the symbolic path on which the issue 
> occurred and prints an extra note at the place where the node is allocated. 
> It knows at which node the pointer is allocated because that is where the 
> state of the pointer changes from untracked to "Allocated".
> 
Ok, I will use the same pattern. Thanks for the explanation.


http://reviews.llvm.org/D12761



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


[PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Dimitry Andric via cfe-commits
dim created this revision.
dim added reviewers: EricWF, mclow.lists.
dim added subscribers: majnemer, jroelofs, cfe-commits.
Herald added a subscriber: aemerson.

In rL241532, atomic_support.h was added, which provides handling of
atomic operations for libc++.  When atomic builtins are not available,
it emits a warning about being unsupported, but it still provides a
number of stubs for the required functions.

However, it misses a stub for __libcpp_relaxed_store().  Add it, by
using the same implementation as for __libcpp_atomic_store().

(Note that I encountered this on arm-freebsd, which still defaults to
armv4, and does not have the runtime libcalls to support atomic
builtins.  For now, I have simply disabled using them.)

http://reviews.llvm.org/D13051

Files:
  src/include/atomic_support.h

Index: src/include/atomic_support.h
===
--- src/include/atomic_support.h
+++ src/include/atomic_support.h
@@ -103,6 +103,13 @@
 *__dest = __val;
 }
 
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
+{
+*__dest = __val;
+}
+
 template 
 inline _LIBCPP_INLINE_VISIBILITY
 _ValueType __libcpp_atomic_load(_ValueType const* __val,


Index: src/include/atomic_support.h
===
--- src/include/atomic_support.h
+++ src/include/atomic_support.h
@@ -103,6 +103,13 @@
 *__dest = __val;
 }
 
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
+{
+*__dest = __val;
+}
+
 template 
 inline _LIBCPP_INLINE_VISIBILITY
 _ValueType __libcpp_atomic_load(_ValueType const* __val,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread David Chisnall via cfe-commits
theraven added a comment.

Looks fine (though this probably won't actually work correctly on ARMv4).

It's a shame that libc++ decided to reinvent the wheel here and not use the C11 
atomics support...


http://reviews.llvm.org/D13051



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


[PATCH] D13052: Add NamingStyle option to modernize-loop-convert.

2015-09-22 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: klimek, cfe-commits.

Add an option to specify wich style must be followed when choosing the new 
index name.

http://reviews.llvm.org/D13052

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tidy/modernize/LoopConvertCheck.h
  clang-tidy/modernize/LoopConvertUtils.cpp
  clang-tidy/modernize/LoopConvertUtils.h
  clang-tidy/modernize/ModernizeTidyModule.cpp
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp

Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -14,9 +14,9 @@
 int b = arr[i][a];
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : arr)
+  // CHECK-FIXES: for (auto & Elem : arr)
   // CHECK-FIXES-NEXT: int a = 0;
-  // CHECK-FIXES-NEXT: int b = elem[a];
+  // CHECK-FIXES-NEXT: int b = Elem[a];
 
   for (int j = 0; j < M; ++j) {
 int a = 0;
@@ -64,21 +64,21 @@
 int z = Arr[i].x + t.x;
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Arr)
-  // CHECK-FIXES-NEXT: Val &t = elem;
+  // CHECK-FIXES: for (auto & Elem : Arr)
+  // CHECK-FIXES-NEXT: Val &t = Elem;
   // CHECK-FIXES-NEXT: int y = t.x;
-  // CHECK-FIXES-NEXT: int z = elem.x + t.x;
+  // CHECK-FIXES-NEXT: int z = Elem.x + t.x;
 
   for (int i = 0; i < N; ++i) {
 Val t = Arr[i];
 int y = t.x;
 int z = Arr[i].x + t.x;
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Arr)
-  // CHECK-FIXES-NEXT: Val t = elem;
+  // CHECK-FIXES: for (auto & Elem : Arr)
+  // CHECK-FIXES-NEXT: Val t = Elem;
   // CHECK-FIXES-NEXT: int y = t.x;
-  // CHECK-FIXES-NEXT: int z = elem.x + t.x;
+  // CHECK-FIXES-NEXT: int z = Elem.x + t.x;
 
   // The same for pseudo-arrays like std::vector (or here dependent)
   // which provide a subscript operator[].
@@ -108,8 +108,8 @@
 int y = t.x;
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Arr)
-  // CHECK-FIXES-NEXT: Val &t = func(elem);
+  // CHECK-FIXES: for (auto & Elem : Arr)
+  // CHECK-FIXES-NEXT: Val &t = func(Elem);
   // CHECK-FIXES-NEXT: int y = t.x;
 
   int IntArr[N];
@@ -164,8 +164,8 @@
 IntRef Int(IntArr[i]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : IntArr)
-  // CHECK-FIXES-NEXT: IntRef Int(elem);
+  // CHECK-FIXES: for (auto & Elem : IntArr)
+  // CHECK-FIXES-NEXT: IntRef Int(Elem);
 }
 
 
@@ -218,8 +218,8 @@
 unsigned othersize = other.size();
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : dep)
-  // CHECK-FIXES-NEXT: printf("%d\n", elem);
+  // CHECK-FIXES: for (auto & Elem : dep)
+  // CHECK-FIXES-NEXT: printf("%d\n", Elem);
   // CHECK-FIXES-NEXT: const int& idx = other[0];
   // CHECK-FIXES-NEXT: unsigned othersize = other.size();
 
@@ -418,10 +418,10 @@
   }
   // CHECK-MESSAGES: :[[@LINE-8]]:3: warning: use range-based for loop instead
   // CHECK-MESSAGES: :[[@LINE-8]]:5: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES: for (auto & Elem : Arr)
   // CHECK-FIXES-NEXT: for (auto & Arr_j : Arr)
-  // CHECK-FIXES-NEXT: int k = elem.x + Arr_j.x;
-  // CHECK-FIXES-NOT: int l = elem.x + elem.x;
+  // CHECK-FIXES-NEXT: int k = Elem.x + Arr_j.x;
+  // CHECK-FIXES-NOT: int l = Elem.x + Elem.x;
 
   // The inner loop is also convertible, but doesn't need to be converted
   // immediately. FIXME: update this test when that changes.
@@ -432,9 +432,9 @@
 }
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Nest)
+  // CHECK-FIXES: for (auto & Elem : Nest)
   // CHECK-FIXES-NEXT: for (int j = 0; j < M; ++j)
-  // CHECK-FIXES-NEXT: printf("Got item %d", elem[j].x);
+  // CHECK-FIXES-NEXT: printf("Got item %d", Elem[j].x);
 
   // Note that the order of M and N are switched for this test.
   for (int j = 0; j < M; ++j) {
@@ -445,8 +445,8 @@
   // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead
   // CHECK-FIXES-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[i])
   // CHECK-FIXES: for (int j = 0; j < M; ++j)
-  // CHECK-FIXES-NEXT: for (auto & elem : Nest)
-  // CHECK-FIXES-NEXT: printf("Got item %d", elem[j].x);
+  // CHECK-FIXES-NEXT: for (auto & Elem : Nest)
+  // CHECK-FIXES-NEXT: printf("Got item %d", Elem[j].x);
 
   // The inner loop is also convertible.
   Nested NestT;
@@ -456,8 +456,8 @@
 }
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warni

Re: [PATCH] D12492: [Clang-Format] Add AlwaysBreakBeforeElse and AlwaysBreakBeforeCatch Style to avoid cuddled else/catch

2015-09-22 Thread Paul Hoad via cfe-commits
MyDeveloperDay added a comment.

@djasper I'm more than happy with that, just ping me if you need me the rework 
the change afterwards to fit


http://reviews.llvm.org/D12492



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


Re: [PATCH] D13052: Add NamingStyle option to modernize-loop-convert.

2015-09-22 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 35362.
angelgarcia added a comment.

Remove related FIXME.


http://reviews.llvm.org/D13052

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tidy/modernize/LoopConvertCheck.h
  clang-tidy/modernize/LoopConvertUtils.cpp
  clang-tidy/modernize/LoopConvertUtils.h
  clang-tidy/modernize/ModernizeTidyModule.cpp
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp

Index: test/clang-tidy/modernize-loop-convert-extra.cpp
===
--- test/clang-tidy/modernize-loop-convert-extra.cpp
+++ test/clang-tidy/modernize-loop-convert-extra.cpp
@@ -14,9 +14,9 @@
 int b = arr[i][a];
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : arr)
+  // CHECK-FIXES: for (auto & Elem : arr)
   // CHECK-FIXES-NEXT: int a = 0;
-  // CHECK-FIXES-NEXT: int b = elem[a];
+  // CHECK-FIXES-NEXT: int b = Elem[a];
 
   for (int j = 0; j < M; ++j) {
 int a = 0;
@@ -64,21 +64,21 @@
 int z = Arr[i].x + t.x;
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Arr)
-  // CHECK-FIXES-NEXT: Val &t = elem;
+  // CHECK-FIXES: for (auto & Elem : Arr)
+  // CHECK-FIXES-NEXT: Val &t = Elem;
   // CHECK-FIXES-NEXT: int y = t.x;
-  // CHECK-FIXES-NEXT: int z = elem.x + t.x;
+  // CHECK-FIXES-NEXT: int z = Elem.x + t.x;
 
   for (int i = 0; i < N; ++i) {
 Val t = Arr[i];
 int y = t.x;
 int z = Arr[i].x + t.x;
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Arr)
-  // CHECK-FIXES-NEXT: Val t = elem;
+  // CHECK-FIXES: for (auto & Elem : Arr)
+  // CHECK-FIXES-NEXT: Val t = Elem;
   // CHECK-FIXES-NEXT: int y = t.x;
-  // CHECK-FIXES-NEXT: int z = elem.x + t.x;
+  // CHECK-FIXES-NEXT: int z = Elem.x + t.x;
 
   // The same for pseudo-arrays like std::vector (or here dependent)
   // which provide a subscript operator[].
@@ -108,8 +108,8 @@
 int y = t.x;
   }
   // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Arr)
-  // CHECK-FIXES-NEXT: Val &t = func(elem);
+  // CHECK-FIXES: for (auto & Elem : Arr)
+  // CHECK-FIXES-NEXT: Val &t = func(Elem);
   // CHECK-FIXES-NEXT: int y = t.x;
 
   int IntArr[N];
@@ -164,8 +164,8 @@
 IntRef Int(IntArr[i]);
   }
   // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : IntArr)
-  // CHECK-FIXES-NEXT: IntRef Int(elem);
+  // CHECK-FIXES: for (auto & Elem : IntArr)
+  // CHECK-FIXES-NEXT: IntRef Int(Elem);
 }
 
 
@@ -218,8 +218,8 @@
 unsigned othersize = other.size();
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : dep)
-  // CHECK-FIXES-NEXT: printf("%d\n", elem);
+  // CHECK-FIXES: for (auto & Elem : dep)
+  // CHECK-FIXES-NEXT: printf("%d\n", Elem);
   // CHECK-FIXES-NEXT: const int& idx = other[0];
   // CHECK-FIXES-NEXT: unsigned othersize = other.size();
 
@@ -418,10 +418,10 @@
   }
   // CHECK-MESSAGES: :[[@LINE-8]]:3: warning: use range-based for loop instead
   // CHECK-MESSAGES: :[[@LINE-8]]:5: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Arr)
+  // CHECK-FIXES: for (auto & Elem : Arr)
   // CHECK-FIXES-NEXT: for (auto & Arr_j : Arr)
-  // CHECK-FIXES-NEXT: int k = elem.x + Arr_j.x;
-  // CHECK-FIXES-NOT: int l = elem.x + elem.x;
+  // CHECK-FIXES-NEXT: int k = Elem.x + Arr_j.x;
+  // CHECK-FIXES-NOT: int l = Elem.x + Elem.x;
 
   // The inner loop is also convertible, but doesn't need to be converted
   // immediately. FIXME: update this test when that changes.
@@ -432,9 +432,9 @@
 }
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : Nest)
+  // CHECK-FIXES: for (auto & Elem : Nest)
   // CHECK-FIXES-NEXT: for (int j = 0; j < M; ++j)
-  // CHECK-FIXES-NEXT: printf("Got item %d", elem[j].x);
+  // CHECK-FIXES-NEXT: printf("Got item %d", Elem[j].x);
 
   // Note that the order of M and N are switched for this test.
   for (int j = 0; j < M; ++j) {
@@ -445,8 +445,8 @@
   // CHECK-MESSAGES: :[[@LINE-4]]:5: warning: use range-based for loop instead
   // CHECK-FIXES-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[i])
   // CHECK-FIXES: for (int j = 0; j < M; ++j)
-  // CHECK-FIXES-NEXT: for (auto & elem : Nest)
-  // CHECK-FIXES-NEXT: printf("Got item %d", elem[j].x);
+  // CHECK-FIXES-NEXT: for (auto & Elem : Nest)
+  // CHECK-FIXES-NEXT: printf("Got item %d", Elem[j].x);
 
   // The inner loop is also convertible.
   Nested NestT;
@@ -456,8 +456,8 @@
 }
   }
   // CHECK-MESSAGES: :[[@LINE-5]]:3: warning: use range-based for loop instead
-  // CHECK-FIXES: for (auto & elem : NestT)
-  // CHECK-FIXES-NEXT: for (T

[PATCH] D13054: [libc++] Un-guarded reference to uncaught_exception() in ostream header

2015-09-22 Thread Asiri Rathnayake via cfe-commits
rmaprath created this revision.
rmaprath added a subscriber: cfe-commits.

The ostream header contains an un-guarded reference to uncaught_exception() 
which causes it to drag in the exception handling machinery even when not 
required (i.e. when compiling with -fno-exceptions). There are no tests for 
this fix as the behaviour is only visible at link time (unnecessary symbols 
present and increased image size).

http://reviews.llvm.org/D13054

Files:
  include/ostream

Index: include/ostream
===
--- include/ostream
+++ include/ostream
@@ -260,7 +260,10 @@
 basic_ostream<_CharT, _Traits>::sentry::~sentry()
 {
 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
-  && !uncaught_exception())
+#ifndef _LIBCPP_NO_EXCEPTIONS
+  && !uncaught_exception()
+#endif  // _LIBCPP_NO_EXCEPTIONS
+   )
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
 try


Index: include/ostream
===
--- include/ostream
+++ include/ostream
@@ -260,7 +260,10 @@
 basic_ostream<_CharT, _Traits>::sentry::~sentry()
 {
 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
-  && !uncaught_exception())
+#ifndef _LIBCPP_NO_EXCEPTIONS
+  && !uncaught_exception()
+#endif  // _LIBCPP_NO_EXCEPTIONS
+   )
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
 try
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13054: [libc++] Un-guarded reference to uncaught_exception() in ostream header

2015-09-22 Thread Asiri Rathnayake via cfe-commits
rmaprath updated this revision to Diff 35367.
rmaprath added a comment.

Updated patch with bit more context (-U20).


http://reviews.llvm.org/D13054

Files:
  include/ostream

Index: include/ostream
===
--- include/ostream
+++ include/ostream
@@ -260,7 +260,10 @@
 basic_ostream<_CharT, _Traits>::sentry::~sentry()
 {
 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
-  && !uncaught_exception())
+#ifndef _LIBCPP_NO_EXCEPTIONS
+  && !uncaught_exception()
+#endif  // _LIBCPP_NO_EXCEPTIONS
+   )
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
 try


Index: include/ostream
===
--- include/ostream
+++ include/ostream
@@ -260,7 +260,10 @@
 basic_ostream<_CharT, _Traits>::sentry::~sentry()
 {
 if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
-  && !uncaught_exception())
+#ifndef _LIBCPP_NO_EXCEPTIONS
+  && !uncaught_exception()
+#endif  // _LIBCPP_NO_EXCEPTIONS
+   )
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
 try
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-22 Thread Alexandros Lamprineas via cfe-commits
labrinea added a comment.

GCC online docs 
  state:

> -ffast-math

>  Might allow some programs designed to not be too dependent on IEEE behavior 
> for floating-point to run faster, or die trying. Sets 
> -funsafe-math-optimizations, -ffinite-math-only, and -fno-trapping-math.

> 

> -funsafe-math-optimizations

>  Allow optimizations that may be give incorrect results for certain IEEE 
> inputs.

> 

> -ffinite-math-only

> Allow optimizations for floating-point arithmetic that assume that arguments 
> and results are not NaNs or +-Infs.

> 

> -fno-trapping-math

>  Allow the compiler to assume that floating-point arithmetic will not 
> generate traps on any inputs. This is useful, for example, when running a 
> program using IEEE "non-stop" floating-point arithmetic.


Does this mean, define _ARM_FP_FAST when all these three flags are set 
(-funsafe-math-optimizations, -ffinite-math-only, and -fno-trapping-math)? We 
are currently checking ("-ffast-math" or "-ffinite-math-only").

ACLE docs state:

> __ARM_FP_FAST is defined to 1 if floating-point optimizations may occur such 
> that the computed results are different from those prescribed by the order of 
> operations according to the C standard. Examples of such optimizations would 
> be reassociation of expressions to reduce depth, and replacement of a 
> division by constant with multiplication by its reciprocal.



http://reviews.llvm.org/D12633



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


Re: [PATCH] D13048: Fix for merging decls in pragma weak

2015-09-22 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.


Comment at: lib/Sema/SemaDeclAttr.cpp:5201
@@ -5200,5 +5200,3 @@
   if (FunctionDecl *FD = dyn_cast(ND)) {
-FunctionDecl *NewFD;
-// FIXME: Missing call to CheckFunctionDeclaration().
 // FIXME: Mangling?
 // FIXME: Is the qualifier info correct?

If we're in this code, any chance you can also look at the other FIXME 
statements? If not, that's fine -- this is still positive movement. But it's 
usually best to tackle all of these at once while it's fresh in someone's mind 
what's happening here.


http://reviews.llvm.org/D13048



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


Re: [PATCH] D13052: Add NamingStyle option to modernize-loop-convert.

2015-09-22 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-tidy/modernize/LoopConvertUtils.cpp:815
@@ -815,3 +814,3 @@
   std::string IteratorName;
   std::string ContainerName;
   if (TheContainer)

This can be a StringRef to avoid some copies.


Comment at: clang-tidy/modernize/LoopConvertUtils.cpp:820
@@ -820,3 +819,3 @@
   size_t Len = ContainerName.length();
   if (Len > 1 && ContainerName[Len - 1] == 's')
 IteratorName = ContainerName.substr(0, Len - 1);

Once `ContainerName` is a StringRef, this can be replaced with

  if (ContainerName.endswith("s"))


Comment at: clang-tidy/modernize/LoopConvertUtils.cpp:828
@@ -828,3 +827,3 @@
 
   IteratorName = ContainerName + "_" + OldIndex->getName().str();
   if (!declarationExists(IteratorName))

The underscore here is not needed in the LLVM style.


Comment at: clang-tidy/modernize/LoopConvertUtils.cpp:832
@@ -832,3 +831,3 @@
 
   IteratorName = ContainerName + "_elem";
   if (!declarationExists(IteratorName))

This should also handle LLVM style.


Comment at: clang-tidy/modernize/LoopConvertUtils.cpp:836
@@ -836,3 +835,3 @@
 
   IteratorName += "_elem";
   if (!declarationExists(IteratorName))

What will that be? `_elem_elem`? Doesn't make sense to me.


Comment at: clang-tidy/modernize/LoopConvertUtils.cpp:840
@@ -840,3 +839,3 @@
 
-  IteratorName = "_elem_";
+  IteratorName = (Style == NS_LLVM ? "Elem_" : "elem_");
 

The option with the trailing underscore doesn't make sense to me as well 
(unless we add a support for a style requiring trailing underscores for 
variable names).


Comment at: clang-tidy/modernize/LoopConvertUtils.cpp:844
@@ -844,3 +843,3 @@
   while (declarationExists(IteratorName))
 IteratorName += "i";
   return IteratorName;

I'd go with give_me_name{0,1,2,...} or something else that would make it more 
obvious that the automatic name selection failed and a user input is needed.


Comment at: clang-tidy/modernize/LoopConvertUtils.h:418
@@ +417,3 @@
+  // Supported naming styles.
+  enum NamingStyle { NS_LLVM = 0, NS_Google = 1 };
+

The `IdentifierNamingCheck` defines styles in a more generic way (CamelCase, 
camelBack, lower_case, UPPER_CASE). It seems reasonable to use a similar set of 
options. Maybe even move the enum from that check to a common place together 
with the conversion routines.


Comment at: clang-tidy/modernize/LoopConvertUtils.h:418
@@ +417,3 @@
+  // Supported naming styles.
+  enum NamingStyle { NS_LLVM = 0, NS_Google = 1 };
+

alexfh wrote:
> The `IdentifierNamingCheck` defines styles in a more generic way (CamelCase, 
> camelBack, lower_case, UPPER_CASE). It seems reasonable to use a similar set 
> of options. Maybe even move the enum from that check to a common place 
> together with the conversion routines.
Please add tests for all naming conventions.


Comment at: clang-tidy/modernize/LoopConvertUtils.h:448
@@ -444,1 +447,3 @@
+
+  NamingStyle Style;
 };

Please make it const and put it right after `Context`.


http://reviews.llvm.org/D13052



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


r248276 - [mips] Added support for using the command line options -Wa, -msoft-float and -Wa, -mhard-float.

2015-09-22 Thread Daniel Sanders via cfe-commits
Author: dsanders
Date: Tue Sep 22 08:52:32 2015
New Revision: 248276

URL: http://llvm.org/viewvc/llvm-project?rev=248276&view=rev
Log:
[mips] Added support for using the command line options -Wa,-msoft-float and 
-Wa,-mhard-float.

Patch by Scott Egerton.

Reviewers: vkalintiris, dsanders

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/mips-ias-Wa.s

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248276&r1=248275&r2=248276&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Sep 22 08:52:32 2015
@@ -2383,6 +2383,12 @@ static void CollectArgsForIntegratedAsse
   } else if (Value == "--break") {
 CmdArgs.push_back("-target-feature");
 CmdArgs.push_back("-use-tcc-in-div");
+  } else if (Value.startswith("-msoft-float")) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("+soft-float");
+  } else if (Value.startswith("-mhard-float")) {
+CmdArgs.push_back("-target-feature");
+CmdArgs.push_back("-soft-float");
   } else {
 D.Diag(diag::err_drv_unsupported_option_argument)
 << A->getOption().getName() << Value;

Modified: cfe/trunk/test/Driver/mips-ias-Wa.s
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mips-ias-Wa.s?rev=248276&r1=248275&r2=248276&view=diff
==
--- cfe/trunk/test/Driver/mips-ias-Wa.s (original)
+++ cfe/trunk/test/Driver/mips-ias-Wa.s Tue Sep 22 08:52:32 2015
@@ -22,3 +22,28 @@
 // RUN:   FileCheck -check-prefix=TRAP-BOTH-BREAK-FIRST %s
 // TRAP-BOTH-BREAK-FIRST: -cc1as
 // TRAP-BOTH-BREAK-FIRST: "-target-feature" "-use-tcc-in-div" 
"-target-feature" "+use-tcc-in-div"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-DEFAULT %s
+// MSOFT-FLOAT-DEFAULT: -cc1as
+// MSOFT-FLOAT-DEFAULT-NOT: "-target-feature" "-soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,-msoft-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-ON %s
+// MSOFT-FLOAT-ON: -cc1as
+// MSOFT-FLOAT-ON: "-target-feature" "+soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,-mhard-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-OFF %s
+// MSOFT-FLOAT-OFF: -cc1as
+// MSOFT-FLOAT-OFF: "-target-feature" "-soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,-msoft-float,-mhard-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-BOTH-MSOFT-FLOAT-FIRST %s
+// MSOFT-FLOAT-BOTH-MSOFT-FLOAT-FIRST: -cc1as
+// MSOFT-FLOAT-BOTH-MSOFT-FLOAT-FIRST: "-target-feature" "+soft-float" 
"-target-feature" "-soft-float"
+
+// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s 
-Wa,-mhard-float,-msoft-float 2>&1 | \
+// RUN:   FileCheck -check-prefix=MSOFT-FLOAT-BOTH-MHARD-FLOAT-FIRST %s
+// MSOFT-FLOAT-BOTH-MHARD-FLOAT-FIRST: -cc1as
+// MSOFT-FLOAT-BOTH-MHARD-FLOAT-FIRST: "-target-feature" "-soft-float" 
"-target-feature" "+soft-float"


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


Re: [PATCH] D12839: Extend MoveConstructorInitCheck to also flag constructor arguments passed by value and can be moved assigned to fields.

2015-09-22 Thread Alexander Kornienko via cfe-commits
alexfh added inline comments.


Comment at: clang-tidy/misc/MoveConstructorInitCheck.cpp:96
@@ +95,3 @@
+
+void MoveConstructorInitCheck::handleMoveConstructor(
+const MatchFinder::MatchResult &Result) {

Other checks have separate options for the include style (see 
`PassByValueCheck.cpp`, for example), so this one should have its own option 
too. If we ever decide to introduce a common option instead, it will be easier 
to do this, if all usages of the `IncludeInserter` do the same thing with the 
include style.

One thing I would change though, is to add the IncludeStyle <-> string 
conversion functions instead of doing this in each check.


http://reviews.llvm.org/D12839



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


r248279 - Remove unused diagnostic. NFC.

2015-09-22 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Tue Sep 22 09:34:59 2015
New Revision: 248279

URL: http://llvm.org/viewvc/llvm-project?rev=248279&view=rev
Log:
Remove unused diagnostic. NFC.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=248279&r1=248278&r2=248279&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 22 09:34:59 
2015
@@ -7778,8 +7778,6 @@ def err_module_import_in_extern_c : Erro
   "specification">;
 def note_module_import_in_extern_c : Note<
   "extern \"C\" language linkage specification begins here">;
-def err_module_import_not_at_top_level : Error<
-  "import of module '%0' appears within %1">;
 def err_module_import_not_at_top_level_fatal : Error<
   "import of module '%0' appears within %1">, DefaultFatal;
 def note_module_import_not_at_top_level : Note<"%0 begins here">;


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


[PATCH] D13057: [mips] Relax -mnan=2008 acceptance to permit MIPS32R2 and MIPS64R2.

2015-09-22 Thread Daniel Sanders via cfe-commits
dsanders created this revision.
dsanders added a reviewer: atanasyan.
dsanders added a subscriber: cfe-commits.

Strictly speaking, the MIPS*R2 ISA's should not permit -mnan=2008 since this
feature was added in MIPS*R3. However, other toolchains permit this and we
should do the same.

http://reviews.llvm.org/D13057

Files:
  lib/Driver/Tools.cpp
  test/CodeGen/mips-unsupported-nan.c

Index: test/CodeGen/mips-unsupported-nan.c
===
--- test/CodeGen/mips-unsupported-nan.c
+++ test/CodeGen/mips-unsupported-nan.c
@@ -1,24 +1,44 @@
-// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips2 -emit-llvm 
-S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS2 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips3 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS3 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips4 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS4 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r2 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32R2 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r3 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-NOT-MIPS32R3 
-check-prefix=CHECK-NAN2008 %s
-// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -march=mips32r6 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32R6 
-check-prefix=CHECK-NAN2008 %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64r2 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64R2 
-check-prefix=CHECK-NANLEGACY %s
-// RUN: %clang -target mips64el-unknown-linux -mnan=legacy -march=mips64r6 
-emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64R6 
-check-prefix=CHECK-NAN2008 %s
+// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips2 -emit-llvm 
-S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS2 %s < %t
+//
+// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips3 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS3 %s < %t
+//
+// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips4 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS4 %s < %t
+//
+// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS32 %s < %t
+//
+// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r2 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NAN2008 %s
+// RUN: FileCheck -allow-empty -check-prefix=NO-WARNINGS %s < %t
+//
+// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r3 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NAN2008 %s
+// RUN: FileCheck -allow-empty -check-prefix=NO-WARNINGS %s < %t
+//
+// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -march=mips32r6 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NAN2008 %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS32R6 %s < %t
+//
+// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NANLEGACY %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS64 %s < %t
+//
+// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64r2 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NAN2008 %s
+// RUN: FileCheck -allow-empty -check-prefix=NO-WARNINGS %s < %t
+//
+// RUN: %clang -target mips64el-unknown-linux -mnan=legacy -march=mips64r6 
-emit-llvm -S %s -o - 2>%t | FileCheck -check-prefix=CHECK-NAN2008 %s
+// RUN: FileCheck -check-prefix=CHECK-MIPS64R6 %s < %t
+
+// NO-WARNINGS-NOT: warning: ignoring '-mnan=legacy' option
+// NO-WARNINGS-NOT: warning: ignoring '-mnan=2008' option
 
 // CHECK-MIPS2: warning: ignoring '-mnan=2008' option because the 'mips2' 
architecture does not support it
 // CHECK-MIPS3: warning: ignoring '-mnan=2008' option because the 'mips3' 
architecture does not support it
 // CHECK-MIPS4: warning: ignoring '-mnan=2008' option because the 'mips4' 
architecture does not support it
 // CHECK-MIPS32: warning: ignoring '-mnan=2008' option because the 'mips32' 
architecture does not support it
-// CHECK-MIPS32R2: warning: ignoring '-mnan=2008' 

Re: [PATCH] D13057: [mips] Relax -mnan=2008 acceptance to permit MIPS32R2 and MIPS64R2.

2015-09-22 Thread Simon Atanasyan via cfe-commits
atanasyan accepted this revision.
atanasyan added a comment.
This revision is now accepted and ready to land.

LGTM


http://reviews.llvm.org/D13057



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


Re: [PATCH] __attribute__((enable_if)) and non-overloaded member functions

2015-09-22 Thread Ettore Speziale via cfe-commits
Hello,

> It looks like the attached patch is the same as the original one?

I’ve attache the wrong patch. Here is the right one:



enable-if.diff
Description: Binary data

Thanks,
Ettore Speziale___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12501: [clang-format] Obj-C dictionary literals: Fixed typecast getting put on a separate line from the key

2015-09-22 Thread Kent Sutherland via cfe-commits
ksuther added a comment.

I do not.


http://reviews.llvm.org/D12501



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


Re: [PATCH] D12489: [clang-format] Fixed missing space between Obj-C for/in and a typecast

2015-09-22 Thread Kent Sutherland via cfe-commits
ksuther added a comment.

I don't, this and http://reviews.llvm.org/D12489 are my first patch submissions.


http://reviews.llvm.org/D12489



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


Re: [PATCH] D11240: Add basic #include sorting functionality to clang-format

2015-09-22 Thread Daniel Jasper via cfe-commits
djasper updated this revision to Diff 35375.
djasper added a comment.

Restructured a bit. Not as many comments just yet. Do you think this is an 
improvement?


http://reviews.llvm.org/D11240

Files:
  include/clang/Format/Format.h
  include/clang/Tooling/Core/Replacement.h
  lib/Format/Format.cpp
  lib/Format/FormatToken.cpp
  lib/Tooling/Core/Replacement.cpp
  tools/clang-format/CMakeLists.txt
  tools/clang-format/ClangFormat.cpp
  tools/clang-format/clang-format.py
  unittests/Format/CMakeLists.txt
  unittests/Format/SortIncludesTest.cpp
  unittests/Tooling/RefactoringTest.cpp

Index: unittests/Tooling/RefactoringTest.cpp
===
--- unittests/Tooling/RefactoringTest.cpp
+++ unittests/Tooling/RefactoringTest.cpp
@@ -489,5 +489,98 @@
   }
 }
 
+class MergeReplacementsTest : public ::testing::Test {
+protected:
+  void mergeAndTestRewrite(StringRef Code, StringRef Intermediate,
+   StringRef Result, const Replacements &First,
+   const Replacements &Second) {
+// These are mainly to verify the test itself and make it easier to read.
+std::string AfterFirst = applyAllReplacements(Code, First);
+std::string InSequenceRewrite = applyAllReplacements(AfterFirst, Second);
+EXPECT_EQ(Intermediate, AfterFirst);
+EXPECT_EQ(Result, InSequenceRewrite);
+
+tooling::Replacements Merged = mergeReplacements(First, Second);
+std::string MergedRewrite = applyAllReplacements(Code, Merged);
+EXPECT_EQ(InSequenceRewrite, MergedRewrite);
+if (InSequenceRewrite != MergedRewrite)
+  for (tooling::Replacement M : Merged)
+llvm::errs() << M.getOffset() << " " << M.getLength() << " "
+ << M.getReplacementText() << "\n";
+  }
+  void mergeAndTestRewrite(StringRef Code, const Replacements &First,
+   const Replacements &Second) {
+std::string InSequenceRewrite =
+applyAllReplacements(applyAllReplacements(Code, First), Second);
+tooling::Replacements Merged = mergeReplacements(First, Second);
+std::string MergedRewrite = applyAllReplacements(Code, Merged);
+EXPECT_EQ(InSequenceRewrite, MergedRewrite);
+if (InSequenceRewrite != MergedRewrite)
+  for (tooling::Replacement M : Merged)
+llvm::errs() << M.getOffset() << " " << M.getLength() << " "
+ << M.getReplacementText() << "\n";
+  }
+};
+
+TEST_F(MergeReplacementsTest, Offsets) {
+  mergeAndTestRewrite("aaa", "aabab", "cacabab",
+  {{"", 2, 0, "b"}, {"", 3, 0, "b"}},
+  {{"", 0, 0, "c"}, {"", 1, 0, "c"}});
+  mergeAndTestRewrite("aaa", "babaa", "babacac",
+  {{"", 0, 0, "b"}, {"", 1, 0, "b"}},
+  {{"", 4, 0, "c"}, {"", 5, 0, "c"}});
+  mergeAndTestRewrite("", "aaa", "aac", {{"", 1, 1, ""}},
+  {{"", 2, 1, "c"}});
+
+  mergeAndTestRewrite("aa", "bbabba", "bbabcba",
+  {{"", 0, 0, "bb"}, {"", 1, 0, "bb"}}, {{"", 4, 0, "c"}});
+}
+
+TEST_F(MergeReplacementsTest, Concatenations) {
+  // Basic concatenations. It is important to merge these into a single
+  // replacement to ensure the correct order.
+  EXPECT_EQ((Replacements{{"", 0, 0, "ab"}}),
+mergeReplacements({{"", 0, 0, "a"}}, {{"", 1, 0, "b"}}));
+  EXPECT_EQ((Replacements{{"", 0, 0, "ba"}}),
+mergeReplacements({{"", 0, 0, "a"}}, {{"", 0, 0, "b"}}));
+  mergeAndTestRewrite("", "a", "ab", {{"", 0, 0, "a"}}, {{"", 1, 0, "b"}});
+  mergeAndTestRewrite("", "a", "ba", {{"", 0, 0, "a"}}, {{"", 0, 0, "b"}});
+}
+
+TEST_F(MergeReplacementsTest, NotChangingLengths) {
+  mergeAndTestRewrite("", "abba", "acca", {{"", 1, 2, "bb"}},
+  {{"", 1, 2, "cc"}});
+  mergeAndTestRewrite("", "abba", "abcc", {{"", 1, 2, "bb"}},
+  {{"", 2, 2, "cc"}});
+  mergeAndTestRewrite("", "abba", "ccba", {{"", 1, 2, "bb"}},
+  {{"", 0, 2, "cc"}});
+  mergeAndTestRewrite("aa", "abbdda", "abccda",
+  {{"", 1, 2, "bb"}, {"", 3, 2, "dd"}}, {{"", 2, 2, "cc"}});
+}
+
+TEST_F(MergeReplacementsTest, OverlappingRanges) {
+  mergeAndTestRewrite("aaa", "bbd", "bcbcd",
+  {{"", 0, 1, "bb"}, {"", 1, 2, "d"}},
+  {{"", 1, 0, "c"}, {"", 2, 0, "c"}});
+
+  mergeAndTestRewrite("", "aabbaa", "aa", {{"", 2, 0, "bb"}},
+  {{"", 1, 4, ""}});
+  mergeAndTestRewrite("", "aababa", "aa",
+  {{"", 2, 0, "b"}, {"", 3, 0, "b"}}, {{"", 1, 4, ""}});
+  mergeAndTestRewrite("aa", "aa", "abba", {{"", 1, 4, ""}},
+  {{"", 2, 2, ""}});
+  mergeAndTestRewrite("", "aa", "cc", {{"", 1, 1, ""}, {"", 2, 1, ""}},
+  {{"", 0, 2, "cc"}});
+  mergeAndTestRewrite("aa", "abbba", "abcbcba", {{"", 1, 0, "bbb"}},
+  {{"", 2, 0, "c"}, {"", 3

Re: [PATCH] D12633: Implement ACLE 2.0 macros of chapters 6.6 and 6.7 for [ARM] and [Aarch64] targets

2015-09-22 Thread Tim Northover via cfe-commits
t.p.northover added a comment.

I can't explain the Opts.C99 (fesetround is provided by conforming C++11 
implementations too), but I think I was just trying to capture the fact that 
decent hosted platforms support fesetround but freestanding ones don't (not 
having any library).

Supporting "C89 but we also have math.h" (or more realistically "C++03 with 
math.h") wasn't really something that interested me: users should be encouraged 
to write to standards.

Cheers.

Tim.


http://reviews.llvm.org/D12633



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


Re: [PATCH] D13048: Fix for merging decls in pragma weak

2015-09-22 Thread Alexander Musman via cfe-commits
amusman added inline comments.


Comment at: lib/Sema/SemaDeclAttr.cpp:5201
@@ -5200,5 +5200,3 @@
   if (FunctionDecl *FD = dyn_cast(ND)) {
-FunctionDecl *NewFD;
-// FIXME: Missing call to CheckFunctionDeclaration().
 // FIXME: Mangling?
 // FIXME: Is the qualifier info correct?

aaron.ballman wrote:
> If we're in this code, any chance you can also look at the other FIXME 
> statements? If not, that's fine -- this is still positive movement. But it's 
> usually best to tackle all of these at once while it's fresh in someone's 
> mind what's happening here.
I've got here through an existing test case that failed on assertion, not sure 
I can quickly write or find examples for the other fixme's... So, I'd prefer 
not to promise that :)



http://reviews.llvm.org/D13048



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


Re: r248276 - [mips] Added support for using the command line options -Wa, -msoft-float and -Wa, -mhard-float.

2015-09-22 Thread Joerg Sonnenberger via cfe-commits
On Tue, Sep 22, 2015 at 01:52:33PM -, Daniel Sanders via cfe-commits wrote:
> Author: dsanders
> Date: Tue Sep 22 08:52:32 2015
> New Revision: 248276
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=248276&view=rev
> Log:
> [mips] Added support for using the command line options -Wa,-msoft-float and 
> -Wa,-mhard-float.

Can we please split the various -Wa options supported by the platforms
or at least add comments for which platforms the flags are? This is
starting to become a long list and it will grow even further.

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


Re: [PATCH] D13048: Fix for merging decls in pragma weak

2015-09-22 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

Generally LGTM, but I would wait for Richard to review in this case.

~Aaron



Comment at: lib/Sema/SemaDeclAttr.cpp:5201
@@ -5200,5 +5200,3 @@
   if (FunctionDecl *FD = dyn_cast(ND)) {
-FunctionDecl *NewFD;
-// FIXME: Missing call to CheckFunctionDeclaration().
 // FIXME: Mangling?
 // FIXME: Is the qualifier info correct?

amusman wrote:
> aaron.ballman wrote:
> > If we're in this code, any chance you can also look at the other FIXME 
> > statements? If not, that's fine -- this is still positive movement. But 
> > it's usually best to tackle all of these at once while it's fresh in 
> > someone's mind what's happening here.
> I've got here through an existing test case that failed on assertion, not 
> sure I can quickly write or find examples for the other fixme's... So, I'd 
> prefer not to promise that :)
> 
Ah, I hadn't noticed that this was Eli's code originally. I thought the 
original author was on the review thread for context. I wouldn't worry about 
it. If it's not problems in the last four years, we can live with it for a bit 
longer. ;-)


http://reviews.llvm.org/D13048



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


Re: [PATCH] D11240: Add basic #include sorting functionality to clang-format

2015-09-22 Thread Manuel Klimek via cfe-commits
klimek added a comment.

Sending another batch of comments.



Comment at: lib/Tooling/Core/Replacement.cpp:305-307
@@ +304,5 @@
+  Replacements Result;
+  // Iterate over both sets and always add the next element (smallest total
+  // Offset) from either 'First' or 'Second'. Merge that element with
+  // subsequent replacements as long as they overlap.
+  for (auto FirstI = First.begin(), SecondI = Second.begin();

Merge the two sets which are each sorted by offset:
Look at the the next replacement from both sets and check whether they overlap:
1. as long as they do not overlap, we add the replacement with the lower offset 
to the result set
2. when they do overlap, merge into the replacement with the lower offset:
repeatedly take the next replacement from the other queue and merge it, 
until the end of the
next replacement is past the end of the currently merged into replacement;
in that case, the next replacement becomes the currently merged into 
replacement;

Invariants:
- we always merge replacements from the first set into a replacement from the 
second set or vice versa
- an invariant while merging is that the offset of the next replacement to 
merge is always >= the offset
  of the currently merged-into replacement
- more?

Position projections:
When comparing positions, we calculate the projection of positions in the 
second (later) set into where they would happen in the original string.
In the above algorithm, we can always project the start position of a 
replacement from the second set correctly: only a replacement with a smaller 
offset can influence the start position of a replacement from the second set; 
due to the invariant, we never try to merge a replacement from the second set 
before we have merged all replacements with a smaller offset.
We cannot generally project the end position of a replacement from the second 
set correctly, but:
- we can correctly project it correctly if it is smaller or equal to the end 
position of the replacement
   from the first set we currently compare to
- that means if we cannot correctly project it, we still know it is larger than 
the end position of the
   replacement from the first set we currently compare against, so the 
replacement from the second set
   will stay the element to merge into, and we will continuously adapt the end 
position's projection
   when we merge further replacements from the first set.


Comment at: lib/Tooling/Core/Replacement.cpp:308-309
@@ +307,4 @@
+  // subsequent replacements as long as they overlap.
+  for (auto FirstI = First.begin(), SecondI = Second.begin();
+   FirstI != First.end() || SecondI != Second.end();) {
+// 'MergeSecond' is true if an element from 'Second' needs to be merged

Comment:
// We get here on the first run or when we ended a merge sequence (that is, we 
found that
// we are at the start of a new replacement in the result set).

(not sure whether that comment carries it's weight; I started it because it 
took me a moment to figure out why we don't compute which one to take next 
during merging, and it's a bit more complex, but not sure where to put the 
comment yet; basically, the problem is that if the next replacement at the end 
doesn't overlap, it might also be after a non-overlapping replacement from the 
other set, which I think is not entirely obvious).


Comment at: lib/Tooling/Core/Replacement.cpp:310-314
@@ +309,7 @@
+   FirstI != First.end() || SecondI != Second.end();) {
+// 'MergeSecond' is true if an element from 'Second' needs to be merged
+// next, and false if an element from 'First' should be merged. As the 
input
+// replacements are non-overlapping (within each set), we always need to
+// merge an element from 'Second' into an element from 'First' or vice
+// versa.
+bool MergeSecond = SecondI == Second.end() ||

Ok, I think I now understand what confuses me here:
When we do *not* merge (the replacements don't overlap), we take the other 
element next into the result set. A less specific name like 'FirstNext', or 
'NextFromFirst', or even 'MergedIsFirst' (which would fit the 'Merged' prefix 
of the attributes later) would probably fit my mental model better.
Note that for me there's also ambiguity (at least on the first read) between 
'merge into the result set' and 'merge (subsume) one replacement into the 
current one'.

For me calling this:
NextIsFirst, NextOffset, NextLength, NextReplacement
would help.


Comment at: lib/Tooling/Core/Replacement.cpp:326
@@ +325,3 @@
+unsigned MergedLength = R.getLength();
+std::string MergedText = R.getReplacementText();
+

This I'm less sure about, but I think 'Text' is somewhat ambiguous here - 
perhaps 'MergedReplaceWith'?


Comment at: lib/Tooling/Core/Replacement.cpp:354
@@ +353,3 @@
+StringRef Head = MergedRef.substr(0, Offset 

Re: [PATCH] D12793: Three new security overflow builtins with generic argument types

2015-09-22 Thread David Grayson via cfe-commits
DavidEGrayson added a comment.

Thanks for looking at this patch, John!  I disagreed with your comment about 
calculating the encompassing type, but I will incorporate everything else and 
make a new patch tonight or within a few days.



Comment at: docs/LanguageExtensions.rst:1720
@@ -1712,1 +1719,3 @@
+being stored there, and the function returns 1.  The behavior of these builtins
+is well-defined for all argument values.
 

rjmccall wrote:
> Hmm.  It's not necessarily truncation; you could meaningfully use these 
> intrinsics to add two small signed numbers and store the result in an 
> unsigned number.  It's the unique representative value modulo 2^n, where n is 
> the bit-width of the result.
OK, I'll change the documentation because I like your way of phrasing it, but I 
think truncation always gives you the unique representative value modulo 2^n.  
If I'm adding ((int8_t)-1) to ((int8_t)-1), the infinite-width result would be 
-2, which in infinite-width binary is 11...0.  Then we truncate it 
to 8 bits to get 1110, which is 254.  And 254 is also the unique 
representative value of -2 modulo 256.



Comment at: lib/CodeGen/CGBuiltin.cpp:289
@@ +288,3 @@
+static std::pair
+EncompassingIntegerType(std::vector> Types) {
+  assert(Types.size() > 0 && "Empty list of types.");

rjmccall wrote:
> This should just take an ArrayRef.  Also, please at least introduce a typedef 
> for your pair type, and consider just making a little struct for it.
A struct called IntegerWidthAndSignedness sounds good to me, thanks.  And I 
will learn how to use ArrayRef and use it here.


Comment at: lib/CodeGen/CGBuiltin.cpp:314
@@ +313,3 @@
+static std::pair
+IntegerWidthAndSignedness(const clang::ASTContext &context,
+  const clang::QualType Type) {

rjmccall wrote:
> getIntegerWidthAndSignedness, please.
Sounds good.  That frees up the name IntegerWidthAndSignedness to be used for 
my new struct.


Comment at: lib/CodeGen/CGBuiltin.cpp:1601
@@ +1600,3 @@
+auto RITy = IntegerWidthAndSignedness(CGM.getContext(), RQTy);
+auto EITy = EncompassingIntegerType({XITy, YITy, RITy});
+

rjmccall wrote:
> These are not the most evocative names you could have chosen. :)
> 
> Also, this strategy is correct, but it produces horrible code when the 
> operands have the same signedness and the result is different, where the 
> result would otherwise be an ordinary operation and a compare.  You really 
> want to just merge the two operands and then max with the width of the result 
> type.
I don't think that would work.  It sounds like you want me to remove RITy from 
the call to EncompassingIntegerType.  That means the ecompassing type could be 
smaller than the result type, and the arithmetic intrinsic would report an 
overflow even though the mathematical result is representable in the result 
type.

For example, if I am multiplying ((uint8_t)100) by ((uint8_t)100) and storing 
the result in a (uint16_t), the result needs to be 1 and there is no 
overflow.  To arrive at that result, we need to convert the operands to 16-bit 
unsigned integers before multiplying them.  If we multiply them as 8-bit 
unsigned integers, the multiplication intrinsic will report an overflow and 
give a result of 16.  That seems like a messy situation and I don't see how a 
max operation would fix it.


Comment at: lib/CodeGen/CGBuiltin.cpp:1610
@@ +1609,3 @@
+default:
+  llvm_unreachable("Unknown security overflow builtin id.");
+case Builtin::BI__builtin_add_overflow:

rjmccall wrote:
> These aren't really security-specific; they're just arbitrary-precision.
I agree that these functions are not security-specific.  I just copied that 
message from a place a little bit lower in CGBuiltin.cpp where it was used to 
describe some other overflow builtins.  I am happy to remove the word 
"security" from both places.


Comment at: lib/CodeGen/CGBuiltin.cpp:1630
@@ +1629,3 @@
+// Extend each operand to the encompassing type.
+if (XQTy->isSignedIntegerType()) {
+  X = Builder.CreateSExt(X, ELTy);

rjmccall wrote:
> This is Builder.CreateIntegerCast(X, ELTy, XITy.second).
Thanks, I thought there had to be a function for that already but just could 
not find it.


Comment at: lib/CodeGen/CGBuiltin.cpp:1667
@@ +1666,3 @@
+// we have to extend them before storing.
+Q = Builder.CreateZExt(Q, OutPtr.getElementType());
+

rjmccall wrote:
> EmitToMemory.
Thanks again, will do.


Repository:
  rL LLVM

http://reviews.llvm.org/D12793



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


Re: [PATCH] D13052: Add NamingStyle option to modernize-loop-convert.

2015-09-22 Thread Angel Garcia via cfe-commits
angelgarcia updated this revision to Diff 35380.
angelgarcia marked 10 inline comments as done.
angelgarcia added a comment.

Use CamelCase on the existing tests and add a test for every other naming 
convention.


http://reviews.llvm.org/D13052

Files:
  clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tidy/modernize/LoopConvertCheck.h
  clang-tidy/modernize/LoopConvertUtils.cpp
  clang-tidy/modernize/LoopConvertUtils.h
  clang-tidy/modernize/ModernizeTidyModule.cpp
  test/clang-tidy/Inputs/modernize-loop-convert/structures.h
  test/clang-tidy/modernize-loop-convert-basic.cpp
  test/clang-tidy/modernize-loop-convert-camelback.cpp
  test/clang-tidy/modernize-loop-convert-extra.cpp
  test/clang-tidy/modernize-loop-convert-lowercase.cpp
  test/clang-tidy/modernize-loop-convert-negative.cpp
  test/clang-tidy/modernize-loop-convert-uppercase.cpp

Index: test/clang-tidy/modernize-loop-convert-uppercase.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-loop-convert-uppercase.cpp
@@ -0,0 +1,49 @@
+// RUN: %python %S/check_clang_tidy.py %s modernize-loop-convert %t \
+// RUN:   -config="{CheckOptions: [{key: modernize-loop-convert.NamingStyle, value: 'UPPER_CASE'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/modernize-loop-convert
+
+#include "structures.h"
+
+const int N = 10;
+int ARR[N];
+int NUMS[N];
+
+void naming() {
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", ARR[I]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead [modernize-loop-convert]
+  // CHECK-FIXES: for (auto & ELEM : ARR)
+  // CHECK-FIXES-NEXT: printf("%d\n", ELEM);
+
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I]);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & NUM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUM);
+
+  int NUM = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & ELEM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", ELEM + NUM);
+
+  int ELEM = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM + ELEM);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & NUMS_I : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUMS_I + NUM + ELEM);
+
+  int NUMS_I = 0;
+  for (int I = 0; I < N; ++I) {
+printf("%d\n", NUMS[I] + NUM + ELEM + NUMS_I);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES: for (auto & NUMS_ELEM : NUMS)
+  // CHECK-FIXES-NEXT: printf("%d\n", NUMS_ELEM + NUM + ELEM + NUMS_I);
+}
Index: test/clang-tidy/modernize-loop-convert-negative.cpp
===
--- test/clang-tidy/modernize-loop-convert-negative.cpp
+++ test/clang-tidy/modernize-loop-convert-negative.cpp
@@ -8,47 +8,47 @@
 namespace Negative {
 
 const int N = 6;
-int arr[N] = {1, 2, 3, 4, 5, 6};
-int (*pArr)[N] = &arr;
+int Arr[N] = {1, 2, 3, 4, 5, 6};
+int (*pArr)[N] = &Arr;
 int Sum = 0;
 
 // Checks for the Index start and end:
 void IndexStartAndEnd() {
   for (int I = 0; I < N + 1; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N - 1; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 1; I < N; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 1; I < N; ++I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0;; ++I)
 Sum += (*pArr)[I];
 }
 
 // Checks for invalid increment steps:
 void increment() {
   for (int I = 0; I < N; --I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N; I)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N;)
-Sum += arr[I];
+Sum += Arr[I];
 
   for (int I = 0; I < N; I += 2)
 Sum++;
 }
 
 // Checks to make sure that the Index isn't used outside of the array:
 void IndexUse() {
   for (int I = 0; I < N; ++I)
-arr[I] += 1 + I;
+Arr[I] += 1 + I;
 }
 
 // Check for loops that don't mention arrays
@@ -65,30 +65,30 @@
 
 // Checks for incorrect loop variables.
 void mixedVariables() {
-  int badIndex;
-  for (int I = 0; badIndex < N; ++I)
-Sum += arr[I];
+  int BadIndex;
+  for (int I = 0; BadIndex < N; ++I)
+Sum += Arr[I];
 
-  for (int I = 0; I < N; ++badIndex)
-Sum += arr[I];
+  for (int I = 0; I < N; ++BadIndex)
+Sum += Arr[I];
 
-  for (int I = 0; badIndex < N; ++badIndex)
-Sum += arr[I];
+  for (int I = 0; BadIndex < N; ++BadIndex)
+Sum += Arr[I];
 
-  for (int I = 0; badIndex < N; ++badIndex)
-Sum += arr[badIndex];
+  for (int I = 0; BadIndex < N; ++BadIndex)
+Sum += Arr[BadIndex];
 }
 
 // Checks for multiple arrays Indexed.
 void multipleArrays() {
-  int badArr[N];
+  int BadArr[N];
 
   for (int I = 0; I < N; ++I)
-Sum += arr[I] + badArr[I];
+Sum += Arr[I] + BadArr[I

Re: [PATCH] D12482: Analyzer: Teach analyzer how to handle TypeTraitExpr

2015-09-22 Thread Ismail Pazarbasi via cfe-commits
ismailp updated this revision to Diff 35384.
ismailp added a comment.

Addressed comments.


http://reviews.llvm.org/D12482

Files:
  lib/StaticAnalyzer/Core/Environment.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/SValBuilder.cpp
  test/Analysis/dtor.cpp

Index: test/Analysis/dtor.cpp
===
--- test/Analysis/dtor.cpp
+++ test/Analysis/dtor.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config 
c++-inlining=destructors,cfg-temporary-dtors=true -Wno-null-dereference 
-Wno-inaccessible-base -verify %s
+// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection,cplusplus 
-analyzer-config c++-inlining=destructors,cfg-temporary-dtors=true 
-Wno-null-dereference -Wno-inaccessible-base -verify %s
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_checkInlined(bool);
@@ -505,3 +505,38 @@
   class Foo; // expected-note{{forward declaration}}
   void f(Foo *foo) { delete foo; } // expected-warning{{deleting pointer to 
incomplete type}}
 }
+
+namespace TypeTraitExpr {
+template 
+struct copier {
+  static void do_copy(T *dest, const T *src, unsigned count);
+};
+template 
+void do_copy(T *dest, const U *src, unsigned count) {
+  const bool IsSimple = __is_trivial(T) && __is_same(T, U);
+  copier::do_copy(dest, src, count);
+}
+struct NonTrivial {
+  int *p;
+  NonTrivial() : p(new int[1]) { p[0] = 0; }
+  NonTrivial(const NonTrivial &other) {
+p = new int[1];
+do_copy(p, other.p, 1);
+  }
+  NonTrivial &operator=(const NonTrivial &other) {
+p = other.p;
+return *this;
+  }
+  ~NonTrivial() {
+delete[] p; // expected-warning {{free released memory}}
+  }
+};
+
+void f() {
+  NonTrivial nt1;
+  NonTrivial nt2(nt1);
+  nt1 = nt2;
+  clang_analyzer_eval(__is_trivial(NonTrivial)); // expected-warning{{FALSE}}
+  clang_analyzer_eval(__alignof(NonTrivial) > 0); // expected-warning{{TRUE}}
+}
+}
Index: lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -259,6 +259,11 @@
   case Stmt::CXXBoolLiteralExprClass:
 return makeBoolVal(cast(E));
 
+  case Stmt::TypeTraitExprClass: {
+const TypeTraitExpr *TE = cast(E);
+return makeTruthVal(TE->getValue(), TE->getType());
+  }
+
   case Stmt::IntegerLiteralClass:
 return makeIntVal(cast(E));
 
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -756,7 +756,6 @@
 case Stmt::MSPropertyRefExprClass:
 case Stmt::CXXUnresolvedConstructExprClass:
 case Stmt::DependentScopeDeclRefExprClass:
-case Stmt::TypeTraitExprClass:
 case Stmt::ArrayTypeTraitExprClass:
 case Stmt::ExpressionTraitExprClass:
 case Stmt::UnresolvedLookupExprClass:
@@ -902,7 +901,8 @@
 case Stmt::CXXPseudoDestructorExprClass:
 case Stmt::SubstNonTypeTemplateParmExprClass:
 case Stmt::CXXNullPtrLiteralExprClass:
-case Stmt::OMPArraySectionExprClass: {
+case Stmt::OMPArraySectionExprClass:
+case Stmt::TypeTraitExprClass: {
   Bldr.takeNodes(Pred);
   ExplodedNodeSet preVisit;
   getCheckerManager().runCheckersForPreStmt(preVisit, Pred, S, *this);
Index: lib/StaticAnalyzer/Core/Environment.cpp
===
--- lib/StaticAnalyzer/Core/Environment.cpp
+++ lib/StaticAnalyzer/Core/Environment.cpp
@@ -90,6 +90,7 @@
   case Stmt::CXXNullPtrLiteralExprClass:
   case Stmt::ObjCStringLiteralClass:
   case Stmt::StringLiteralClass:
+  case Stmt::TypeTraitExprClass:
 // Known constants; defer to SValBuilder.
 return svalBuilder.getConstantVal(cast(S)).getValue();
 


Index: test/Analysis/dtor.cpp
===
--- test/Analysis/dtor.cpp
+++ test/Analysis/dtor.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config c++-inlining=destructors,cfg-temporary-dtors=true -Wno-null-dereference -Wno-inaccessible-base -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection,cplusplus -analyzer-config c++-inlining=destructors,cfg-temporary-dtors=true -Wno-null-dereference -Wno-inaccessible-base -verify %s
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_checkInlined(bool);
@@ -505,3 +505,38 @@
   class Foo; // expected-note{{forward declaration}}
   void f(Foo *foo) { delete foo; } // expected-warning{{deleting pointer to incomplete type}}
 }
+
+namespace TypeTraitExpr {
+template 
+struct copier {
+  static void do_copy(T *dest, const T *src, unsigned count);
+};
+template 
+void do_copy(T *dest, const U *src, unsigned count) {
+  const bool IsS

Re: [PATCH] D12482: Analyzer: Teach analyzer how to handle TypeTraitExpr

2015-09-22 Thread Ismail Pazarbasi via cfe-commits
ismailp marked an inline comment as done.
ismailp added a comment.

Thanks for reviewing.


http://reviews.llvm.org/D12482



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


r248292 - [tooling] Provide the compile commands of the JSON database in the order that they were provided in the JSON file.

2015-09-22 Thread Argyrios Kyrtzidis via cfe-commits
Author: akirtzidis
Date: Tue Sep 22 12:22:33 2015
New Revision: 248292

URL: http://llvm.org/viewvc/llvm-project?rev=248292&view=rev
Log:
[tooling] Provide the compile commands of the JSON database in the order that 
they were provided in the JSON file.

This is useful for debugging of issues and reduction of test cases.
For example, an issue may show up due to the order that some commands were 
processed.
It is convenient to be able to remove commands from the file and still preserve 
the order
that they are returned, instead of getting a completely different order when 
removing a few commands.

Modified:
cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Modified: cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h?rev=248292&r1=248291&r2=248292&view=diff
==
--- cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h (original)
+++ cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h Tue Sep 22 
12:22:33 2015
@@ -116,6 +116,10 @@ private:
   // Maps file paths to the compile command lines for that file.
   llvm::StringMap> IndexByFile;
 
+  /// All the compile commands in the order that they were provided in the
+  /// JSON stream.
+  std::vector AllCommands;
+
   FileMatchTrie MatchTrie;
 
   std::unique_ptr Database;

Modified: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp?rev=248292&r1=248291&r2=248292&view=diff
==
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp Tue Sep 22 12:22:33 2015
@@ -206,11 +206,7 @@ JSONCompilationDatabase::getAllFiles() c
 std::vector
 JSONCompilationDatabase::getAllCompileCommands() const {
   std::vector Commands;
-  for (llvm::StringMap< std::vector >::const_iterator
-CommandsRefI = IndexByFile.begin(), CommandsRefEnd = IndexByFile.end();
-  CommandsRefI != CommandsRefEnd; ++CommandsRefI) {
-getCommands(CommandsRefI->getValue(), Commands);
-  }
+  getCommands(AllCommands, Commands);
   return Commands;
 }
 
@@ -337,8 +333,9 @@ bool JSONCompilationDatabase::parse(std:
 } else {
   llvm::sys::path::native(FileName, NativeFilePath);
 }
-IndexByFile[NativeFilePath].push_back(
-CompileCommandRef(Directory, File, *Command));
+auto Cmd = CompileCommandRef(Directory, File, *Command);
+IndexByFile[NativeFilePath].push_back(Cmd);
+AllCommands.push_back(Cmd);
 MatchTrie.insert(NativeFilePath);
   }
   return true;

Modified: cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp?rev=248292&r1=248291&r2=248292&view=diff
==
--- cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp Tue Sep 22 12:22:33 
2015
@@ -118,6 +118,25 @@ TEST(JSONCompilationDatabase, GetAllComp
   EXPECT_EQ(FileName2, Commands[1].Filename) << ErrorMessage;
   ASSERT_EQ(1u, Commands[1].CommandLine.size());
   EXPECT_EQ(Command2, Commands[1].CommandLine[0]) << ErrorMessage;
+
+  // Check that order is preserved.
+  Commands = getAllCompileCommands(
+  ("[{\"directory\":\"" + Directory2 + "\"," +
+ "\"command\":\"" + Command2 + "\","
+ "\"file\":\"" + FileName2 + "\"},"
+   " {\"directory\":\"" + Directory1 + "\"," +
+ "\"command\":\"" + Command1 + "\","
+ "\"file\":\"" + FileName1 + "\"}]").str(),
+  ErrorMessage);
+  EXPECT_EQ(2U, Commands.size()) << ErrorMessage;
+  EXPECT_EQ(Directory2, Commands[0].Directory) << ErrorMessage;
+  EXPECT_EQ(FileName2, Commands[0].Filename) << ErrorMessage;
+  ASSERT_EQ(1u, Commands[0].CommandLine.size());
+  EXPECT_EQ(Command2, Commands[0].CommandLine[0]) << ErrorMessage;
+  EXPECT_EQ(Directory1, Commands[1].Directory) << ErrorMessage;
+  EXPECT_EQ(FileName1, Commands[1].Filename) << ErrorMessage;
+  ASSERT_EQ(1u, Commands[1].CommandLine.size());
+  EXPECT_EQ(Command1, Commands[1].CommandLine[0]) << ErrorMessage;
 }
 
 static CompileCommand findCompileArgsInJsonDatabase(StringRef FileName,


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


r248293 - [CUDA] Add implicit __attribute__((used)) to all __global__ functions.

2015-09-22 Thread Artem Belevich via cfe-commits
Author: tra
Date: Tue Sep 22 12:22:51 2015
New Revision: 248293

URL: http://llvm.org/viewvc/llvm-project?rev=248293&view=rev
Log:
[CUDA] Add implicit __attribute__((used)) to all __global__ functions.

This makes sure that we emit kernels that were instantiated from the
host code and which would never be explicitly referenced by anything
else on device side.

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

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=248293&r1=248292&r2=248293&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Sep 22 12:22:51 2015
@@ -3350,6 +3350,10 @@ static void handleGlobalAttr(Sema &S, De
   D->addAttr(::new (S.Context)
   CUDAGlobalAttr(Attr.getRange(), S.Context,
  Attr.getAttributeSpellingListIndex()));
+
+  // Add implicit attribute((used)) so we don't eliminate kernels
+  // because there is nothing referencing them on device side.
+  D->addAttr(UsedAttr::CreateImplicit(S.Context));
 }
 
 static void handleGNUInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) {

Modified: cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu?rev=248293&r1=248292&r2=248293&view=diff
==
--- cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu (original)
+++ cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu Tue Sep 22 12:22:51 2015
@@ -1,7 +1,16 @@
+// Make sure that __global__ functions are emitted along with correct
+// annotations and are added to @llvm.used to prevent their elimination.
+// REQUIRES: nvptx-registered-target
+//
 // RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -fcuda-is-device 
-emit-llvm -o - | FileCheck %s
 
 #include "Inputs/cuda.h"
 
+// Make sure that all __global__ functions are added to @llvm.used
+// CHECK: @llvm.used = appending global
+// CHECK-SAME: @global_function
+// CHECK-SAME: @_Z16templated_kernelIiEvT_
+
 // CHECK-LABEL: define void @device_function
 extern "C"
 __device__ void device_function() {}
@@ -13,4 +22,10 @@ __global__ void global_function() {
   device_function();
 }
 
+// Make sure host-instantiated kernels are preserved on device side.
+template  __global__ void templated_kernel(T param) {}
+// CHECK-LABEL: define linkonce_odr void @_Z16templated_kernelIiEvT_
+void host_function() { templated_kernel<<<0,0>>>(0); }
+
 // CHECK: !{{[0-9]+}} = !{void ()* @global_function, !"kernel", i32 1}
+// CHECK: !{{[0-9]+}} = !{void (i32)* @_Z16templated_kernelIiEvT_, !"kernel", 
i32 1}


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


r248295 - [CUDA] Allow function overloads in CUDA based on host/device attributes.

2015-09-22 Thread Artem Belevich via cfe-commits
Author: tra
Date: Tue Sep 22 12:22:59 2015
New Revision: 248295

URL: http://llvm.org/viewvc/llvm-project?rev=248295&view=rev
Log:
[CUDA] Allow function overloads in CUDA based on host/device attributes.

The patch makes it possible to parse CUDA files that contain host/device
functions with identical signatures, but different attributes without
having to physically split source into host-only and device-only parts.

This change is needed in order to parse CUDA header files that have
a lot of name clashes with standard include files.

Gory details are in design doc here: https://goo.gl/EXnymm
Feel free to leave comments there or in this review thread.

This feature is controlled with CC1 option -fcuda-target-overloads
and is disabled by default.

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

Added:
cfe/trunk/test/CodeGenCUDA/function-overload.cu
cfe/trunk/test/SemaCUDA/function-overload.cu
Modified:
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaCUDA.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=248295&r1=248294&r2=248295&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Tue Sep 22 12:22:59 2015
@@ -166,6 +166,7 @@ LANGOPT(OpenMPUseTLS  , 1, 0, "Use T
 LANGOPT(CUDAIsDevice  , 1, 0, "Compiling for CUDA device")
 LANGOPT(CUDAAllowHostCallsFromHostDevice, 1, 0, "Allow host device functions 
to call host functions")
 LANGOPT(CUDADisableTargetCallChecks, 1, 0, "Disable checks for call targets 
(host, device, etc.)")
+LANGOPT(CUDATargetOverloads, 1, 0, "Enable function overloads based on CUDA 
target attributes")
 LANGOPT(CUDAUsesLibDevice , 1, 0, "Selectively link and internalize bitcode.")
 
 LANGOPT(AssumeSaneOperatorNew , 1, 1, "implicit __attribute__((malloc)) for 
C++'s new operators")

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=248295&r1=248294&r2=248295&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Sep 22 12:22:59 2015
@@ -659,6 +659,8 @@ def fcuda_disable_target_call_checks : F
   HelpText<"Disable all cross-target (host, device, etc.) call checks in 
CUDA">;
 def fcuda_include_gpubinary : Separate<["-"], "fcuda-include-gpubinary">,
   HelpText<"Incorporate CUDA device-side binary into host object file.">;
+def fcuda_target_overloads : Flag<["-"], "fcuda-target-overloads">,
+  HelpText<"Enable function overloads based on CUDA target attributes.">;
 def fcuda_uses_libdevice : Flag<["-"], "fcuda-uses-libdevice">,
   HelpText<"Selectively link and internalize bitcode.">;
 

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=248295&r1=248294&r2=248295&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Sep 22 12:22:59 2015
@@ -8613,8 +8613,37 @@ public:
 
   CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D);
 
+  enum CUDAFunctionPreference {
+CFP_Never,  // Invalid caller/callee combination.
+CFP_LastResort, // Lowest priority. Only in effect if
+// LangOpts.CUDADisableTargetCallChecks is true.
+CFP_Fallback,   // Low priority caller/callee combination
+CFP_Best,   // Preferred caller/callee combination
+  };
+
+  /// Identifies relative preference of a given Caller/Callee
+  /// combination, based on their host/device attributes.
+  /// \param Caller function which needs address of \p Callee.
+  ///   nullptr in case of global context.
+  /// \param Callee target function
+  ///
+  /// \returns preference value for particular Caller/Callee combination.
+  CUDAFunctionPreference IdentifyCUDAPreference(const FunctionDecl *Caller,
+const FunctionDecl *Callee);
+
   bool CheckCUDATarget(const FunctionDecl *Caller, const FunctionDecl *Callee);
 
+  /// Finds a function in \p Matches with highest calling priority
+  /// from \p Caller context and erases all functions with lower
+  /// calling priority.
+  void EraseUnwantedCUDAMatches(const FunctionDecl *Caller,
+SmallVectorImpl &Matches);
+  void EraseUnwantedCUDAMatches(const FunctionDecl *Caller,
+  

r248296 - [CUDA] Add appropriate host/device attribute to builtins.

2015-09-22 Thread Artem Belevich via cfe-commits
Author: tra
Date: Tue Sep 22 12:23:05 2015
New Revision: 248296

URL: http://llvm.org/viewvc/llvm-project?rev=248296&view=rev
Log:
[CUDA] Add appropriate host/device attribute to builtins.

The changes are part of attribute-based CUDA function overloading (D12453)
and as such are only enabled when it's in effect (-fcuda-target-overloads).

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

Added:
cfe/trunk/test/SemaCUDA/builtins.cu
Modified:
cfe/trunk/include/clang/Basic/Builtins.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCUDA/implicit-intrinsic.cu

Modified: cfe/trunk/include/clang/Basic/Builtins.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=248296&r1=248295&r2=248296&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.h (original)
+++ cfe/trunk/include/clang/Basic/Builtins.h Tue Sep 22 12:23:05 2015
@@ -81,6 +81,11 @@ public:
 return getRecord(ID).Type;
   }
 
+  /// \brief Return true if this function is a target-specific builtin
+  bool isTSBuiltin(unsigned ID) const {
+return ID >= Builtin::FirstTSBuiltin;
+  }
+
   /// \brief Return true if this function has no side effects and doesn't
   /// read memory.
   bool isConst(unsigned ID) const {

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=248296&r1=248295&r2=248296&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 22 12:23:05 2015
@@ -529,7 +529,7 @@ Sema::CheckBuiltinFunctionCall(FunctionD
 
   // Since the target specific builtins for each arch overlap, only check those
   // of the arch we are compiling for.
-  if (BuiltinID >= Builtin::FirstTSBuiltin) {
+  if (Context.BuiltinInfo.isTSBuiltin(BuiltinID)) {
 switch (Context.getTargetInfo().getTriple().getArch()) {
   case llvm::Triple::arm:
   case llvm::Triple::armeb:

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=248296&r1=248295&r2=248296&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 22 12:23:05 2015
@@ -11290,6 +11290,18 @@ void Sema::AddKnownFunctionAttributes(Fu
   FD->addAttr(NoThrowAttr::CreateImplicit(Context, FD->getLocation()));
 if (Context.BuiltinInfo.isConst(BuiltinID) && !FD->hasAttr())
   FD->addAttr(ConstAttr::CreateImplicit(Context, FD->getLocation()));
+if (getLangOpts().CUDA && getLangOpts().CUDATargetOverloads &&
+Context.BuiltinInfo.isTSBuiltin(BuiltinID) &&
+!FD->hasAttr() && !FD->hasAttr()) {
+  // Target-specific builtins are assumed to be intended for use
+  // in this particular CUDA compilation mode and should have
+  // appropriate attribute set so we can enforce CUDA function
+  // call restrictions.
+  if (getLangOpts().CUDAIsDevice)
+FD->addAttr(CUDADeviceAttr::CreateImplicit(Context, 
FD->getLocation()));
+  else
+FD->addAttr(CUDAHostAttr::CreateImplicit(Context, FD->getLocation()));
+}
   }
 
   IdentifierInfo *Name = FD->getIdentifier();

Added: cfe/trunk/test/SemaCUDA/builtins.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/builtins.cu?rev=248296&view=auto
==
--- cfe/trunk/test/SemaCUDA/builtins.cu (added)
+++ cfe/trunk/test/SemaCUDA/builtins.cu Tue Sep 22 12:23:05 2015
@@ -0,0 +1,36 @@
+// Tests that target-specific builtins have appropriate host/device
+// attributes and that CUDA call restrictions are enforced. Also
+// verify that non-target builtins can be used from both host and
+// device functions.
+//
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
+// RUN: -fcuda-target-overloads -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple nvptx64-unknown-cuda -fcuda-is-device \
+// RUN: -fcuda-target-overloads -fsyntax-only -verify %s
+
+
+#ifdef __CUDA_ARCH__
+// Device-side builtins are not allowed to be called from host functions.
+void hf() {
+  int x = __builtin_ptx_read_tid_x(); // expected-note  
{{'__builtin_ptx_read_tid_x' declared here}}
+  // expected-error@-1 {{reference to __device__ function 
'__builtin_ptx_read_tid_x' in __host__ function}}
+  x = __builtin_abs(1);
+}
+__attribute__((device)) void df() {
+  int x = __builtin_ptx_read_tid_x();
+  x = __builtin_abs(1);
+}
+#else
+// Host-side builtins are not allowed to be called from device functions.
+__attribute__((device)) void df() {
+  int x = __builtin_ia32_rdtsc();   // expected-note {{'__builtin_ia32_rdtsc

r248297 - [CUDA] Fixes minor cuda-related issues in the driver

2015-09-22 Thread Artem Belevich via cfe-commits
Author: tra
Date: Tue Sep 22 12:23:09 2015
New Revision: 248297

URL: http://llvm.org/viewvc/llvm-project?rev=248297&view=rev
Log:
[CUDA] Fixes minor cuda-related issues in the driver

* Only the last of the --cuda-host-only/--cuda-device-only options has effect.
* CudaHostAction always wraps host-side compilation now.
* Fixed printing of empty action lists.

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

Modified:
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/test/Driver/cuda-options.cu

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=248297&r1=248296&r2=248297&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Sep 22 12:23:09 2015
@@ -920,12 +920,15 @@ static unsigned PrintActions1(const Comp
 } else
   AL = &A->getInputs();
 
-const char *Prefix = "{";
-for (Action *PreRequisite : *AL) {
-  os << Prefix << PrintActions1(C, PreRequisite, Ids);
-  Prefix = ", ";
-}
-os << "}";
+if (AL->size()) {
+  const char *Prefix = "{";
+  for (Action *PreRequisite : *AL) {
+os << Prefix << PrintActions1(C, PreRequisite, Ids);
+Prefix = ", ";
+  }
+  os << "}";
+} else
+  os << "{}";
   }
 
   unsigned Id = Ids.size();
@@ -1243,6 +1246,13 @@ static std::unique_ptr
 buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args,
  const Arg *InputArg, std::unique_ptr HostAction,
  ActionList &Actions) {
+  Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only,
+   options::OPT_cuda_device_only);
+  // Host-only compilation case.
+  if (PartialCompilationArg &&
+  PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only))
+return std::unique_ptr(
+new CudaHostAction(std::move(HostAction), {}));
 
   // Collect all cuda_gpu_arch parameters, removing duplicates.
   SmallVector GpuArchList;
@@ -1288,7 +1298,7 @@ buildCudaActions(const Driver &D, const
 
   // Figure out what to do with device actions -- pass them as inputs to the
   // host action or run each of them independently.
-  bool DeviceOnlyCompilation = Args.hasArg(options::OPT_cuda_device_only);
+  bool DeviceOnlyCompilation = PartialCompilationArg != nullptr;
   if (PartialCompilation || DeviceOnlyCompilation) {
 // In case of partial or device-only compilation results of device actions
 // are not consumed by the host action device actions have to be added to
@@ -1421,11 +1431,8 @@ void Driver::BuildActions(const ToolChai
   continue;
 }
 
-phases::ID CudaInjectionPhase;
-bool InjectCuda = (InputType == types::TY_CUDA &&
-   !Args.hasArg(options::OPT_cuda_host_only));
-CudaInjectionPhase = FinalPhase;
-for (auto &Phase : PL)
+phases::ID CudaInjectionPhase = FinalPhase;
+for (const auto &Phase : PL)
   if (Phase <= FinalPhase && Phase == phases::Compile) {
 CudaInjectionPhase = Phase;
 break;
@@ -1457,7 +1464,7 @@ void Driver::BuildActions(const ToolChai
   // Otherwise construct the appropriate action.
   Current = ConstructPhaseAction(TC, Args, Phase, std::move(Current));
 
-  if (InjectCuda && Phase == CudaInjectionPhase) {
+  if (InputType == types::TY_CUDA && Phase == CudaInjectionPhase) {
 Current = buildCudaActions(*this, TC, Args, InputArg,
std::move(Current), Actions);
 if (!Current)

Modified: cfe/trunk/test/Driver/cuda-options.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-options.cu?rev=248297&r1=248296&r2=248297&view=diff
==
--- cfe/trunk/test/Driver/cuda-options.cu (original)
+++ cfe/trunk/test/Driver/cuda-options.cu Tue Sep 22 12:23:09 2015
@@ -21,7 +21,7 @@
 // Then link things.
 // RUN:   -check-prefix CUDA-L %s
 
-// Verify that -cuda-no-device disables device-side compilation and linking
+// Verify that --cuda-host-only disables device-side compilation and linking
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only %s 2>&1 \
 // Make sure we didn't run device-side compilation.
 // RUN:   | FileCheck -check-prefix CUDA-ND \
@@ -30,11 +30,29 @@
 // Linking is allowed to happen, even if we're missing GPU code.
 // RUN:-check-prefix CUDA-L %s
 
-// Verify that -cuda-no-host disables host-side compilation and linking
+// Same test as above, but with preceeding --cuda-device-only to make
+// sure only last option has effect.
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only 
--cuda-host-only %s 2>&1 \
+// Make sure we didn't run device-side compilation.
+// RUN:   | FileCheck -check-prefix CUDA-ND \
+// Then compile host side and make sure we don't attempt to 

Re: PATCH: Provide the compile commands of the JSON database in consistent order

2015-09-22 Thread Argyrios Kyrtzidis via cfe-commits
In r248292, the added unit test fails without the changes.

> On Sep 18, 2015, at 5:49 PM, Manuel Klimek via cfe-commits 
>  wrote:
> 
> LG in general; I think if we like the order to be deterministic we should try 
> to come up with a unit test so nobody regresses this in the future.
> 
> On Fri, Sep 18, 2015 at 4:44 PM Argyrios Kyrtzidis  > wrote:
> Hi,
> 
> I have found it useful for the getAllCompileCommands() to return the commands 
> in the order that they were provided in the JSON file.
> This is useful for debugging of issues and reduction of test cases.
> For example, an issue may show up due to the order that some commands were 
> processed. It is convenient to be able to remove commands from the file and 
> still preserve the order that they are returned, instead of getting a 
> completely different order when removing a few commands.
> 
> Let me know what you think!
> 
> ___
> 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


r248298 - Augmented CudaHostAction to carry device-side triple.

2015-09-22 Thread Artem Belevich via cfe-commits
Author: tra
Date: Tue Sep 22 12:23:13 2015
New Revision: 248298

URL: http://llvm.org/viewvc/llvm-project?rev=248298&view=rev
Log:
Augmented CudaHostAction to carry device-side triple.

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

Modified:
cfe/trunk/include/clang/Driver/Action.h
cfe/trunk/lib/Driver/Action.cpp
cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/include/clang/Driver/Action.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Action.h?rev=248298&r1=248297&r2=248298&view=diff
==
--- cfe/trunk/include/clang/Driver/Action.h (original)
+++ cfe/trunk/include/clang/Driver/Action.h Tue Sep 22 12:23:13 2015
@@ -160,14 +160,16 @@ public:
 class CudaHostAction : public Action {
   virtual void anchor();
   ActionList DeviceActions;
+  const char *DeviceTriple;
 
 public:
-  CudaHostAction(std::unique_ptr Input,
- const ActionList &DeviceActions);
+  CudaHostAction(std::unique_ptr Input, const ActionList 
&DeviceActions,
+ const char *DeviceTriple);
   ~CudaHostAction() override;
 
   ActionList &getDeviceActions() { return DeviceActions; }
   const ActionList &getDeviceActions() const { return DeviceActions; }
+  const char *getDeviceTriple() const { return DeviceTriple; }
 
   static bool classof(const Action *A) { return A->getKind() == CudaHostClass; 
}
 };

Modified: cfe/trunk/lib/Driver/Action.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Action.cpp?rev=248298&r1=248297&r2=248298&view=diff
==
--- cfe/trunk/lib/Driver/Action.cpp (original)
+++ cfe/trunk/lib/Driver/Action.cpp Tue Sep 22 12:23:13 2015
@@ -66,8 +66,10 @@ CudaDeviceAction::CudaDeviceAction(std::
 void CudaHostAction::anchor() {}
 
 CudaHostAction::CudaHostAction(std::unique_ptr Input,
-   const ActionList &DeviceActions)
-: Action(CudaHostClass, std::move(Input)), DeviceActions(DeviceActions) {}
+   const ActionList &DeviceActions,
+   const char *DeviceTriple)
+: Action(CudaHostClass, std::move(Input)), DeviceActions(DeviceActions),
+  DeviceTriple(DeviceTriple) {}
 
 CudaHostAction::~CudaHostAction() {
   for (auto &DA : DeviceActions)

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=248298&r1=248297&r2=248298&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Sep 22 12:23:13 2015
@@ -1246,13 +1246,18 @@ static std::unique_ptr
 buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args,
  const Arg *InputArg, std::unique_ptr HostAction,
  ActionList &Actions) {
+  // Figure out which NVPTX triple to use for device-side compilation based on
+  // whether host is 64-bit.
+  const char *DeviceTriple = TC.getTriple().isArch64Bit()
+ ? "nvptx64-nvidia-cuda"
+ : "nvptx-nvidia-cuda";
   Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only,
options::OPT_cuda_device_only);
   // Host-only compilation case.
   if (PartialCompilationArg &&
   PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only))
 return std::unique_ptr(
-new CudaHostAction(std::move(HostAction), {}));
+new CudaHostAction(std::move(HostAction), {}, DeviceTriple));
 
   // Collect all cuda_gpu_arch parameters, removing duplicates.
   SmallVector GpuArchList;
@@ -1290,12 +1295,6 @@ buildCudaActions(const Driver &D, const
 }
   }
 
-  // Figure out which NVPTX triple to use for device-side compilation based on
-  // whether host is 64-bit.
-  const char *DeviceTriple = TC.getTriple().isArch64Bit()
- ? "nvptx64-nvidia-cuda"
- : "nvptx-nvidia-cuda";
-
   // Figure out what to do with device actions -- pass them as inputs to the
   // host action or run each of them independently.
   bool DeviceOnlyCompilation = PartialCompilationArg != nullptr;
@@ -1331,7 +1330,7 @@ buildCudaActions(const Driver &D, const
   // Return a new host action that incorporates original host action and all
   // device actions.
   return std::unique_ptr(
-  new CudaHostAction(std::move(HostAction), DeviceActions));
+  new CudaHostAction(std::move(HostAction), DeviceActions, DeviceTriple));
 }
 
 void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args,


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


r248299 - [CUDA] Allow parsing of host and device code simultaneously.

2015-09-22 Thread Artem Belevich via cfe-commits
Author: tra
Date: Tue Sep 22 12:23:22 2015
New Revision: 248299

URL: http://llvm.org/viewvc/llvm-project?rev=248299&view=rev
Log:
[CUDA] Allow parsing of host and device code simultaneously.

 * adds -aux-triple option to specify target triple
 * propagates aux target info to AST context and Preprocessor
 * pulls in target specific preprocessor macros.
 * pulls in target-specific builtins from aux target.
 * sets appropriate host or device attribute on builtins.

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

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/Builtins.h
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Basic/Builtins.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCUDA/builtins.cu

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=248299&r1=248298&r2=248299&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Sep 22 12:23:22 2015
@@ -437,6 +437,7 @@ private:
   friend class CXXRecordDecl;
 
   const TargetInfo *Target;
+  const TargetInfo *AuxTarget;
   clang::PrintingPolicy PrintingPolicy;
   
 public:
@@ -523,7 +524,8 @@ public:
   }
 
   const TargetInfo &getTargetInfo() const { return *Target; }
-  
+  const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
+
   /// getIntTypeForBitwidth -
   /// sets integer QualTy according to specified details:
   /// bitwidth, signed/unsigned.
@@ -2415,9 +2417,10 @@ public:
   /// This routine may only be invoked once for a given ASTContext object.
   /// It is normally invoked after ASTContext construction.
   ///
-  /// \param Target The target 
-  void InitBuiltinTypes(const TargetInfo &Target);
-  
+  /// \param Target The target
+  void InitBuiltinTypes(const TargetInfo &Target,
+const TargetInfo *AuxTarget = nullptr);
+
 private:
   void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
 

Modified: cfe/trunk/include/clang/Basic/Builtins.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=248299&r1=248298&r2=248299&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.h (original)
+++ cfe/trunk/include/clang/Basic/Builtins.h Tue Sep 22 12:23:22 2015
@@ -56,15 +56,23 @@ struct Info {
 
 /// \brief Holds information about both target-independent and
 /// target-specific builtins, allowing easy queries by clients.
+///
+/// Builtins from an optional auxiliary target are stored in
+/// AuxTSRecords. Their IDs are shifted up by NumTSRecords and need to
+/// be translated back with getAuxBuiltinID() before use.
 class Context {
   const Info *TSRecords;
+  const Info *AuxTSRecords;
   unsigned NumTSRecords;
+  unsigned NumAuxTSRecords;
+
 public:
   Context();
 
   /// \brief Perform target-specific initialization
-  void initializeTarget(const TargetInfo &Target);
-  
+  /// \param AuxTarget Target info to incorporate builtins from. May be 
nullptr.
+  void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget);
+
   /// \brief Mark the identifiers for all the builtins with their
   /// appropriate builtin ID # and mark any non-portable builtin identifiers as
   /// such.
@@ -176,6 +184,15 @@ public:
 return getRecord(ID).Features;
   }
 
+  /// \brief Return true if builtin ID belongs to AuxTarget.
+  bool isAuxBuiltinID(unsigned ID) const {
+return ID >= (Builtin::FirstTSBuiltin + NumTSRecords);
+  }
+
+  /// Return real buitin ID (i.e. ID it would have furing compilation
+  /// for AuxTarget).
+  unsigned getAuxBuiltinID(unsigned ID) const { return ID - NumTSRecords; }
+
 private:
   const Info &getRecord(unsigned ID) const;
 

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=248299&r1=248298&r2=248299&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Tue Sep 22 12:23:22 2015
@@ -325,6 +325,8 @@ def cc1as : Flag<["-"], "cc1as">;
 def ast_merge : Separate<["-"], "ast-merge">,
   MetaVarName<"">,
   HelpText<"Merge the given AST file into the translation unit being 
compiled.">;
+def aux_triple : Separate<["-"], "aux-t

Re: [PATCH] D12453: [CUDA] Allow function overloads based on host/device attributes.

2015-09-22 Thread Artem Belevich via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL248295: [CUDA] Allow function overloads in CUDA based on 
host/device attributes. (authored by tra).

Changed prior to commit:
  http://reviews.llvm.org/D12453?vs=34368&id=35387#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12453

Files:
  cfe/trunk/include/clang/Basic/LangOptions.def
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Sema/SemaCUDA.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaExprCXX.cpp
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/test/CodeGenCUDA/function-overload.cu
  cfe/trunk/test/SemaCUDA/function-overload.cu

Index: cfe/trunk/test/SemaCUDA/function-overload.cu
===
--- cfe/trunk/test/SemaCUDA/function-overload.cu
+++ cfe/trunk/test/SemaCUDA/function-overload.cu
@@ -0,0 +1,317 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// Make sure we handle target overloads correctly.
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \
+// RUN:-fsyntax-only -fcuda-target-overloads -verify %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda \
+// RUN:-fsyntax-only -fcuda-target-overloads -fcuda-is-device -verify %s
+
+// Check target overloads handling with disabled call target checks.
+// RUN: %clang_cc1 -DNOCHECKS -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:-fcuda-disable-target-call-checks -fcuda-target-overloads -verify %s
+// RUN: %clang_cc1 -DNOCHECKS -triple nvptx64-nvidia-cuda -fsyntax-only \
+// RUN:-fcuda-disable-target-call-checks -fcuda-target-overloads \
+// RUN:-fcuda-is-device -verify %s
+
+#include "Inputs/cuda.h"
+
+typedef int (*fp_t)(void);
+typedef void (*gp_t)(void);
+
+// Host and unattributed functions can't be overloaded
+__host__ int hh(void) { return 1; } // expected-note {{previous definition is here}}
+int hh(void) { return 1; } // expected-error {{redefinition of 'hh'}}
+
+// H/D overloading is OK
+__host__ int dh(void) { return 2; }
+__device__ int dh(void) { return 2; }
+
+// H/HD and D/HD are not allowed
+__host__ __device__ int hdh(void) { return 5; } // expected-note {{previous definition is here}}
+__host__ int hdh(void) { return 4; } // expected-error {{redefinition of 'hdh'}}
+
+__host__ int hhd(void) { return 4; } // expected-note {{previous definition is here}}
+__host__ __device__ int hhd(void) { return 5; } // expected-error {{redefinition of 'hhd'}}
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+
+__host__ __device__ int hdd(void) { return 7; } // expected-note {{previous definition is here}}
+__device__ int hdd(void) { return 6; } // expected-error {{redefinition of 'hdd'}}
+
+__device__ int dhd(void) { return 6; } // expected-note {{previous definition is here}}
+__host__ __device__ int dhd(void) { return 7; } // expected-error {{redefinition of 'dhd'}}
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+
+// Same tests for extern "C" functions
+extern "C" __host__ int chh(void) {return 11;} // expected-note {{previous definition is here}}
+extern "C" int chh(void) {return 11;} // expected-error {{redefinition of 'chh'}}
+
+// H/D overloading is OK
+extern "C" __device__ int cdh(void) {return 10;}
+extern "C" __host__ int cdh(void) {return 11;}
+
+// H/HD and D/HD overloading is not allowed.
+extern "C" __host__ __device__ int chhd1(void) {return 12;} // expected-note {{previous definition is here}}
+extern "C" __host__ int chhd1(void) {return 13;} // expected-error {{redefinition of 'chhd1'}}
+
+extern "C" __host__ int chhd2(void) {return 13;} // expected-note {{previous definition is here}}
+extern "C" __host__ __device__ int chhd2(void) {return 12;} // expected-error {{redefinition of 'chhd2'}}
+// expected-warning@-1 {{attribute declaration must precede definition}}
+// expected-note@-3 {{previous definition is here}}
+
+// Helper functions to verify calling restrictions.
+__device__ int d(void) { return 8; }
+__host__ int h(void) { return 9; }
+__global__ void g(void) {}
+extern "C" __device__ int cd(void) {return 10;}
+extern "C" __host__ int ch(void) {return 11;}
+
+__host__ void hostf(void) {
+  fp_t dp = d;
+  fp_t cdp = cd;
+#if !defined(NOCHECKS)
+  // expected-error@-3 {{reference to __device__ function 'd' in __host__ function}}
+  // expected-note@65 {{'d' declared here}}
+  // expected-error@-4 {{reference to __device__ function 'cd' in __host__ function}}
+  // expected-note@68 {{'cd' declared here}}
+#endif
+  fp_t hp = h;
+  fp_t chp = ch;
+  fp_t dhp = dh;
+  fp_t cdhp = cdh;
+  gp_t gp = g;
+
+  d();
+  cd();
+#if !defined(NOCHECKS)
+  // expected-error@-3 {{no matching function for call to 'd'}}
+  // expected-note@65 {{candidate fun

Re: [PATCH] D12893: Augmented CudaHostAction to carry device-side triple.

2015-09-22 Thread Artem Belevich via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL248298: Augmented CudaHostAction to carry device-side 
triple. (authored by tra).

Changed prior to commit:
  http://reviews.llvm.org/D12893?vs=34857&id=35388#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12893

Files:
  cfe/trunk/include/clang/Driver/Action.h
  cfe/trunk/lib/Driver/Action.cpp
  cfe/trunk/lib/Driver/Driver.cpp

Index: cfe/trunk/include/clang/Driver/Action.h
===
--- cfe/trunk/include/clang/Driver/Action.h
+++ cfe/trunk/include/clang/Driver/Action.h
@@ -160,14 +160,16 @@
 class CudaHostAction : public Action {
   virtual void anchor();
   ActionList DeviceActions;
+  const char *DeviceTriple;
 
 public:
-  CudaHostAction(std::unique_ptr Input,
- const ActionList &DeviceActions);
+  CudaHostAction(std::unique_ptr Input, const ActionList 
&DeviceActions,
+ const char *DeviceTriple);
   ~CudaHostAction() override;
 
   ActionList &getDeviceActions() { return DeviceActions; }
   const ActionList &getDeviceActions() const { return DeviceActions; }
+  const char *getDeviceTriple() const { return DeviceTriple; }
 
   static bool classof(const Action *A) { return A->getKind() == CudaHostClass; 
}
 };
Index: cfe/trunk/lib/Driver/Action.cpp
===
--- cfe/trunk/lib/Driver/Action.cpp
+++ cfe/trunk/lib/Driver/Action.cpp
@@ -66,8 +66,10 @@
 void CudaHostAction::anchor() {}
 
 CudaHostAction::CudaHostAction(std::unique_ptr Input,
-   const ActionList &DeviceActions)
-: Action(CudaHostClass, std::move(Input)), DeviceActions(DeviceActions) {}
+   const ActionList &DeviceActions,
+   const char *DeviceTriple)
+: Action(CudaHostClass, std::move(Input)), DeviceActions(DeviceActions),
+  DeviceTriple(DeviceTriple) {}
 
 CudaHostAction::~CudaHostAction() {
   for (auto &DA : DeviceActions)
Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1246,13 +1246,18 @@
 buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args,
  const Arg *InputArg, std::unique_ptr HostAction,
  ActionList &Actions) {
+  // Figure out which NVPTX triple to use for device-side compilation based on
+  // whether host is 64-bit.
+  const char *DeviceTriple = TC.getTriple().isArch64Bit()
+ ? "nvptx64-nvidia-cuda"
+ : "nvptx-nvidia-cuda";
   Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only,
options::OPT_cuda_device_only);
   // Host-only compilation case.
   if (PartialCompilationArg &&
   PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only))
 return std::unique_ptr(
-new CudaHostAction(std::move(HostAction), {}));
+new CudaHostAction(std::move(HostAction), {}, DeviceTriple));
 
   // Collect all cuda_gpu_arch parameters, removing duplicates.
   SmallVector GpuArchList;
@@ -1290,12 +1295,6 @@
 }
   }
 
-  // Figure out which NVPTX triple to use for device-side compilation based on
-  // whether host is 64-bit.
-  const char *DeviceTriple = TC.getTriple().isArch64Bit()
- ? "nvptx64-nvidia-cuda"
- : "nvptx-nvidia-cuda";
-
   // Figure out what to do with device actions -- pass them as inputs to the
   // host action or run each of them independently.
   bool DeviceOnlyCompilation = PartialCompilationArg != nullptr;
@@ -1331,7 +1330,7 @@
   // Return a new host action that incorporates original host action and all
   // device actions.
   return std::unique_ptr(
-  new CudaHostAction(std::move(HostAction), DeviceActions));
+  new CudaHostAction(std::move(HostAction), DeviceActions, DeviceTriple));
 }
 
 void Driver::BuildActions(const ToolChain &TC, DerivedArgList &Args,


Index: cfe/trunk/include/clang/Driver/Action.h
===
--- cfe/trunk/include/clang/Driver/Action.h
+++ cfe/trunk/include/clang/Driver/Action.h
@@ -160,14 +160,16 @@
 class CudaHostAction : public Action {
   virtual void anchor();
   ActionList DeviceActions;
+  const char *DeviceTriple;
 
 public:
-  CudaHostAction(std::unique_ptr Input,
- const ActionList &DeviceActions);
+  CudaHostAction(std::unique_ptr Input, const ActionList &DeviceActions,
+ const char *DeviceTriple);
   ~CudaHostAction() override;
 
   ActionList &getDeviceActions() { return DeviceActions; }
   const ActionList &getDeviceActions() const { return DeviceActions; }
+  const char *getDeviceTriple() const { return DeviceTriple; }
 
   static 

Re: [PATCH] D12892: [CUDA] Minor cuda-related driver fixes.

2015-09-22 Thread Artem Belevich via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL248297: [CUDA] Fixes minor cuda-related issues in the driver 
(authored by tra).

Changed prior to commit:
  http://reviews.llvm.org/D12892?vs=34855&id=35386#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12892

Files:
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/test/Driver/cuda-options.cu

Index: cfe/trunk/test/Driver/cuda-options.cu
===
--- cfe/trunk/test/Driver/cuda-options.cu
+++ cfe/trunk/test/Driver/cuda-options.cu
@@ -21,22 +21,40 @@
 // Then link things.
 // RUN:   -check-prefix CUDA-L %s
 
-// Verify that -cuda-no-device disables device-side compilation and linking
+// Verify that --cuda-host-only disables device-side compilation and linking
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only %s 2>&1 \
 // Make sure we didn't run device-side compilation.
 // RUN:   | FileCheck -check-prefix CUDA-ND \
 // Then compile host side and make sure we don't attempt to incorporate GPU code.
 // RUN:-check-prefix CUDA-H -check-prefix CUDA-H-NI \
 // Linking is allowed to happen, even if we're missing GPU code.
 // RUN:-check-prefix CUDA-L %s
 
-// Verify that -cuda-no-host disables host-side compilation and linking
+// Same test as above, but with preceeding --cuda-device-only to make
+// sure only last option has effect.
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only --cuda-host-only %s 2>&1 \
+// Make sure we didn't run device-side compilation.
+// RUN:   | FileCheck -check-prefix CUDA-ND \
+// Then compile host side and make sure we don't attempt to incorporate GPU code.
+// RUN:-check-prefix CUDA-H -check-prefix CUDA-H-NI \
+// Linking is allowed to happen, even if we're missing GPU code.
+// RUN:-check-prefix CUDA-L %s
+
+// Verify that --cuda-device-only disables host-side compilation and linking
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only %s 2>&1 \
 // Compile device-side to PTX assembly
 // RUN:   | FileCheck -check-prefix CUDA-D1 -check-prefix CUDA-D1NS\
 // Make sure there are no host cmpilation or linking.
 // RUN:   -check-prefix CUDA-NH -check-prefix CUDA-NL %s
 
+// Same test as above, but with preceeding --cuda-host-only to make
+// sure only last option has effect.
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only --cuda-device-only %s 2>&1 \
+// Compile device-side to PTX assembly
+// RUN:   | FileCheck -check-prefix CUDA-D1 -check-prefix CUDA-D1NS\
+// Make sure there are no host cmpilation or linking.
+// RUN:   -check-prefix CUDA-NH -check-prefix CUDA-NL %s
+
 // Verify that with -S we compile host and device sides to assembly
 // and incorporate device code on the host side.
 // RUN: %clang -### -target x86_64-linux-gnu -S -c %s 2>&1 \
Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -920,12 +920,15 @@
 } else
   AL = &A->getInputs();
 
-const char *Prefix = "{";
-for (Action *PreRequisite : *AL) {
-  os << Prefix << PrintActions1(C, PreRequisite, Ids);
-  Prefix = ", ";
-}
-os << "}";
+if (AL->size()) {
+  const char *Prefix = "{";
+  for (Action *PreRequisite : *AL) {
+os << Prefix << PrintActions1(C, PreRequisite, Ids);
+Prefix = ", ";
+  }
+  os << "}";
+} else
+  os << "{}";
   }
 
   unsigned Id = Ids.size();
@@ -1243,6 +1246,13 @@
 buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args,
  const Arg *InputArg, std::unique_ptr HostAction,
  ActionList &Actions) {
+  Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only,
+   options::OPT_cuda_device_only);
+  // Host-only compilation case.
+  if (PartialCompilationArg &&
+  PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only))
+return std::unique_ptr(
+new CudaHostAction(std::move(HostAction), {}));
 
   // Collect all cuda_gpu_arch parameters, removing duplicates.
   SmallVector GpuArchList;
@@ -1288,7 +1298,7 @@
 
   // Figure out what to do with device actions -- pass them as inputs to the
   // host action or run each of them independently.
-  bool DeviceOnlyCompilation = Args.hasArg(options::OPT_cuda_device_only);
+  bool DeviceOnlyCompilation = PartialCompilationArg != nullptr;
   if (PartialCompilation || DeviceOnlyCompilation) {
 // In case of partial or device-only compilation results of device actions
 // are not consumed by the host action device actions have to be added to
@@ -1421,11 +1431,8 @@
   continue;
 }
 
-phases::ID CudaInjectionPhase;
-bool InjectCuda = (InputType == types::TY_CUDA &&
-   !Args.hasArg(options::OPT_cuda_host_only));
-CudaInjectionPhase = FinalPhase;
-f

Re: [PATCH] D12917: [CUDA] Allow parsing of host and device code simultaneously.

2015-09-22 Thread Artem Belevich via cfe-commits
This revision was automatically updated to reflect the committed changes.
tra marked an inline comment as done.
Closed by commit rL248299: [CUDA] Allow parsing of host and device code 
simultaneously. (authored by tra).

Changed prior to commit:
  http://reviews.llvm.org/D12917?vs=35031&id=35389#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12917

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/Basic/Builtins.h
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/Frontend/CompilerInstance.h
  cfe/trunk/include/clang/Frontend/FrontendOptions.h
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/Basic/Builtins.cpp
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Frontend/InitPreprocessor.cpp
  cfe/trunk/lib/Lex/Preprocessor.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/SemaCUDA/builtins.cu

Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -325,6 +325,8 @@
 def ast_merge : Separate<["-"], "ast-merge">,
   MetaVarName<"">,
   HelpText<"Merge the given AST file into the translation unit being compiled.">;
+def aux_triple : Separate<["-"], "aux-triple">,
+  HelpText<"Auxiliary target triple.">;
 def code_completion_at : Separate<["-"], "code-completion-at">,
   MetaVarName<"::">,
   HelpText<"Dump code-completion information at a location">;
Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -98,6 +98,7 @@
   DiagnosticsEngine*Diags;
   LangOptions   &LangOpts;
   const TargetInfo  *Target;
+  const TargetInfo  *AuxTarget;
   FileManager   &FileMgr;
   SourceManager &SourceMgr;
   std::unique_ptr ScratchBuf;
@@ -656,7 +657,10 @@
   ///
   /// \param Target is owned by the caller and must remain valid for the
   /// lifetime of the preprocessor.
-  void Initialize(const TargetInfo &Target);
+  /// \param AuxTarget is owned by the caller and must remain valid for
+  /// the lifetime of the preprocessor.
+  void Initialize(const TargetInfo &Target,
+  const TargetInfo *AuxTarget = nullptr);
 
   /// \brief Initialize the preprocessor to parse a model file
   ///
@@ -678,6 +682,7 @@
 
   const LangOptions &getLangOpts() const { return LangOpts; }
   const TargetInfo &getTargetInfo() const { return *Target; }
+  const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
   FileManager &getFileManager() const { return FileMgr; }
   SourceManager &getSourceManager() const { return SourceMgr; }
   HeaderSearch &getHeaderSearchInfo() const { return HeaderInfo; }
Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -437,6 +437,7 @@
   friend class CXXRecordDecl;
 
   const TargetInfo *Target;
+  const TargetInfo *AuxTarget;
   clang::PrintingPolicy PrintingPolicy;
   
 public:
@@ -523,7 +524,8 @@
   }
 
   const TargetInfo &getTargetInfo() const { return *Target; }
-  
+  const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
+
   /// getIntTypeForBitwidth -
   /// sets integer QualTy according to specified details:
   /// bitwidth, signed/unsigned.
@@ -2415,9 +2417,10 @@
   /// This routine may only be invoked once for a given ASTContext object.
   /// It is normally invoked after ASTContext construction.
   ///
-  /// \param Target The target 
-  void InitBuiltinTypes(const TargetInfo &Target);
-  
+  /// \param Target The target
+  void InitBuiltinTypes(const TargetInfo &Target,
+const TargetInfo *AuxTarget = nullptr);
+
 private:
   void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
 
Index: cfe/trunk/include/clang/Basic/Builtins.h
===
--- cfe/trunk/include/clang/Basic/Builtins.h
+++ cfe/trunk/include/clang/Basic/Builtins.h
@@ -56,15 +56,23 @@
 
 /// \brief Holds information about both target-independent and
 /// target-specific builtins, allowing easy queries by clients.
+///
+/// Builtins from an optional auxiliary target are stored in
+/// AuxTSRecords. Their IDs are shifted up by NumTSRecords and need to
+/// be translated back with getAuxBuiltinID() before use.
 class Context {
   const Info *TSRecords;
+  const Info *AuxTSRecords;
   unsigned NumTSRecords;
+  unsigned NumAuxTSRecords;
+
 public:
   Context();
 
   /// \brief Perform target-specific initialization
-  void initializeTarget(const TargetInfo &Target);
-  
+  /// \param AuxTarget Target info to incorporate builtins from

Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

Does anything actually need this? This interface was never really meant to be 
complete, just want was needed.

> It's a shame that libc++ decided to reinvent the wheel here and not use the 
> C11 atomics support


GCC doesn't provide "_Atomic" and `` isn't always fully available. This 
is a minimal subset of atomic functionality needed to support `std::shared_ptr` 
and `std::call_once` among other things. All new code should use std::atomic 
IMO. It's not meant to reinvent the wheel, It's meant to be a portable option 
for when there is no "wheel" already.

Does armv4 need lib calls for atomic operations on "unsigned long"?


http://reviews.llvm.org/D13051



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


[libcxx] r248304 - Change pair::swap(pair&) to call ADL swap instead of iter_swap; this fixes an obscure bug having to do with overloaded operator&. Fixes PR#24890

2015-09-22 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Tue Sep 22 12:50:11 2015
New Revision: 248304

URL: http://llvm.org/viewvc/llvm-project?rev=248304&view=rev
Log:
Change pair::swap(pair&) to call ADL swap instead of iter_swap; this fixes an 
obscure bug having to do with overloaded operator&. Fixes PR#24890

Modified:
libcxx/trunk/include/utility

Modified: libcxx/trunk/include/utility
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=248304&r1=248303&r2=248304&view=diff
==
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Tue Sep 22 12:50:11 2015
@@ -388,8 +388,9 @@ struct _LIBCPP_TYPE_VIS_ONLY pair
 swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable::value &&
__is_nothrow_swappable::value)
 {
-_VSTD::iter_swap(&first, &__p.first);
-_VSTD::iter_swap(&second, &__p.second);
+using _VSTD::swap;
+swap(first,  __p.first);
+swap(second, __p.second);
 }
 private:
 


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


Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Jonathan Roelofs via cfe-commits
jroelofs added a comment.

In http://reviews.llvm.org/D13051#250836, @EricWF wrote:

> Does armv4 need lib calls for atomic operations on "unsigned long"?


IIRC, yes.


http://reviews.llvm.org/D13051



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


[libcxx] r248305 - Check in the test for PR#24890 that I forgot in previous commit

2015-09-22 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Tue Sep 22 12:57:41 2015
New Revision: 248305

URL: http://llvm.org/viewvc/llvm-project?rev=248305&view=rev
Log:
Check in the test for PR#24890 that I forgot in previous commit

Modified:
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp

Modified: libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp?rev=248305&r1=248304&r2=248305&view=diff
==
--- libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp Tue 
Sep 22 12:57:41 2015
@@ -16,6 +16,14 @@
 #include 
 #include 
 
+struct S {
+int i; 
+S() : i(0) {}
+S(int j) : i(j) {}
+S const * operator& () const { assert(false); return this; }
+bool operator==(int x) const { return i == x; }
+};
+
 int main()
 {
 {
@@ -25,6 +33,16 @@ int main()
 p1.swap(p2);
 assert(p1.first == 5);
 assert(p1.second == 6);
+assert(p2.first == 3);
+assert(p2.second == 4);
+}
+{
+typedef std::pair P1;
+P1 p1(3, S(4));
+P1 p2(5, S(6));
+p1.swap(p2);
+assert(p1.first == 5);
+assert(p1.second == 6);
 assert(p2.first == 3);
 assert(p2.second == 4);
 }


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


Re: [PATCH] D11240: Add basic #include sorting functionality to clang-format

2015-09-22 Thread Daniel Jasper via cfe-commits
djasper updated this revision to Diff 35395.
djasper added a comment.

Added comments and did some renaming.


http://reviews.llvm.org/D11240

Files:
  include/clang/Format/Format.h
  include/clang/Tooling/Core/Replacement.h
  lib/Format/Format.cpp
  lib/Format/FormatToken.cpp
  lib/Tooling/Core/Replacement.cpp
  tools/clang-format/CMakeLists.txt
  tools/clang-format/ClangFormat.cpp
  tools/clang-format/clang-format.py
  unittests/Format/CMakeLists.txt
  unittests/Format/SortIncludesTest.cpp
  unittests/Tooling/RefactoringTest.cpp

Index: unittests/Tooling/RefactoringTest.cpp
===
--- unittests/Tooling/RefactoringTest.cpp
+++ unittests/Tooling/RefactoringTest.cpp
@@ -489,5 +489,98 @@
   }
 }
 
+class MergeReplacementsTest : public ::testing::Test {
+protected:
+  void mergeAndTestRewrite(StringRef Code, StringRef Intermediate,
+   StringRef Result, const Replacements &First,
+   const Replacements &Second) {
+// These are mainly to verify the test itself and make it easier to read.
+std::string AfterFirst = applyAllReplacements(Code, First);
+std::string InSequenceRewrite = applyAllReplacements(AfterFirst, Second);
+EXPECT_EQ(Intermediate, AfterFirst);
+EXPECT_EQ(Result, InSequenceRewrite);
+
+tooling::Replacements Merged = mergeReplacements(First, Second);
+std::string MergedRewrite = applyAllReplacements(Code, Merged);
+EXPECT_EQ(InSequenceRewrite, MergedRewrite);
+if (InSequenceRewrite != MergedRewrite)
+  for (tooling::Replacement M : Merged)
+llvm::errs() << M.getOffset() << " " << M.getLength() << " "
+ << M.getReplacementText() << "\n";
+  }
+  void mergeAndTestRewrite(StringRef Code, const Replacements &First,
+   const Replacements &Second) {
+std::string InSequenceRewrite =
+applyAllReplacements(applyAllReplacements(Code, First), Second);
+tooling::Replacements Merged = mergeReplacements(First, Second);
+std::string MergedRewrite = applyAllReplacements(Code, Merged);
+EXPECT_EQ(InSequenceRewrite, MergedRewrite);
+if (InSequenceRewrite != MergedRewrite)
+  for (tooling::Replacement M : Merged)
+llvm::errs() << M.getOffset() << " " << M.getLength() << " "
+ << M.getReplacementText() << "\n";
+  }
+};
+
+TEST_F(MergeReplacementsTest, Offsets) {
+  mergeAndTestRewrite("aaa", "aabab", "cacabab",
+  {{"", 2, 0, "b"}, {"", 3, 0, "b"}},
+  {{"", 0, 0, "c"}, {"", 1, 0, "c"}});
+  mergeAndTestRewrite("aaa", "babaa", "babacac",
+  {{"", 0, 0, "b"}, {"", 1, 0, "b"}},
+  {{"", 4, 0, "c"}, {"", 5, 0, "c"}});
+  mergeAndTestRewrite("", "aaa", "aac", {{"", 1, 1, ""}},
+  {{"", 2, 1, "c"}});
+
+  mergeAndTestRewrite("aa", "bbabba", "bbabcba",
+  {{"", 0, 0, "bb"}, {"", 1, 0, "bb"}}, {{"", 4, 0, "c"}});
+}
+
+TEST_F(MergeReplacementsTest, Concatenations) {
+  // Basic concatenations. It is important to merge these into a single
+  // replacement to ensure the correct order.
+  EXPECT_EQ((Replacements{{"", 0, 0, "ab"}}),
+mergeReplacements({{"", 0, 0, "a"}}, {{"", 1, 0, "b"}}));
+  EXPECT_EQ((Replacements{{"", 0, 0, "ba"}}),
+mergeReplacements({{"", 0, 0, "a"}}, {{"", 0, 0, "b"}}));
+  mergeAndTestRewrite("", "a", "ab", {{"", 0, 0, "a"}}, {{"", 1, 0, "b"}});
+  mergeAndTestRewrite("", "a", "ba", {{"", 0, 0, "a"}}, {{"", 0, 0, "b"}});
+}
+
+TEST_F(MergeReplacementsTest, NotChangingLengths) {
+  mergeAndTestRewrite("", "abba", "acca", {{"", 1, 2, "bb"}},
+  {{"", 1, 2, "cc"}});
+  mergeAndTestRewrite("", "abba", "abcc", {{"", 1, 2, "bb"}},
+  {{"", 2, 2, "cc"}});
+  mergeAndTestRewrite("", "abba", "ccba", {{"", 1, 2, "bb"}},
+  {{"", 0, 2, "cc"}});
+  mergeAndTestRewrite("aa", "abbdda", "abccda",
+  {{"", 1, 2, "bb"}, {"", 3, 2, "dd"}}, {{"", 2, 2, "cc"}});
+}
+
+TEST_F(MergeReplacementsTest, OverlappingRanges) {
+  mergeAndTestRewrite("aaa", "bbd", "bcbcd",
+  {{"", 0, 1, "bb"}, {"", 1, 2, "d"}},
+  {{"", 1, 0, "c"}, {"", 2, 0, "c"}});
+
+  mergeAndTestRewrite("", "aabbaa", "aa", {{"", 2, 0, "bb"}},
+  {{"", 1, 4, ""}});
+  mergeAndTestRewrite("", "aababa", "aa",
+  {{"", 2, 0, "b"}, {"", 3, 0, "b"}}, {{"", 1, 4, ""}});
+  mergeAndTestRewrite("aa", "aa", "abba", {{"", 1, 4, ""}},
+  {{"", 2, 2, ""}});
+  mergeAndTestRewrite("", "aa", "cc", {{"", 1, 1, ""}, {"", 2, 1, ""}},
+  {{"", 0, 2, "cc"}});
+  mergeAndTestRewrite("aa", "abbba", "abcbcba", {{"", 1, 0, "bbb"}},
+  {{"", 2, 0, "c"}, {"", 3, 0, "c"}});
+
+  mergeAndTestRewrite("aaa", "abbab

Re: [PATCH] D5102: [analyzer][Bugfix/improvement] Fix for PR16833

2015-09-22 Thread Yury Gribov via cfe-commits
ygribov added a subscriber: ygribov.
ygribov added a comment.

Folks, could someone commit this for us?


http://reviews.llvm.org/D5102



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


Re: [PATCH] D11240: Add basic #include sorting functionality to clang-format

2015-09-22 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

Ok, I think this is now understandable enough for me to go in.


http://reviews.llvm.org/D11240



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


Re: [PATCH] __attribute__((enable_if)) and non-overloaded member functions

2015-09-22 Thread George Burgess via cfe-commits
Looks good to me!

Do you have commit access, or would you like for me to commit it for you?

George

On Tue, Sep 22, 2015 at 7:45 AM, Ettore Speziale 
wrote:

> Hello,
>
> > It looks like the attached patch is the same as the original one?
>
> I’ve attache the wrong patch. Here is the right one:
>
>
>
> Thanks,
> Ettore Speziale
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D5102: [analyzer][Bugfix/improvement] Fix for PR16833

2015-09-22 Thread Devin Coughlin via cfe-commits
dcoughlin added a comment.

I will commit. Thanks!


http://reviews.llvm.org/D5102



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


[libcxx] r248307 - The test I cnecked in to check the fix for PR#24890 failed (as expected) w/o the fix, but for the wrong reason. Now it fails for the right reason.

2015-09-22 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Tue Sep 22 13:09:13 2015
New Revision: 248307

URL: http://llvm.org/viewvc/llvm-project?rev=248307&view=rev
Log:
The test I cnecked in to check the fix for PR#24890 failed (as expected) w/o 
the fix, but for the wrong reason. Now it fails for the right reason.

Modified:
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp

Modified: libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp?rev=248307&r1=248306&r2=248307&view=diff
==
--- libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/swap.pass.cpp Tue 
Sep 22 13:09:13 2015
@@ -20,6 +20,7 @@ struct S {
 int i; 
 S() : i(0) {}
 S(int j) : i(j) {}
+S * operator& () { assert(false); return this; }
 S const * operator& () const { assert(false); return this; }
 bool operator==(int x) const { return i == x; }
 };


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


Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Joerg Sonnenberger via cfe-commits
On Tue, Sep 22, 2015 at 05:44:59PM +, Eric Fiselier via cfe-commits wrote:
> EricWF added a comment.
> 
> Does anything actually need this? This interface was never really meant to be 
> complete, just want was needed.
> 
> > It's a shame that libc++ decided to reinvent the wheel here and not use the 
> > C11 atomics support
> 
> 
> GCC doesn't provide "_Atomic" and `` isn't always fully available. 
> This is a minimal subset of atomic functionality needed to support 
> `std::shared_ptr` and `std::call_once` among other things. All new code 
> should use std::atomic IMO. It's not meant to reinvent the wheel, It's meant 
> to be a portable option for when there is no "wheel" already.
> 
> Does armv4 need lib calls for atomic operations on "unsigned long"?

Yes, the hardware doesn't support anything.

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


Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Dimitry Andric via cfe-commits
dim added a comment.

In http://reviews.llvm.org/D13051#250836, @EricWF wrote:

> Does anything actually need this? This interface was never really meant to be 
> complete, just want was needed.


I need it at least for FreeBSD/arm, since it defaults to armv4, and it does not 
yet have a full set of atomic ops as libcalls.  In any case, if stub functions 
are provided, they should at least compile. :-)


http://reviews.llvm.org/D13051



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


[PATCH] D13062: [libcxx] Fix PR24779 -- Prevent evaluation of std::is_default_constructible in clearly ill-formed tuple constructor.

2015-09-22 Thread Eric Fiselier via cfe-commits
EricWF created this revision.
EricWF added a reviewer: mclow.lists.
EricWF added a subscriber: cfe-commits.

This patch fixes PR24779 (https://llvm.org/bugs/show_bug.cgi?id=24779)


http://reviews.llvm.org/D13062

Files:
  include/tuple
  test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes_PR24779.pass.cpp

Index: 
test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes_PR24779.pass.cpp
===
--- /dev/null
+++ 
test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes_PR24779.pass.cpp
@@ -0,0 +1,40 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  class tuple;
+
+// template 
+//   tuple(allocator_arg_t, const Alloc& a, UTypes&&...);
+
+// UNSUPPORTED: c++98, c++03
+
+// Check that this constructor does not evaluate
+// std::is_default_constructible for any T in Types.
+
+#include 
+#include 
+
+template 
+struct BadDefaultCtor {
+constexpr BadDefaultCtor() {
+static_assert(!std::is_same::value, "");
+}
+
+explicit BadDefaultCtor(int) {}
+};
+
+void DeleteFn(int*) {}
+
+int main() {
+typedef BadDefaultCtor<> Type;
+typedef std::tuple Tuple;
+Tuple t(Type(0), Type(0));
+}
Index: include/tuple
===
--- include/tuple
+++ include/tuple
@@ -635,7 +635,8 @@
  >::value &&
  __all_default_constructible<
 typename __make_tuple_types::type
  >::value


Index: test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes_PR24779.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_UTypes_PR24779.pass.cpp
@@ -0,0 +1,40 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  class tuple;
+
+// template 
+//   tuple(allocator_arg_t, const Alloc& a, UTypes&&...);
+
+// UNSUPPORTED: c++98, c++03
+
+// Check that this constructor does not evaluate
+// std::is_default_constructible for any T in Types.
+
+#include 
+#include 
+
+template 
+struct BadDefaultCtor {
+constexpr BadDefaultCtor() {
+static_assert(!std::is_same::value, "");
+}
+
+explicit BadDefaultCtor(int) {}
+};
+
+void DeleteFn(int*) {}
+
+int main() {
+typedef BadDefaultCtor<> Type;
+typedef std::tuple Tuple;
+Tuple t(Type(0), Type(0));
+}
Index: include/tuple
===
--- include/tuple
+++ include/tuple
@@ -635,7 +635,8 @@
  >::value &&
  __all_default_constructible<
 typename __make_tuple_types::type
  >::value
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

Ah sorry I hadn't had coffee yet. Sorry for the breakage. I'll make sure this 
make sure this patch gets backported appropriately.

LGTM thanks for the fix.


http://reviews.llvm.org/D13051



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


[libcxx] r248309 - Remove possible trailing padding from aligned_storage. Patch from Yiran Wang

2015-09-22 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Sep 22 13:37:03 2015
New Revision: 248309

URL: http://llvm.org/viewvc/llvm-project?rev=248309&view=rev
Log:
Remove possible trailing padding from aligned_storage. Patch from Yiran Wang

Modified:
libcxx/trunk/include/type_traits

Modified: libcxx/trunk/include/type_traits
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=248309&r1=248308&r2=248309&view=diff
==
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Tue Sep 22 13:37:03 2015
@@ -1190,7 +1190,7 @@ struct _LIBCPP_TYPE_VIS_ONLY aligned_sto
 union type
 {
 _Aligner __align;
-unsigned char __data[_Len];
+unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
 };
 };
 
@@ -1205,7 +1205,7 @@ struct _LIBCPP_TYPE_VIS_ONLY aligned_sto
 {\
 struct _ALIGNAS(n) type\
 {\
-unsigned char __lx[_Len];\
+unsigned char __lx[(_Len + n - 1)/n * n];\
 };\
 }
 


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


Re: [PATCH] D12247: [libc++] remove possible trailing padding from aligned_storage

2015-09-22 Thread Eric Fiselier via cfe-commits
EricWF closed this revision.
EricWF added a comment.

Committed as r248309.


http://reviews.llvm.org/D12247



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


Re: [PATCH] D12247: [libc++] remove possible trailing padding from aligned_storage

2015-09-22 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

Sure sorry for the delay.


http://reviews.llvm.org/D12247



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


Re: [PATCH] D13062: [libcxx] Fix PR24779 -- Prevent evaluation of std::is_default_constructible in clearly ill-formed tuple constructor.

2015-09-22 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

This probably isn't quite right. I need to think about it for a minute.


http://reviews.llvm.org/D13062



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


Re: [PATCH] D12793: Three new security overflow builtins with generic argument types

2015-09-22 Thread John McCall via cfe-commits
rjmccall added inline comments.


Comment at: docs/LanguageExtensions.rst:1720
@@ -1712,1 +1719,3 @@
+being stored there, and the function returns 1.  The behavior of these builtins
+is well-defined for all argument values.
 

DavidEGrayson wrote:
> rjmccall wrote:
> > Hmm.  It's not necessarily truncation; you could meaningfully use these 
> > intrinsics to add two small signed numbers and store the result in an 
> > unsigned number.  It's the unique representative value modulo 2^n, where n 
> > is the bit-width of the result.
> OK, I'll change the documentation because I like your way of phrasing it, but 
> I think truncation always gives you the unique representative value modulo 
> 2^n.  If I'm adding ((int8_t)-1) to ((int8_t)-1), the infinite-width result 
> would be -2, which in infinite-width binary is 11...0.  Then we 
> truncate it to 8 bits to get 1110, which is 254.  And 254 is also the 
> unique representative value of -2 modulo 256.
> 
When talking about mathematical abstractions, I think it's better to stick with 
mathematical presentations all the way through instead of mixing in the idea 
that the universe is 2's-complement. :)


Comment at: lib/CodeGen/CGBuiltin.cpp:1601
@@ +1600,3 @@
+auto RITy = IntegerWidthAndSignedness(CGM.getContext(), RQTy);
+auto EITy = EncompassingIntegerType({XITy, YITy, RITy});
+

DavidEGrayson wrote:
> rjmccall wrote:
> > These are not the most evocative names you could have chosen. :)
> > 
> > Also, this strategy is correct, but it produces horrible code when the 
> > operands have the same signedness and the result is different, where the 
> > result would otherwise be an ordinary operation and a compare.  You really 
> > want to just merge the two operands and then max with the width of the 
> > result type.
> I don't think that would work.  It sounds like you want me to remove RITy 
> from the call to EncompassingIntegerType.  That means the ecompassing type 
> could be smaller than the result type, and the arithmetic intrinsic would 
> report an overflow even though the mathematical result is representable in 
> the result type.
> 
> For example, if I am multiplying ((uint8_t)100) by ((uint8_t)100) and storing 
> the result in a (uint16_t), the result needs to be 1 and there is no 
> overflow.  To arrive at that result, we need to convert the operands to 
> 16-bit unsigned integers before multiplying them.  If we multiply them as 
> 8-bit unsigned integers, the multiplication intrinsic will report an overflow 
> and give a result of 16.  That seems like a messy situation and I don't see 
> how a max operation would fix it.
I think I was unclear.  I'm not saying that you should do a max as part of 
computing the dynamic result.  I'm saying that, when deciding the encompassing 
type, it should still be at least as wide as the result, but you should ignore 
the result type's signedness and then patch it up with a comparison at the end 
if necessary.  (I believe that in both cases, it's a signed comparison against 
zero.)

That is, when multiplying two uint8_t's and storing the result in an int16_t, 
we should just do an unsigned 16-bit multiply-with-overflow.  The computation 
overflows if the multiply overflows (which it provably doesn't, but we can let 
LLVM figure that out for now) or the result is signed-< 0.


Repository:
  rL LLVM

http://reviews.llvm.org/D12793



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


Re: r248293 - [CUDA] Add implicit __attribute__((used)) to all __global__ functions.

2015-09-22 Thread Richard Smith via cfe-commits
It seems like the real problem here is that we're giving the template
instantiation the wrong linkage. It can be used from outside this llvm
module, so it should be weak_odr instead of linkonce_odr.
On Sep 22, 2015 10:24 AM, "Artem Belevich via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

> Author: tra
> Date: Tue Sep 22 12:22:51 2015
> New Revision: 248293
>
> URL: http://llvm.org/viewvc/llvm-project?rev=248293&view=rev
> Log:
> [CUDA] Add implicit __attribute__((used)) to all __global__ functions.
>
> This makes sure that we emit kernels that were instantiated from the
> host code and which would never be explicitly referenced by anything
> else on device side.
>
> Differential Revision: http://reviews.llvm.org/D11666
>
> Modified:
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu
>
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=248293&r1=248292&r2=248293&view=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Sep 22 12:22:51 2015
> @@ -3350,6 +3350,10 @@ static void handleGlobalAttr(Sema &S, De
>D->addAttr(::new (S.Context)
>CUDAGlobalAttr(Attr.getRange(), S.Context,
>   Attr.getAttributeSpellingListIndex()));
> +
> +  // Add implicit attribute((used)) so we don't eliminate kernels
> +  // because there is nothing referencing them on device side.
> +  D->addAttr(UsedAttr::CreateImplicit(S.Context));
>  }
>
>  static void handleGNUInlineAttr(Sema &S, Decl *D, const AttributeList
> &Attr) {
>
> Modified: cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu?rev=248293&r1=248292&r2=248293&view=diff
>
> ==
> --- cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu (original)
> +++ cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu Tue Sep 22 12:22:51 2015
> @@ -1,7 +1,16 @@
> +// Make sure that __global__ functions are emitted along with correct
> +// annotations and are added to @llvm.used to prevent their elimination.
> +// REQUIRES: nvptx-registered-target
> +//
>  // RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -fcuda-is-device
> -emit-llvm -o - | FileCheck %s
>
>  #include "Inputs/cuda.h"
>
> +// Make sure that all __global__ functions are added to @llvm.used
> +// CHECK: @llvm.used = appending global
> +// CHECK-SAME: @global_function
> +// CHECK-SAME: @_Z16templated_kernelIiEvT_
> +
>  // CHECK-LABEL: define void @device_function
>  extern "C"
>  __device__ void device_function() {}
> @@ -13,4 +22,10 @@ __global__ void global_function() {
>device_function();
>  }
>
> +// Make sure host-instantiated kernels are preserved on device side.
> +template  __global__ void templated_kernel(T param) {}
> +// CHECK-LABEL: define linkonce_odr void @_Z16templated_kernelIiEvT_
> +void host_function() { templated_kernel<<<0,0>>>(0); }
> +
>  // CHECK: !{{[0-9]+}} = !{void ()* @global_function, !"kernel", i32 1}
> +// CHECK: !{{[0-9]+}} = !{void (i32)* @_Z16templated_kernelIiEvT_,
> !"kernel", i32 1}
>
>
> ___
> 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


Re: [PATCH] D12689: [libc++][static linking] std streams are not initialized prior to their use in static object constructors

2015-09-22 Thread Richard Smith via cfe-commits
On Sep 11, 2015 4:23 AM, "Evgeny Astigeevich via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:
>
> eastig added a comment.
>
> In http://reviews.llvm.org/D12689#243592, @rsmith wrote:
>
> > Can we instead fix this in Clang by ensuring that libc++ is put at the
right position in the static link order so that its initializers run first?
libc++'s avoidance of running iostreams init code from every translation
unit is a significant startup performance feature, and we shouldn't abandon
it unless we really have to.
>
>
> Let me give more details about the problem we have.
>
> Clang generates a `__cxx_global_var_init` function for each global
variable that needs to be set-up (initialized) before firing the main
routine of the user program. Those initializer functions are then grouped
under a parent initializer function named after the corresponding
translation unit: `_GLOBAL__sub_I_`.  Those
`_GLOBAL__sub_I_` entries then get stuffed into the
`.init_array` tables of individual object files.
>
> In ARM compiler toolchains `armlink` is used for linking, not `GNU ld`.
`libc++` is a part of the toolchain static system libraries. So `armlink`
logic should be updated to change the order in which the `.init_array`
entries from system libraries are added to the final image's `.init_array`
table. This can be a problem because of an assumption that there are no
dependencies among initializers from different translation units.
>
> IMHO if the programming language has a means of resolving such problems
it's better to use it instead of hacking a linker.
>
> About impact on startup performance, I don't see why it will be
significant. Initialization is done once. Other times it is simply a call
to increase a counter. To be significant there should be millions of calls.

Short-lived programs can spend significant amounts of their runtime in
initialization. There is also a binary size cost.

> Why does `gnu libc++` use a similar way if it hurts performance?

I'm sure they would prefer not to.

> In the patch the `__APPLE__` macro is used to have the old behaviour.
Maybe instead of it another macro, e.g. `__STATIC_BUILD__`, can be use when
we want to build a static library.
>
>
> http://reviews.llvm.org/D12689
>
>
>
> ___
> 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] r248313 - Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Dimitry Andric via cfe-commits
Author: dim
Date: Tue Sep 22 13:55:37 2015
New Revision: 248313

URL: http://llvm.org/viewvc/llvm-project?rev=248313&view=rev
Log:
Add placeholder __libcpp_relaxed_store() for when atomic builtins are not 
available.

Summary:
In rL241532, atomic_support.h was added, which provides handling of
atomic operations for libc++.  When atomic builtins are not available,
it emits a warning about being unsupported, but it still provides a
number of stubs for the required functions.

However, it misses a stub for `__libcpp_relaxed_store()`.  Add it, by
using the same implementation as for `__libcpp_atomic_store()`.

(Note that I encountered this on arm-freebsd, which still defaults to
armv4, and does not have the runtime libcalls to support atomic
builtins.  For now, I have simply disabled using them.)

Reviewers: mclow.lists, EricWF

Subscribers: theraven, cfe-commits, jroelofs, majnemer, aemerson

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

Modified:
libcxx/trunk/src/include/atomic_support.h

Modified: libcxx/trunk/src/include/atomic_support.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/include/atomic_support.h?rev=248313&r1=248312&r2=248313&view=diff
==
--- libcxx/trunk/src/include/atomic_support.h (original)
+++ libcxx/trunk/src/include/atomic_support.h Tue Sep 22 13:55:37 2015
@@ -103,6 +103,13 @@ void __libcpp_atomic_store(_ValueType* _
 *__dest = __val;
 }
 
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
+{
+*__dest = __val;
+}
+
 template 
 inline _LIBCPP_INLINE_VISIBILITY
 _ValueType __libcpp_atomic_load(_ValueType const* __val,


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


Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

@jroelofs @dim, could we fallback to the __sync_* builtins on arm?


http://reviews.llvm.org/D13051



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


Re: [PATCH] D12362: [clang-format] Add support of consecutive declarations alignment

2015-09-22 Thread Beren Minor via cfe-commits
berenm added a comment.

Ping?

The unit tests should work fine, now that http://reviews.llvm.org/D12369 has 
been merged.


http://reviews.llvm.org/D12362



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


Re: r244063 - Add missing atomic libcall support.

2015-09-22 Thread Dimitry Andric via cfe-commits
On 05 Aug 2015, at 18:57, James Y Knight  wrote:
> Author: jyknight
> Date: Wed Aug  5 11:57:36 2015
> New Revision: 244063
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=244063&view=rev
> Log:
> Add missing atomic libcall support.
> 
> Support for emitting libcalls for __atomic_fetch_nand and
> __atomic_{add,sub,and,or,xor,nand}_fetch was missing; add it, and some
> test cases.
> 
> Differential Revision: http://reviews.llvm.org/D10847

Hi James, is this OK to merge to the 3.7 branch, targeting 3.7.1?

-Dimitry



signature.asc
Description: Message signed with OpenPGP using GPGMail
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Jonathan Roelofs via cfe-commits
jroelofs added a comment.

In http://reviews.llvm.org/D13051#250910, @EricWF wrote:

> @jroelofs @dim, could we fallback to the __sync_* builtins on arm?


@dim would need armv4-flavored implementations of them in compiler-rt (if 
that's what he's using)... the existing ones use instructions that v4 doesn't 
have. Implementation-wise, they'd have to use `__kuser_cmpxchg`. See: 
https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt


http://reviews.llvm.org/D13051



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


r248314 - Analyzer: Teach analyzer how to handle TypeTraitExpr

2015-09-22 Thread Ismail Pazarbasi via cfe-commits
Author: ismailp
Date: Tue Sep 22 14:33:15 2015
New Revision: 248314

URL: http://llvm.org/viewvc/llvm-project?rev=248314&view=rev
Log:
Analyzer: Teach analyzer how to handle TypeTraitExpr

Summary:
`TypeTraitExpr`s are not supported by the ExprEngine today. Analyzer
creates a sink, and aborts the block. Therefore, certain bugs that
involve type traits intrinsics cannot be detected (see PR24710).

This patch creates boolean `SVal`s for `TypeTraitExpr`s, which are
evaluated by the compiler.

Test within the patch is a summary of PR24710.

Reviewers: zaks.anna, dcoughlin, krememek

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
cfe/trunk/test/Analysis/dtor.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp?rev=248314&r1=248313&r2=248314&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp Tue Sep 22 14:33:15 2015
@@ -90,6 +90,7 @@ SVal Environment::getSVal(const Environm
   case Stmt::CXXNullPtrLiteralExprClass:
   case Stmt::ObjCStringLiteralClass:
   case Stmt::StringLiteralClass:
+  case Stmt::TypeTraitExprClass:
 // Known constants; defer to SValBuilder.
 return svalBuilder.getConstantVal(cast(S)).getValue();
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=248314&r1=248313&r2=248314&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Sep 22 14:33:15 2015
@@ -756,7 +756,6 @@ void ExprEngine::Visit(const Stmt *S, Ex
 case Stmt::MSPropertyRefExprClass:
 case Stmt::CXXUnresolvedConstructExprClass:
 case Stmt::DependentScopeDeclRefExprClass:
-case Stmt::TypeTraitExprClass:
 case Stmt::ArrayTypeTraitExprClass:
 case Stmt::ExpressionTraitExprClass:
 case Stmt::UnresolvedLookupExprClass:
@@ -902,7 +901,8 @@ void ExprEngine::Visit(const Stmt *S, Ex
 case Stmt::CXXPseudoDestructorExprClass:
 case Stmt::SubstNonTypeTemplateParmExprClass:
 case Stmt::CXXNullPtrLiteralExprClass:
-case Stmt::OMPArraySectionExprClass: {
+case Stmt::OMPArraySectionExprClass:
+case Stmt::TypeTraitExprClass: {
   Bldr.takeNodes(Pred);
   ExplodedNodeSet preVisit;
   getCheckerManager().runCheckersForPreStmt(preVisit, Pred, S, *this);

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp?rev=248314&r1=248313&r2=248314&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp Tue Sep 22 14:33:15 2015
@@ -259,6 +259,11 @@ Optional SValBuilder::getConstantV
   case Stmt::CXXBoolLiteralExprClass:
 return makeBoolVal(cast(E));
 
+  case Stmt::TypeTraitExprClass: {
+const TypeTraitExpr *TE = cast(E);
+return makeTruthVal(TE->getValue(), TE->getType());
+  }
+
   case Stmt::IntegerLiteralClass:
 return makeIntVal(cast(E));
 

Modified: cfe/trunk/test/Analysis/dtor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dtor.cpp?rev=248314&r1=248313&r2=248314&view=diff
==
--- cfe/trunk/test/Analysis/dtor.cpp (original)
+++ cfe/trunk/test/Analysis/dtor.cpp Tue Sep 22 14:33:15 2015
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config 
c++-inlining=destructors,cfg-temporary-dtors=true -Wno-null-dereference 
-Wno-inaccessible-base -verify %s
+// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection,cplusplus 
-analyzer-config c++-inlining=destructors,cfg-temporary-dtors=true 
-Wno-null-dereference -Wno-inaccessible-base -verify %s
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_checkInlined(bool);
@@ -505,3 +505,38 @@ namespace Incomplete {
   class Foo; // expected-note{{forward declaration}}
   void f(Foo *foo) { delete foo; } // expected-warning{{deleting pointer to 
incomplete type}}
 }
+
+namespace TypeTraitExpr {
+template 
+struct copier {
+  static void do_copy(T *dest, const T *src, unsigned count);
+};
+template 
+void do_copy(T *dest, const U *src, unsigned count) {
+  const bool IsSimple = __is_trivial(T) && __is_same(T, U);
+  copier::do_copy(dest, src, count);
+}
+struct NonTrivial {
+  int *p;
+ 

Re: [PATCH] D12482: Analyzer: Teach analyzer how to handle TypeTraitExpr

2015-09-22 Thread Ismail Pazarbasi via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL248314: Analyzer: Teach analyzer how to handle TypeTraitExpr 
(authored by ismailp).

Changed prior to commit:
  http://reviews.llvm.org/D12482?vs=35384&id=35403#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12482

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
  cfe/trunk/test/Analysis/dtor.cpp

Index: cfe/trunk/test/Analysis/dtor.cpp
===
--- cfe/trunk/test/Analysis/dtor.cpp
+++ cfe/trunk/test/Analysis/dtor.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config 
c++-inlining=destructors,cfg-temporary-dtors=true -Wno-null-dereference 
-Wno-inaccessible-base -verify %s
+// RUN: %clang_cc1 -analyze 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection,cplusplus 
-analyzer-config c++-inlining=destructors,cfg-temporary-dtors=true 
-Wno-null-dereference -Wno-inaccessible-base -verify %s
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_checkInlined(bool);
@@ -505,3 +505,38 @@
   class Foo; // expected-note{{forward declaration}}
   void f(Foo *foo) { delete foo; } // expected-warning{{deleting pointer to 
incomplete type}}
 }
+
+namespace TypeTraitExpr {
+template 
+struct copier {
+  static void do_copy(T *dest, const T *src, unsigned count);
+};
+template 
+void do_copy(T *dest, const U *src, unsigned count) {
+  const bool IsSimple = __is_trivial(T) && __is_same(T, U);
+  copier::do_copy(dest, src, count);
+}
+struct NonTrivial {
+  int *p;
+  NonTrivial() : p(new int[1]) { p[0] = 0; }
+  NonTrivial(const NonTrivial &other) {
+p = new int[1];
+do_copy(p, other.p, 1);
+  }
+  NonTrivial &operator=(const NonTrivial &other) {
+p = other.p;
+return *this;
+  }
+  ~NonTrivial() {
+delete[] p; // expected-warning {{free released memory}}
+  }
+};
+
+void f() {
+  NonTrivial nt1;
+  NonTrivial nt2(nt1);
+  nt1 = nt2;
+  clang_analyzer_eval(__is_trivial(NonTrivial)); // expected-warning{{FALSE}}
+  clang_analyzer_eval(__alignof(NonTrivial) > 0); // expected-warning{{TRUE}}
+}
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -756,7 +756,6 @@
 case Stmt::MSPropertyRefExprClass:
 case Stmt::CXXUnresolvedConstructExprClass:
 case Stmt::DependentScopeDeclRefExprClass:
-case Stmt::TypeTraitExprClass:
 case Stmt::ArrayTypeTraitExprClass:
 case Stmt::ExpressionTraitExprClass:
 case Stmt::UnresolvedLookupExprClass:
@@ -902,7 +901,8 @@
 case Stmt::CXXPseudoDestructorExprClass:
 case Stmt::SubstNonTypeTemplateParmExprClass:
 case Stmt::CXXNullPtrLiteralExprClass:
-case Stmt::OMPArraySectionExprClass: {
+case Stmt::OMPArraySectionExprClass:
+case Stmt::TypeTraitExprClass: {
   Bldr.takeNodes(Pred);
   ExplodedNodeSet preVisit;
   getCheckerManager().runCheckersForPreStmt(preVisit, Pred, S, *this);
Index: cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -259,6 +259,11 @@
   case Stmt::CXXBoolLiteralExprClass:
 return makeBoolVal(cast(E));
 
+  case Stmt::TypeTraitExprClass: {
+const TypeTraitExpr *TE = cast(E);
+return makeTruthVal(TE->getValue(), TE->getType());
+  }
+
   case Stmt::IntegerLiteralClass:
 return makeIntVal(cast(E));
 
Index: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
@@ -90,6 +90,7 @@
   case Stmt::CXXNullPtrLiteralExprClass:
   case Stmt::ObjCStringLiteralClass:
   case Stmt::StringLiteralClass:
+  case Stmt::TypeTraitExprClass:
 // Known constants; defer to SValBuilder.
 return svalBuilder.getConstantVal(cast(S)).getValue();
 


Index: cfe/trunk/test/Analysis/dtor.cpp
===
--- cfe/trunk/test/Analysis/dtor.cpp
+++ cfe/trunk/test/Analysis/dtor.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config c++-inlining=destructors,cfg-temporary-dtors=true -Wno-null-dereference -Wno-inaccessible-base -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection,cplusplus -analyzer-config c++-inlining=destructors,cfg-temporary-dtors=true -Wno-null-dereference -Wno-inaccessible-base -verify %s
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_checkInlined(bool);

Re: [PATCH] D12417: Improvements to localizability checks for iOS / OS X

2015-09-22 Thread Kulpreet Chilana via cfe-commits
kulpreet added a subscriber: cfe-commits.
kulpreet updated this revision to Diff 35404.
kulpreet added a comment.

Shortened description of PluralMisuseChecker in Checkers.td as per Anna's 
recommendation.


http://reviews.llvm.org/D12417

Files:
  lib/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  test/Analysis/localization-aggressive.m
  test/Analysis/localization.m

Index: test/Analysis/localization.m
===
--- test/Analysis/localization.m
+++ test/Analysis/localization.m
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -fblocks -analyzer-store=region -analyzer-checker=alpha.osx.cocoa.NonLocalizedStringChecker -analyzer-checker=alpha.osx.cocoa.EmptyLocalizationContextChecker -verify  %s
+// RUN: %clang_cc1 -analyze -fblocks -analyzer-store=region -analyzer-checker=alpha.osx.cocoa.NonLocalizedStringChecker -analyzer-checker=alpha.osx.cocoa.PluralMisuseChecker -verify  %s
 
 // The larger set of tests in located in localization.m. These are tests
 // specific for non-aggressive reporting.
@@ -20,6 +20,8 @@
 - (id)init;
 @end
 @interface NSString : NSObject
+- (NSString *)stringByAppendingFormat:(NSString *)format, ...;
++ (instancetype)stringWithFormat:(NSString *)format, ...;
 @end
 @interface NSBundle : NSObject
 + (NSBundle *)mainBundle;
@@ -36,11 +38,16 @@
 
 @interface LocalizationTestSuite : NSObject
 int random();
+@property (assign) int unreadArticlesCount;
 @end
-
+#define MCLocalizedString(s) NSLocalizedString(s,nil);
 // Test cases begin here
 @implementation LocalizationTestSuite
 
+NSString *KHLocalizedString(NSString* key, NSString* comment) {
+return NSLocalizedString(key, comment);
+}
+
 // An object passed in as an parameter's string member
 // should not be considered unlocalized
 - (void)testObjectAsArgument:(TestObject *)argumentObject {
@@ -58,7 +65,7 @@
 bar = @"Unlocalized string";
   }
 
-  [testLabel setText:bar]; // expected-warning {{String should be localized}}
+  [testLabel setText:bar]; // expected-warning {{User-facing text should use localized string macro}}
 }
 
 - (void)testOneCharacterStringsDoNotGiveAWarning {
@@ -83,4 +90,118 @@
   [testLabel setText:bar]; // no-warning
 }
 
+// Plural Misuse Checker Tests
+// These tests are modeled off incorrect uses of the many-one pattern
+// from real projects. 
+
+- (NSString *)test1:(int)plural {
+if (plural) {
+return MCLocalizedString(@"TYPE_PLURAL"); // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
+}
+return MCLocalizedString(@"TYPE");
+}
+
+- (NSString *)test2:(int)numOfReminders {
+if (numOfReminders > 0) {
+return [NSString stringWithFormat:@"%@, %@", @"Test", (numOfReminders != 1) ? [NSString stringWithFormat:NSLocalizedString(@"%@ Reminders", @"Plural count of reminders"), numOfReminders] : [NSString stringWithFormat:NSLocalizedString(@"1 reminder", @"One reminder")]]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}} expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
+} 
+return nil;
+}
+
+- (void)test3 {
+NSString *count;
+if (self.unreadArticlesCount > 1)
+{
+count = [count stringByAppendingFormat:@"%@", KHLocalizedString(@"New Stories", @"Plural count for new stories")]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
+} else {
+count = [count stringByAppendingFormat:@"%@",  KHLocalizedString(@"New Story", @"One new story")]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
+}
+}
+
+- (NSString *)test4:(int)count {
+if ( count == 1 )
+{
+return [NSString stringWithFormat:KHLocalizedString(@"value.singular",nil), count]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
+} else {
+return [NSString stringWithFormat:KHLocalizedString(@"value.plural",nil), count]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
+}
+}
+
+- (NSString *)test5:(int)count {
+	int test = count == 1;
+if (test)
+{
+return [NSString stringWithFormat:KHLocalizedString(@"value.singular",nil), count]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
+} else {
+return [NSString stringWithFormat:KHLocalizedString(@"value.plural",nil), count]; // expected-warning {{Plural cases are not supported accross all languages. Use a .stringsdict file}}
+}
+}
+
+// This tests the heuristic that the direct parent IfStmt must match the isCheckingPlurality confition to avoid false positives generated from complex code (generally the pattern we're looking for is simple If-Else)
+
+- (NSString *)test6:(int)s

Re: [PATCH] __attribute__((enable_if)) and non-overloaded member functions

2015-09-22 Thread Ettore Speziale via cfe-commits
Hello,

> Looks good to me!
> 
> Do you have commit access, or would you like for me to commit it for you?

I do not have commit access. It would be great if you can commit for me.

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


Re: [PATCH] D10881: [Sema] Catch a case when 'volatile' qualifier is dropped while binding

2015-09-22 Thread John McCall via cfe-commits
rjmccall added a comment.

This is outside of my expertise, but I've asked Doug Gregor to take a look.


http://reviews.llvm.org/D10881



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


Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Joerg Sonnenberger via cfe-commits
On Tue, Sep 22, 2015 at 07:26:46PM +, Jonathan Roelofs via cfe-commits 
wrote:
> jroelofs added a comment.
> 
> In http://reviews.llvm.org/D13051#250910, @EricWF wrote:
> 
> > @jroelofs @dim, could we fallback to the __sync_* builtins on arm?
> 
> 
> @dim would need armv4-flavored implementations of them in compiler-rt
> (if that's what he's using)... the existing ones use instructions that
> v4 doesn't have. Implementation-wise, they'd have to use
> `__kuser_cmpxchg`. See: 
> https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt

That's a Linux-specific function/system call. That's not really helpful
on FreeBSD. NetBSD provides restartable atomic sequences for this
purpose.

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


r248318 - [analyzer] Create one state for a range switch case instead of multiple.

2015-09-22 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Tue Sep 22 15:31:19 2015
New Revision: 248318

URL: http://llvm.org/viewvc/llvm-project?rev=248318&view=rev
Log:
[analyzer] Create one state for a range switch case instead of multiple.

This fixes PR16833, in which the analyzer was using large amounts of memory
for switch statements with large case ranges.

rdar://problem/14685772

A patch by Aleksei Sidorin!

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

Added:
cfe/trunk/test/Analysis/switch-case.c
Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.h

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h?rev=248318&r1=248317&r2=248318&view=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
Tue Sep 22 15:31:19 2015
@@ -99,6 +99,35 @@ public:
 return ProgramStatePair(StTrue, StFalse);
   }
 
+  virtual ProgramStateRef assumeWithinInclusiveRange(ProgramStateRef State,
+ NonLoc Value,
+ const llvm::APSInt &From,
+ const llvm::APSInt &To,
+ bool InBound) = 0;
+
+  virtual ProgramStatePair assumeWithinInclusiveRangeDual(
+  ProgramStateRef State, NonLoc Value, const llvm::APSInt &From,
+  const llvm::APSInt &To) {
+ProgramStateRef StInRange = assumeWithinInclusiveRange(State, Value, From,
+   To, true);
+
+// If StTrue is infeasible, asserting the falseness of Cond is unnecessary
+// because the existing constraints already establish this.
+if (!StInRange)
+  return ProgramStatePair((ProgramStateRef)nullptr, State);
+
+ProgramStateRef StOutOfRange = assumeWithinInclusiveRange(State, Value,
+  From, To, false);
+if (!StOutOfRange) {
+  // We are careful to return the original state, /not/ StTrue,
+  // because we want to avoid having callers generate a new node
+  // in the ExplodedGraph.
+  return ProgramStatePair(State, (ProgramStateRef)nullptr);
+}
+
+return ProgramStatePair(StInRange, StOutOfRange);
+  }
+
   /// \brief If a symbol is perfectly constrained to a constant, attempt
   /// to return the concrete value.
   ///

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=248318&r1=248317&r2=248318&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Tue Sep 22 15:31:19 2015
@@ -190,6 +190,27 @@ public:
DefinedOrUnknownSVal upperBound,
bool assumption,
QualType IndexType = QualType()) const;
+
+  /// Assumes that the value of \p Val is bounded with [\p From; \p To]
+  /// (if \p assumption is "true") or it is fully out of this range
+  /// (if \p assumption is "false").
+  ///
+  /// This returns a new state with the added constraint on \p cond.
+  /// If no new state is feasible, NULL is returned.
+  ProgramStateRef assumeWithinInclusiveRange(DefinedOrUnknownSVal Val,
+ const llvm::APSInt &From,
+ const llvm::APSInt &To,
+ bool assumption) const;
+
+  /// Assumes given range both "true" and "false" for \p Val, and returns both
+  /// corresponding states (respectively).
+  ///
+  /// This is more efficient than calling assume() twice. Note that one (but 
not
+  /// both) of the returned states may be NULL.
+  std::pair
+  assumeWithinInclusiveRange(DefinedOrUnknownSVal Val, const llvm::APSInt 
&From,
+ const llvm::APSInt &To) const;
+
   
   /// \brief Check if the given SVal is constrained to zero or is a zero
   ///constant.
@@ -636,6 +657,33 @@ ProgramState::assume(DefinedOrUnk

Re: [PATCH] D5102: [analyzer][Bugfix/improvement] Fix for PR16833

2015-09-22 Thread Devin Coughlin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL248318: [analyzer] Create one state for a range switch case 
instead of multiple. (authored by dcoughlin).

Changed prior to commit:
  http://reviews.llvm.org/D5102?vs=32664&id=35411#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D5102

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  cfe/trunk/lib/Analysis/CFG.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/SimpleConstraintManager.h
  cfe/trunk/test/Analysis/switch-case.c

Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
@@ -99,6 +99,35 @@
 return ProgramStatePair(StTrue, StFalse);
   }
 
+  virtual ProgramStateRef assumeWithinInclusiveRange(ProgramStateRef State,
+ NonLoc Value,
+ const llvm::APSInt &From,
+ const llvm::APSInt &To,
+ bool InBound) = 0;
+
+  virtual ProgramStatePair assumeWithinInclusiveRangeDual(
+  ProgramStateRef State, NonLoc Value, const llvm::APSInt &From,
+  const llvm::APSInt &To) {
+ProgramStateRef StInRange = assumeWithinInclusiveRange(State, Value, From,
+   To, true);
+
+// If StTrue is infeasible, asserting the falseness of Cond is unnecessary
+// because the existing constraints already establish this.
+if (!StInRange)
+  return ProgramStatePair((ProgramStateRef)nullptr, State);
+
+ProgramStateRef StOutOfRange = assumeWithinInclusiveRange(State, Value,
+  From, To, false);
+if (!StOutOfRange) {
+  // We are careful to return the original state, /not/ StTrue,
+  // because we want to avoid having callers generate a new node
+  // in the ExplodedGraph.
+  return ProgramStatePair(State, (ProgramStateRef)nullptr);
+}
+
+return ProgramStatePair(StInRange, StOutOfRange);
+  }
+
   /// \brief If a symbol is perfectly constrained to a constant, attempt
   /// to return the concrete value.
   ///
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -190,6 +190,27 @@
DefinedOrUnknownSVal upperBound,
bool assumption,
QualType IndexType = QualType()) const;
+
+  /// Assumes that the value of \p Val is bounded with [\p From; \p To]
+  /// (if \p assumption is "true") or it is fully out of this range
+  /// (if \p assumption is "false").
+  ///
+  /// This returns a new state with the added constraint on \p cond.
+  /// If no new state is feasible, NULL is returned.
+  ProgramStateRef assumeWithinInclusiveRange(DefinedOrUnknownSVal Val,
+ const llvm::APSInt &From,
+ const llvm::APSInt &To,
+ bool assumption) const;
+
+  /// Assumes given range both "true" and "false" for \p Val, and returns both
+  /// corresponding states (respectively).
+  ///
+  /// This is more efficient than calling assume() twice. Note that one (but not
+  /// both) of the returned states may be NULL.
+  std::pair
+  assumeWithinInclusiveRange(DefinedOrUnknownSVal Val, const llvm::APSInt &From,
+ const llvm::APSInt &To) const;
+
   
   /// \brief Check if the given SVal is constrained to zero or is a zero
   ///constant.
@@ -636,6 +657,33 @@
   ->assumeDual(this, Cond.castAs());
 }
 
+inline ProgramStateRef
+ProgramState::assumeWithinInclusiveRange(DefinedOrUnknownSVal Val,
+ const llvm::APSInt &From,
+ const llvm::APSInt &To,
+ bool Assumption) const {
+  if (Val.isUnknown())
+return this;
+
+  assert(Val.getAs() && "Only NonLocs are supported!");
+
+  return getStateManager().ConstraintMgr->assumeWithinInclusiveRange(
+this, Val.castAs(), From, To, Assumption);
+}
+
+inline std::pair
+ProgramState::assumeW

[PATCH] D13067: [CUDA] __global__ functions should always be visible externally.

2015-09-22 Thread Artem Belevich via cfe-commits
tra created this revision.
tra added reviewers: rsmith, echristo.
tra added a subscriber: cfe-commits.

Adjusted __global__ functions with DiscardableODR linkage to use StrongODR 
linkage instead so they are visible externally.

Replaces D11666 / r248293


http://reviews.llvm.org/D13067

Files:
  lib/AST/ASTContext.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCUDA/ptx-kernels.cu

Index: test/CodeGenCUDA/ptx-kernels.cu
===
--- test/CodeGenCUDA/ptx-kernels.cu
+++ test/CodeGenCUDA/ptx-kernels.cu
@@ -6,11 +6,6 @@
 
 #include "Inputs/cuda.h"
 
-// Make sure that all __global__ functions are added to @llvm.used
-// CHECK: @llvm.used = appending global
-// CHECK-SAME: @global_function
-// CHECK-SAME: @_Z16templated_kernelIiEvT_
-
 // CHECK-LABEL: define void @device_function
 extern "C"
 __device__ void device_function() {}
@@ -24,7 +19,7 @@
 
 // Make sure host-instantiated kernels are preserved on device side.
 template  __global__ void templated_kernel(T param) {}
-// CHECK-LABEL: define linkonce_odr void @_Z16templated_kernelIiEvT_
+// CHECK-LABEL: define weak_odr void @_Z16templated_kernelIiEvT_
 void host_function() { templated_kernel<<<0,0>>>(0); }
 
 // CHECK: !{{[0-9]+}} = !{void ()* @global_function, !"kernel", i32 1}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3351,9 +3351,6 @@
   CUDAGlobalAttr(Attr.getRange(), S.Context,
  Attr.getAttributeSpellingListIndex()));
 
-  // Add implicit attribute((used)) so we don't eliminate kernels
-  // because there is nothing referencing them on device side.
-  D->addAttr(UsedAttr::CreateImplicit(S.Context));
 }
 
 static void handleGNUInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) {
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -8284,22 +8284,22 @@
   return GVA_DiscardableODR;
 }
 
-static GVALinkage adjustGVALinkageForDLLAttribute(GVALinkage L, const Decl *D) 
{
+static GVALinkage adjustGVALinkageForAttributes(GVALinkage L, const Decl *D) {
   // See http://msdn.microsoft.com/en-us/library/xa0d9ste.aspx
   // dllexport/dllimport on inline functions.
   if (D->hasAttr()) {
 if (L == GVA_DiscardableODR || L == GVA_StrongODR)
   return GVA_AvailableExternally;
-  } else if (D->hasAttr()) {
+  } else if (D->hasAttr() || D->hasAttr()) {
 if (L == GVA_DiscardableODR)
   return GVA_StrongODR;
   }
   return L;
 }
 
 GVALinkage ASTContext::GetGVALinkageForFunction(const FunctionDecl *FD) const {
-  return adjustGVALinkageForDLLAttribute(basicGVALinkageForFunction(*this, FD),
- FD);
+  return adjustGVALinkageForAttributes(basicGVALinkageForFunction(*this, FD),
+   FD);
 }
 
 static GVALinkage basicGVALinkageForVariable(const ASTContext &Context,
@@ -8355,8 +8355,8 @@
 }
 
 GVALinkage ASTContext::GetGVALinkageForVariable(const VarDecl *VD) {
-  return adjustGVALinkageForDLLAttribute(basicGVALinkageForVariable(*this, VD),
- VD);
+  return adjustGVALinkageForAttributes(basicGVALinkageForVariable(*this, VD),
+   VD);
 }
 
 bool ASTContext::DeclMustBeEmitted(const Decl *D) {


Index: test/CodeGenCUDA/ptx-kernels.cu
===
--- test/CodeGenCUDA/ptx-kernels.cu
+++ test/CodeGenCUDA/ptx-kernels.cu
@@ -6,11 +6,6 @@
 
 #include "Inputs/cuda.h"
 
-// Make sure that all __global__ functions are added to @llvm.used
-// CHECK: @llvm.used = appending global
-// CHECK-SAME: @global_function
-// CHECK-SAME: @_Z16templated_kernelIiEvT_
-
 // CHECK-LABEL: define void @device_function
 extern "C"
 __device__ void device_function() {}
@@ -24,7 +19,7 @@
 
 // Make sure host-instantiated kernels are preserved on device side.
 template  __global__ void templated_kernel(T param) {}
-// CHECK-LABEL: define linkonce_odr void @_Z16templated_kernelIiEvT_
+// CHECK-LABEL: define weak_odr void @_Z16templated_kernelIiEvT_
 void host_function() { templated_kernel<<<0,0>>>(0); }
 
 // CHECK: !{{[0-9]+}} = !{void ()* @global_function, !"kernel", i32 1}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -3351,9 +3351,6 @@
   CUDAGlobalAttr(Attr.getRange(), S.Context,
  Attr.getAttributeSpellingListIndex()));
 
-  // Add implicit attribute((used)) so we don't eliminate kernels
-  // because there is nothing referencing them on device side.
-  D->addAttr(UsedAttr::CreateImplicit(S.Context));
 }
 
 static void handleGNUInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) {
Index: lib/AST/ASTContex

Re: r248293 - [CUDA] Add implicit __attribute__((used)) to all __global__ functions.

2015-09-22 Thread Artem Belevich via cfe-commits
On Tue, Sep 22, 2015 at 11:49 AM, Richard Smith 
wrote:

> It seems like the real problem here is that we're giving the template
> instantiation the wrong linkage. It can be used from outside this llvm
> module, so it should be weak_odr instead of linkonce_odr.
>
This indeed works much better. I've just sent http://reviews.llvm.org/D13067

--Artem



> On Sep 22, 2015 10:24 AM, "Artem Belevich via cfe-commits" <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: tra
>> Date: Tue Sep 22 12:22:51 2015
>> New Revision: 248293
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=248293&view=rev
>> Log:
>> [CUDA] Add implicit __attribute__((used)) to all __global__ functions.
>>
>> This makes sure that we emit kernels that were instantiated from the
>> host code and which would never be explicitly referenced by anything
>> else on device side.
>>
>> Differential Revision: http://reviews.llvm.org/D11666
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>> cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu
>>
>> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=248293&r1=248292&r2=248293&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Sep 22 12:22:51 2015
>> @@ -3350,6 +3350,10 @@ static void handleGlobalAttr(Sema &S, De
>>D->addAttr(::new (S.Context)
>>CUDAGlobalAttr(Attr.getRange(), S.Context,
>>   Attr.getAttributeSpellingListIndex()));
>> +
>> +  // Add implicit attribute((used)) so we don't eliminate kernels
>> +  // because there is nothing referencing them on device side.
>> +  D->addAttr(UsedAttr::CreateImplicit(S.Context));
>>  }
>>
>>  static void handleGNUInlineAttr(Sema &S, Decl *D, const AttributeList
>> &Attr) {
>>
>> Modified: cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu?rev=248293&r1=248292&r2=248293&view=diff
>>
>> ==
>> --- cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu (original)
>> +++ cfe/trunk/test/CodeGenCUDA/ptx-kernels.cu Tue Sep 22 12:22:51 2015
>> @@ -1,7 +1,16 @@
>> +// Make sure that __global__ functions are emitted along with correct
>> +// annotations and are added to @llvm.used to prevent their elimination.
>> +// REQUIRES: nvptx-registered-target
>> +//
>>  // RUN: %clang_cc1 %s -triple nvptx-unknown-unknown -fcuda-is-device
>> -emit-llvm -o - | FileCheck %s
>>
>>  #include "Inputs/cuda.h"
>>
>> +// Make sure that all __global__ functions are added to @llvm.used
>> +// CHECK: @llvm.used = appending global
>> +// CHECK-SAME: @global_function
>> +// CHECK-SAME: @_Z16templated_kernelIiEvT_
>> +
>>  // CHECK-LABEL: define void @device_function
>>  extern "C"
>>  __device__ void device_function() {}
>> @@ -13,4 +22,10 @@ __global__ void global_function() {
>>device_function();
>>  }
>>
>> +// Make sure host-instantiated kernels are preserved on device side.
>> +template  __global__ void templated_kernel(T param) {}
>> +// CHECK-LABEL: define linkonce_odr void @_Z16templated_kernelIiEvT_
>> +void host_function() { templated_kernel<<<0,0>>>(0); }
>> +
>>  // CHECK: !{{[0-9]+}} = !{void ()* @global_function, !"kernel", i32 1}
>> +// CHECK: !{{[0-9]+}} = !{void (i32)* @_Z16templated_kernelIiEvT_,
>> !"kernel", i32 1}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>


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


[PATCH] D13071: [PATCH] New checker for mismatched operator new/operator delete definitions

2015-09-22 Thread Aaron Ballman via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: klimek, alexfh.
aaron.ballman added a subscriber: cfe-commits.

When defining a free store function, it is almost invariably a bug to fail to 
declare the corresponding free store function. For instance, implementing 
operator new() but failing to implement operator delete(). This new checker 
catches instances where the free store functions are mismatched, while still 
allowing for common code patterns involving deleted functions or placement 
forms of functions. Specifically, this will not warn on implicit free store 
functions, placement forms, deleted functions (such as defining a placement new 
and a deleted operator delete(void*)), and private functions (for code that 
predates C++11).

This patch corresponds to: 
https://www.securecoding.cert.org/confluence/display/cplusplus/DCL54-CPP.+Overload+allocation+and+deallocation+functions+as+a+pair+in+the+same+scope

I ran this checker over Clang and LLVM and it did find two issues, one of which 
I have fixed. YAMLParser.h had a protected operator delete() with a trivial 
definition that I converted to be a deleted function in r248320. This was a 
borderline false positive -- the code was correct because the body of operator 
delete() was trivial. However, defining the function as deleted is cleaner 
since accidental deletion from within Node or one of its subclasses will now be 
diagnosed instead of silently accepted and doing nothing. The other is a true 
positive as best I can tell. The MDNode class in Metadata.h defines a placement 
new operator, a free store operator delete(), and two placement delete 
functions. The free store operator delete() has no matching free store operator 
new() (including when looking in super classes), but the implementation does 
not appear to trigger undefined behavior -- it just seems like a really 
confused design (which is mitigated by the fact that the free store delete is 
protected). Also, one of the placement delete functions is not required by std, 
as the comments suggest, and should be removed.

~Aaron

http://reviews.llvm.org/D13071

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/NewDeleteOverloadsCheck.cpp
  clang-tidy/misc/NewDeleteOverloadsCheck.h
  test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp
  test/clang-tidy/misc-new-delete-overloads.cpp

Index: test/clang-tidy/misc-new-delete-overloads.cpp
===
--- test/clang-tidy/misc-new-delete-overloads.cpp
+++ test/clang-tidy/misc-new-delete-overloads.cpp
@@ -0,0 +1,68 @@
+// RUN: %python %S/check_clang_tidy.py %s misc-new-delete-overloads %t -- -std=c++14
+
+typedef unsigned int size_t;
+
+struct S {
+  // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope
+  void *operator new(size_t size) noexcept;
+  // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new[]' has no matching declaration of 'operator delete[]' at the same scope
+  void *operator new[](size_t size) noexcept;
+};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:7: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope
+void *operator new(size_t size) noexcept;
+
+struct T {
+  // Sized deallocations are not enabled by default, and so this new/delete pair
+  // does not match. However, we expect only one warning, for the new, because
+  // the operator delete is a placement delete and we do not warn on mismatching
+  // placement operations.
+  // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' has no matching declaration of 'operator delete' at the same scope
+  void *operator new(size_t size) noexcept;
+  void operator delete(void *ptr, size_t) noexcept; // ok only if sized deallocation is enabled
+};
+
+struct U {
+  void *operator new(size_t size) noexcept;
+  void operator delete(void *ptr) noexcept;
+
+  void *operator new[](size_t) noexcept;
+  void operator delete[](void *) noexcept;
+};
+
+struct Z {
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: declaration of 'operator delete' has no matching declaration of 'operator new' at the same scope
+  void operator delete(void *ptr) noexcept;
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: declaration of 'operator delete[]' has no matching declaration of 'operator new[]' at the same scope
+  void operator delete[](void *ptr) noexcept;
+};
+
+struct A {
+  void *operator new(size_t size, Z) noexcept; // ok, placement new
+};
+
+struct B {
+  void operator delete(void *ptr, A) noexcept; // ok, placement delete
+};
+
+// It is okay to have a class with an inaccessible free store operator.
+struct C {
+  void *operator new(size_t, A) noexcept; // ok, placement new
+private:
+  void operator delete(void *) noexcept;
+};
+
+// It is also okay to have a class with a delete free store operator.
+struct D {

Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread Dimitry Andric via cfe-commits
dim added a comment.

In http://reviews.llvm.org/D13051#250921, @jroelofs wrote:

> In http://reviews.llvm.org/D13051#250910, @EricWF wrote:
>
> > @jroelofs @dim, could we fallback to the __sync_* builtins on arm?
>


The actual implementations of these __sync builtins should still come from 
somewhere, as they will also be libcalls, right?

> @dim would need armv4-flavored implementations of them in compiler-rt (if 
> that's what he's using)... the existing ones use instructions that v4 doesn't 
> have.


Andrew Turner, a fellow FreeBSD developer, has added them pretty quickly, in 
https://svnweb.freebsd.org/base?view=revision&revision=288125.  So I have now 
reverted the ugly workaround in FreeBSD that disabled 
_LIBCPP_HAS_ATOMIC_BUILTINS for arm < v6.


http://reviews.llvm.org/D13051



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


Re: [PATCH] D13013: [ARM] Fix crash "-target arm -mcpu=generic", without "-march="

2015-09-22 Thread Renato Golin via cfe-commits
rengolin accepted this revision.
rengolin added a comment.
This revision is now accepted and ready to land.

Apart from the style nitpick, LGTM. Thanks!



Comment at: lib/Driver/Tools.cpp:6139
@@ +6138,3 @@
+  ArchKind = llvm::ARM::parseCPUArch(Triple.getARMCPUForArch(Arch));
+  } else
+ArchKind = llvm::ARM::parseCPUArch(CPU);

Please, add curly brackets here for the else case.


Repository:
  rL LLVM

http://reviews.llvm.org/D13013



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


Re: [PATCH] D12840: [cfe-dev] Enabling ThreadSanitizer on PPC64(BE/LE) plarforms

2015-09-22 Thread hfin...@anl.gov via cfe-commits
hfinkel added a subscriber: hfinkel.
hfinkel accepted this revision.
hfinkel added a reviewer: hfinkel.
hfinkel added a comment.
This revision is now accepted and ready to land.

LGTM, although don't commit until any necessary backend/compiler-rt patches are 
in.


http://reviews.llvm.org/D12840



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


[libcxx] r248329 - Fix Typo in GCC no RTTI detection. Fixes PR#24901. Thanks to Bernhard Rosenkraenzer for the report and the patch.

2015-09-22 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Tue Sep 22 16:58:30 2015
New Revision: 248329

URL: http://llvm.org/viewvc/llvm-project?rev=248329&view=rev
Log:
Fix Typo in GCC no RTTI detection. Fixes PR#24901. Thanks to Bernhard 
Rosenkraenzer for the report and the patch.

Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=248329&r1=248328&r2=248329&view=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Tue Sep 22 16:58:30 2015
@@ -744,7 +744,7 @@ extern "C" void __sanitizer_annotate_con
 // g++ and cl.exe have RTTI on by default and define a macro when it is.
 // g++ only defines the macro in 4.3.2 and onwards.
 #if !defined(_LIBCPP_NO_RTTI)
-#  if defined(__GNUG__) && ((__GNUC__ >= 5) || (__GNUC__ == 4 && \
+#  if defined(__GNUC__) && ((__GNUC__ >= 5) || (__GNUC__ == 4 && \
(__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2))) && !defined(__GXX_RTTI)
 #define _LIBCPP_NO_RTTI
 #  elif (defined(_MSC_VER) && !defined(__clang__)) && !defined(_CPPRTTI)


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


Re: r248234 - ms Intrin.h: Fix __movsw's and __stosw's inline asm.

2015-09-22 Thread Renato Golin via cfe-commits
On 21 September 2015 at 17:46, Nico Weber via cfe-commits
 wrote:
> Author: nico
> Date: Mon Sep 21 19:46:21 2015
> New Revision: 248234
>
> URL: http://llvm.org/viewvc/llvm-project?rev=248234&view=rev
> Log:
> ms Intrin.h: Fix __movsw's and __stosw's inline asm.

Hi Nico,

This still seems to be breaking our bots:

http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/6583

Please have a look, or revert.

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


Re: [PATCH] D12251: Analyzer: Calculate field offset correctly

2015-09-22 Thread Ismail Pazarbasi via cfe-commits
ismailp added a comment.

Ping!


http://reviews.llvm.org/D12251



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


r248336 - [analyzer] Make realloc(ptr, 0) handling equivalent to malloc(0).

2015-09-22 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Tue Sep 22 17:47:14 2015
New Revision: 248336

URL: http://llvm.org/viewvc/llvm-project?rev=248336&view=rev
Log:
[analyzer] Make realloc(ptr, 0) handling equivalent to malloc(0).

Currently realloc(ptr, 0) is treated as free() which seems to be not correct. C
standard (N1570) establishes equivalent behavior for malloc(0) and realloc(ptr,
0): "7.22.3 Memory management functions calloc, malloc, realloc: If the size of
the space requested is zero, the behavior is implementation-defined: either a
null pointer is  returned, or the behavior is as if the size were some nonzero
value, except that the returned pointer shall not be used to access an object."
The patch equalizes the processing of malloc(0) and realloc(ptr,0). The patch
also enables unix.Malloc checker to detect references to zero-allocated memory
returned by realloc(ptr,0) ("Use of zero-allocated memory" warning).

A patch by Антон Ярцев!

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/test/Analysis/malloc.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=248336&r1=248335&r2=248336&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Tue Sep 22 17:47:14 
2015
@@ -508,6 +508,7 @@ private:
 
 REGISTER_MAP_WITH_PROGRAMSTATE(RegionState, SymbolRef, RefState)
 REGISTER_MAP_WITH_PROGRAMSTATE(ReallocPairs, SymbolRef, ReallocPair)
+REGISTER_SET_WITH_PROGRAMSTATE(ReallocSizeZeroSymbols, SymbolRef)
 
 // A map from the freed symbol to the symbol representing the return value of
 // the free function.
@@ -891,15 +892,19 @@ ProgramStateRef MallocChecker::ProcessZe
   return State;
 
 const RefState *RS = State->get(Sym);
-if (!RS)
-  return State; // TODO: change to assert(RS); after realloc() will
-// guarantee have a RegionState attached.
-
-if (!RS->isAllocated())
-  return State;
-
-return TrueState->set(Sym,
-   RefState::getAllocatedOfSizeZero(RS));
+if (RS) {
+  if (RS->isAllocated())
+return TrueState->set(Sym,
+  
RefState::getAllocatedOfSizeZero(RS));
+  else
+return State;
+} else {
+  // Case of zero-size realloc. Historically 'realloc(ptr, 0)' is treated 
as
+  // 'free(ptr)' and the returned value from 'realloc(ptr, 0)' is not
+  // tracked. Add zero-reallocated Sym to the state to catch references
+  // to zero-allocated memory.
+  return TrueState->add(Sym);
+}
   }
 
   // Assume the value is non-zero going forward.
@@ -1487,6 +1492,9 @@ MallocChecker::getCheckIfTracked(Checker
 Optional
 MallocChecker::getCheckIfTracked(CheckerContext &C, SymbolRef Sym,
  bool IsALeakCheck) const {
+  if (C.getState()->contains(Sym))
+return CK_MallocChecker;
+
   const RefState *RS = C.getState()->get(Sym);
   assert(RS);
   return getCheckIfTracked(RS->getAllocationFamily(), IsALeakCheck);
@@ -1929,7 +1937,7 @@ ProgramStateRef MallocChecker::ReallocMe
   }
 
   if (PrtIsNull && SizeIsZero)
-return nullptr;
+return State;
 
   // Get the from and to pointer symbols as in toPtr = realloc(fromPtr, size).
   assert(!PrtIsNull);
@@ -2293,10 +2301,14 @@ bool MallocChecker::checkUseAfterFree(Sy
 void MallocChecker::checkUseZeroAllocated(SymbolRef Sym, CheckerContext &C,
   const Stmt *S) const {
   assert(Sym);
-  const RefState *RS = C.getState()->get(Sym);
 
-  if (RS && RS->isAllocatedOfSizeZero())
-ReportUseZeroAllocated(C, RS->getStmt()->getSourceRange(), Sym);
+  if (const RefState *RS = C.getState()->get(Sym)) {
+if (RS->isAllocatedOfSizeZero())
+  ReportUseZeroAllocated(C, RS->getStmt()->getSourceRange(), Sym);
+  }
+  else if (C.getState()->contains(Sym)) {
+ReportUseZeroAllocated(C, S->getSourceRange(), Sym);
+  }
 }
 
 bool MallocChecker::checkDoubleDelete(SymbolRef Sym, CheckerContext &C) const {

Modified: cfe/trunk/test/Analysis/malloc.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.c?rev=248336&r1=248335&r2=248336&view=diff
==
--- cfe/trunk/test/Analysis/malloc.c (original)
+++ cfe/trunk/test/Analysis/malloc.c Tue Sep 22 17:47:14 2015
@@ -263,21 +263,21 @@ void CheckUseZeroAllocated6() {
 
 void CheckUseZeroAllocated7() {
   int *p = realloc(0, 0);
-  *p = 1; //TODO: warn about use of zero-allocated memory
+  *p = 1; // expected-warning {{Use of zero-allocated memory}}
   free(p);
 }
 
 void CheckUseZeroAllocated8() {
   int *p = malloc(8);
   int *q = realloc(p, 0);
-  *q = 1; //

Re: [PATCH] D9040: [analyzer] Make realloc(ptr, 0) handling equivalent to malloc(0).

2015-09-22 Thread Devin Coughlin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL248336: [analyzer] Make realloc(ptr, 0) handling equivalent 
to malloc(0). (authored by dcoughlin).

Changed prior to commit:
  http://reviews.llvm.org/D9040?vs=34583&id=35432#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D9040

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  cfe/trunk/test/Analysis/malloc.c

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -508,6 +508,7 @@
 
 REGISTER_MAP_WITH_PROGRAMSTATE(RegionState, SymbolRef, RefState)
 REGISTER_MAP_WITH_PROGRAMSTATE(ReallocPairs, SymbolRef, ReallocPair)
+REGISTER_SET_WITH_PROGRAMSTATE(ReallocSizeZeroSymbols, SymbolRef)
 
 // A map from the freed symbol to the symbol representing the return value of
 // the free function.
@@ -891,15 +892,19 @@
   return State;
 
 const RefState *RS = State->get(Sym);
-if (!RS)
-  return State; // TODO: change to assert(RS); after realloc() will
-// guarantee have a RegionState attached.
-
-if (!RS->isAllocated())
-  return State;
-
-return TrueState->set(Sym,
-   RefState::getAllocatedOfSizeZero(RS));
+if (RS) {
+  if (RS->isAllocated())
+return TrueState->set(Sym,
+  RefState::getAllocatedOfSizeZero(RS));
+  else
+return State;
+} else {
+  // Case of zero-size realloc. Historically 'realloc(ptr, 0)' is treated as
+  // 'free(ptr)' and the returned value from 'realloc(ptr, 0)' is not
+  // tracked. Add zero-reallocated Sym to the state to catch references
+  // to zero-allocated memory.
+  return TrueState->add(Sym);
+}
   }
 
   // Assume the value is non-zero going forward.
@@ -1487,6 +1492,9 @@
 Optional
 MallocChecker::getCheckIfTracked(CheckerContext &C, SymbolRef Sym,
  bool IsALeakCheck) const {
+  if (C.getState()->contains(Sym))
+return CK_MallocChecker;
+
   const RefState *RS = C.getState()->get(Sym);
   assert(RS);
   return getCheckIfTracked(RS->getAllocationFamily(), IsALeakCheck);
@@ -1929,7 +1937,7 @@
   }
 
   if (PrtIsNull && SizeIsZero)
-return nullptr;
+return State;
 
   // Get the from and to pointer symbols as in toPtr = realloc(fromPtr, size).
   assert(!PrtIsNull);
@@ -2293,10 +2301,14 @@
 void MallocChecker::checkUseZeroAllocated(SymbolRef Sym, CheckerContext &C,
   const Stmt *S) const {
   assert(Sym);
-  const RefState *RS = C.getState()->get(Sym);
 
-  if (RS && RS->isAllocatedOfSizeZero())
-ReportUseZeroAllocated(C, RS->getStmt()->getSourceRange(), Sym);
+  if (const RefState *RS = C.getState()->get(Sym)) {
+if (RS->isAllocatedOfSizeZero())
+  ReportUseZeroAllocated(C, RS->getStmt()->getSourceRange(), Sym);
+  }
+  else if (C.getState()->contains(Sym)) {
+ReportUseZeroAllocated(C, S->getSourceRange(), Sym);
+  }
 }
 
 bool MallocChecker::checkDoubleDelete(SymbolRef Sym, CheckerContext &C) const {
Index: cfe/trunk/test/Analysis/malloc.c
===
--- cfe/trunk/test/Analysis/malloc.c
+++ cfe/trunk/test/Analysis/malloc.c
@@ -263,21 +263,21 @@
 
 void CheckUseZeroAllocated7() {
   int *p = realloc(0, 0);
-  *p = 1; //TODO: warn about use of zero-allocated memory
+  *p = 1; // expected-warning {{Use of zero-allocated memory}}
   free(p);
 }
 
 void CheckUseZeroAllocated8() {
   int *p = malloc(8);
   int *q = realloc(p, 0);
-  *q = 1; //TODO: warn about use of zero-allocated memory
+  *q = 1; // expected-warning {{Use of zero-allocated memory}}
   free(q);
 }
 
 void CheckUseZeroAllocated9() {
   int *p = realloc(0, 0);
   int *q = realloc(p, 0);
-  *q = 1; //TODO: warn about use of zero-allocated memory
+  *q = 1; // expected-warning {{Use of zero-allocated memory}}
   free(q);
 }
 
@@ -307,6 +307,34 @@
   free(p);
 }
 
+void CheckUseZeroReallocatedPathNoWarn(_Bool b) {
+  int s = 0;
+  if (b)
+s= 10;
+
+  char *p = malloc(8);
+  char *q = realloc(p, s);
+
+  if (b)
+*q = 1; // no warning
+
+  free(q);
+}
+
+void CheckUseZeroReallocatedPathWarn(_Bool b) {
+  int s = 10;
+  if (b)
+s= 0;
+
+  char *p = malloc(8);
+  char *q = realloc(p, s);
+
+  if (b)
+*q = 1; // expected-warning {{Use of zero-allocated memory}}
+
+  free(q);
+}
+
 // This case tests that storing malloc'ed memory to a static variable which is
 // then returned is not leaked.  In the absence of known contracts for functions
 // or inter-procedural analysis, this is a conservative answer.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r248345 - Module Debugging: Use the clang module signature as the module's dwo_id

2015-09-22 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Tue Sep 22 18:26:43 2015
New Revision: 248345

URL: http://llvm.org/viewvc/llvm-project?rev=248345&view=rev
Log:
Module Debugging: Use the clang module signature as the module's dwo_id
when building a module. Clang already records the module signature when
building a skeleton CU to reference a clang module.

Matching the id in the skeleton with the one in the module allows a DWARF
consumer to verify that they found the correct version of the module
without them needing to know about the clang module format.

Modified:
cfe/trunk/include/clang/Frontend/PCHContainerOperations.h
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
cfe/trunk/lib/Serialization/GeneratePCH.cpp
cfe/trunk/test/Modules/DebugInfoTransitiveImport.m
cfe/trunk/test/Modules/ModuleDebugInfo.cpp
cfe/trunk/test/Modules/ModuleDebugInfo.m

Modified: cfe/trunk/include/clang/Frontend/PCHContainerOperations.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHContainerOperations.h?rev=248345&r1=248344&r2=248345&view=diff
==
--- cfe/trunk/include/clang/Frontend/PCHContainerOperations.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHContainerOperations.h Tue Sep 22 
18:26:43 2015
@@ -30,8 +30,9 @@ class DiagnosticsEngine;
 class CompilerInstance;
 
 struct PCHBuffer {
-  bool IsComplete;
+  uint64_t Signature;
   llvm::SmallVector Data;
+  bool IsComplete;
 };
   
 /// This abstract interface provides operations for creating

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=248345&r1=248344&r2=248345&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Sep 22 18:26:43 2015
@@ -3453,6 +3453,12 @@ CGDebugInfo::getOrCreateNameSpace(const
   return NS;
 }
 
+void CGDebugInfo::setDwoId(uint64_t Signature) {
+  assert(TheCU && "no main compile unit");
+  TheCU->setDWOId(Signature);
+}
+
+
 void CGDebugInfo::finalize() {
   // Creating types might create further types - invalidating the current
   // element and the size(), so don't cache/reference them.

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=248345&r1=248344&r2=248345&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue Sep 22 18:26:43 2015
@@ -276,6 +276,9 @@ public:
 
   void finalize();
 
+  /// Set the main CU's DwoId field to \p Signature.
+  void setDwoId(uint64_t Signature);
+
   /// When generating debug information for a clang module or
   /// precompiled header, this module map will be used to determine
   /// the module of origin of each Decl.

Modified: cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp?rev=248345&r1=248344&r2=248345&view=diff
==
--- cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp (original)
+++ cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp Tue Sep 22 
18:26:43 2015
@@ -142,7 +142,6 @@ public:
 CodeGenOpts.ThreadModel = "single";
 CodeGenOpts.DebugTypeExtRefs = true;
 CodeGenOpts.setDebugInfo(CodeGenOptions::FullDebugInfo);
-CodeGenOpts.SplitDwarfFile = OutputFileName;
   }
 
   ~PCHContainerGenerator() override = default;
@@ -201,6 +200,7 @@ public:
 
 M->setTargetTriple(Ctx.getTargetInfo().getTriple().getTriple());
 M->setDataLayout(Ctx.getTargetInfo().getDataLayoutString());
+Builder->getModuleDebugInfo()->setDwoId(Buffer->Signature);
 
 // Finalize the Builder.
 if (Builder)

Modified: cfe/trunk/lib/Serialization/GeneratePCH.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/GeneratePCH.cpp?rev=248345&r1=248344&r2=248345&view=diff
==
--- cfe/trunk/lib/Serialization/GeneratePCH.cpp (original)
+++ cfe/trunk/lib/Serialization/GeneratePCH.cpp Tue Sep 22 18:26:43 2015
@@ -48,7 +48,8 @@ void PCHGenerator::HandleTranslationUnit
 
   // Emit the PCH file to the Buffer.
   assert(SemaPtr && "No Sema?");
-  Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, hasErrors);
+  Buffer->Signature =
+  Writer.WriteAST(*SemaPtr, OutputFile, Module, isysroot, hasErrors);
 
   Buffer->IsComplete = true;
 }

Modified: cfe/trunk/test/Modules/DebugInfoTransitiveImport.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/DebugInfoTransitiveImport.m?rev=248345&r1=248344&

r248344 - Serialization: Let ASTWriter return the signature of the written module.

2015-09-22 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Tue Sep 22 18:26:31 2015
New Revision: 248344

URL: http://llvm.org/viewvc/llvm-project?rev=248344&view=rev
Log:
Serialization: Let ASTWriter return the signature of the written module.

NFC

Modified:
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=248344&r1=248343&r2=248344&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Tue Sep 22 18:26:31 2015
@@ -505,10 +505,9 @@ private:
 llvm::DenseSet &ParentStmts);
 
   void WriteBlockInfoBlock();
-  void WriteControlBlock(Preprocessor &PP, ASTContext &Context,
- StringRef isysroot, const std::string &OutputFile);
-  void WriteInputFiles(SourceManager &SourceMgr,
-   HeaderSearchOptions &HSOpts,
+  uint64_t WriteControlBlock(Preprocessor &PP, ASTContext &Context,
+ StringRef isysroot, const std::string 
&OutputFile);
+  void WriteInputFiles(SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
bool Modules);
   void WriteSourceManagerBlock(SourceManager &SourceMgr,
const Preprocessor &PP);
@@ -572,9 +571,9 @@ private:
   void WriteDecl(ASTContext &Context, Decl *D);
   void AddFunctionDefinition(const FunctionDecl *FD, RecordData &Record);
 
-  void WriteASTCore(Sema &SemaRef,
-StringRef isysroot, const std::string &OutputFile,
-Module *WritingModule);
+  uint64_t WriteASTCore(Sema &SemaRef,
+StringRef isysroot, const std::string &OutputFile,
+Module *WritingModule);
 
 public:
   /// \brief Create a new precompiled header writer that outputs to
@@ -600,10 +599,12 @@ public:
   /// \param isysroot if non-empty, write a relocatable file whose headers
   /// are relative to the given system root. If we're writing a module, its
   /// build directory will be used in preference to this if both are available.
-  void WriteAST(Sema &SemaRef,
-const std::string &OutputFile,
-Module *WritingModule, StringRef isysroot,
-bool hasErrors = false);
+  ///
+  /// \return the module signature, which eventually will be a hash of
+  /// the module but currently is merely a random 32-bit number.
+  uint64_t WriteAST(Sema &SemaRef, const std::string &OutputFile,
+Module *WritingModule, StringRef isysroot,
+bool hasErrors = false);
 
   /// \brief Emit a token.
   void AddToken(const Token &Tok, RecordDataImpl &Record);

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=248344&r1=248343&r2=248344&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Sep 22 18:26:31 2015
@@ -1166,9 +1166,12 @@ static ASTFileSignature getSignature() {
 }
 
 /// \brief Write the control block.
-void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
-  StringRef isysroot,
-  const std::string &OutputFile) {
+uint64_t ASTWriter::WriteControlBlock(Preprocessor &PP,
+  ASTContext &Context,
+  StringRef isysroot,
+  const std::string &OutputFile) {
+  ASTFileSignature Signature = 0;
+
   using namespace llvm;
   Stream.EnterSubblock(CONTROL_BLOCK_ID, 5);
   RecordData Record;
@@ -1201,7 +1204,8 @@ void ASTWriter::WriteControlBlock(Prepro
 // is non-deterministic.
 // FIXME: Remove this when output is deterministic.
 if (Context.getLangOpts().ImplicitModules) {
-  RecordData::value_type Record[] = {getSignature()};
+  Signature = getSignature();
+  RecordData::value_type Record[] = {Signature};
   Stream.EmitRecord(SIGNATURE, Record);
 }
 
@@ -1468,6 +1472,7 @@ void ASTWriter::WriteControlBlock(Prepro
   PP.getHeaderSearchInfo().getHeaderSearchOpts(),
   PP.getLangOpts().Modules);
   Stream.ExitBlock();
+  return Signature;
 }
 
 namespace  {
@@ -4012,12 +4017,11 @@ time_t ASTWriter::getTimestampForOutput(
   return IncludeTimestamps ? E->getModificationTime() : 0;
 }
 
-void ASTWriter::WriteAST(Sema &SemaRef,
- const std::string &OutputFile,
- Module *WritingModule, StringRef isysroot,
- bool hasErrors) {
+uint64_t ASTWriter::WriteAST(Sema &SemaRef, const std:

  1   2   >