Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-06 Thread Joerg Sonnenberger via cfe-commits
On Tue, Apr 05, 2016 at 05:27:45PM +, Ben Craig via cfe-commits wrote:
> bcraig added a subscriber: bcraig.
> bcraig added a comment.
> 
> Is this checker able to connect a std::string with a pre-declared string 
> literal (i.e. constant propagation)?  For example...
> 
>   const char *bad_chars = "\0\1\2\3";
>   std::string bad_str = bad_chars;
> 
> I've had real code make that mistake before.

In that case, it would be nice if it also handles the correct pattern
of:

const char bad_chars[] = "\0\1\2\3";
std::string bad_str(bad_chars, sizeof bad_chars);

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


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

2016-04-06 Thread Andrey Bokhanko via cfe-commits
andreybokhanko added a comment.

In http://reviews.llvm.org/D18596#392341, @majnemer wrote:

> In http://reviews.llvm.org/D18596#392098, @andreybokhanko wrote:
>
> > Do we want to do this for an ignored qualifier? I don't see any practical 
> > purpose.
>
>
> It's not ignored for Windows on ARM.


Hmmm... MS documentation 
 explicitly mentions 
IPF only:

> When you declare a pointer with the __unaligned modifier, the compiler 
> assumes that the pointer addresses data that is not aligned. Consequently, 
> for an application that targets an Itanium Processor Family (IPF) computer, 
> the compiler generates code that reads the unaligned data one byte at a time.


OK, I will implement _unaligned as a qualifier, if you think this is the right 
way to go. Note, though, that it will remain ignored, as there is no support 
for _unaligned in LLVM IR.

Andrey


http://reviews.llvm.org/D18596



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


Re: [PATCH] D18713: [OpenCL] Generate bitcast when target address space does not change.

2016-04-06 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: test/CodeGenOpenCL/address-spaces-conversions.cl:11
@@ -8,2 +10,3 @@
   arg_gen = arg_glob; // implicit cast global -> generic
   // CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 
addrspace(4)*
+

Would it make sense to check here and below for NOFAKE too? Basically to check 
that there is no addrspacecast generated?


http://reviews.llvm.org/D18713



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


Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-06 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

So the testing on llvm shows mostly one case - using DEBUG macro like this:

/home/prazek/llvm/lib/Support/APInt.cpp:1656:9: warning: implicitly converting 
integer literal to bool inside macro, use bool literal instead 
[modernize-use-bool-literals]

  DEBUG(dbgs() << " " << r[i]);
  ^

/home/prazek/llvm/include/llvm/Support/Debug.h:92:18: note: expanded from macro 
'DEBUG'
#define DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)

  ^

/home/prazek/llvm/include/llvm/Support/Debug.h:69:48: note: expanded from macro 
'DEBUG_WITH_TYPE'
#define DEBUG_WITH_TYPE(TYPE, X) do { } while (0)

   ^

Some programers maybe would like to supress this in the case of expressions 
like while(1), or specially when it is inside macro. 
What do you think guys? Should we add some special option like 
supress-for-while or supress-macro-while?


http://reviews.llvm.org/D18745



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


[PATCH] D18821: Add modernize-bool-to-integer-conversion

2016-04-06 Thread Piotr Padlewski via cfe-commits
Prazek created this revision.
Prazek added reviewers: alexfh, staronj.
Prazek added a subscriber: cfe-commits.
Herald added a subscriber: joker.eph.

Tested on llvm codebase.
It have found many places like: 
- returning true/false in function returning int,
- assigning true/false to integer inside some classes.

http://reviews.llvm.org/D18821

Files:
  clang-tidy/modernize/BoolToIntegerConversionCheck.cpp
  clang-tidy/modernize/BoolToIntegerConversionCheck.h
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
  test/clang-tidy/modernize-bool-to-integer-conversion.cpp

Index: test/clang-tidy/modernize-bool-to-integer-conversion.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-bool-to-integer-conversion.cpp
@@ -0,0 +1,40 @@
+// RUN: %check_clang_tidy %s modernize-bool-to-integer-conversion %t
+
+int is42Answer = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicitly converting bool literal to integer. Use integer literal instead [modernize-bool-to-integer-conversion]
+// CHECK-FIXES: int is42Answer = 1;{{$}}
+
+int noItsNot = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: implicitly {{..}}
+// CHECK-FIXES: int noItsNot = 0;{{$}}
+int a = 42;
+int az = a;
+
+long long ll = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: implicitly {{..}}
+// CHECK-FIXES: long long ll = 1;{{$}}
+
+void fun(int) {}
+#define ONE true
+
+// No fixup for macros.
+int one = ONE;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicitly converting bool literal to integer inside macro. Use integer literal instead [modernize-bool-to-integer-conversion]
+
+void test() {
+fun(ONE);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: implicitly converting bool {{..}}
+
+fun(42);
+fun(true);
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: implicitly {{..}}
+// CHECK-FIXES: fun(1);{{$}}
+}
+
+char c = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: implicitly {{..}}
+// CHECK-FIXES: char c = 1;
+
+char c2 = 1;
+char c3 = '0';
+bool b = true;
Index: docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - modernize-bool-to-integer-conversion
+
+modernize-bool-to-integer-conversion
+
+
+This check looks for implicit conversion from bool literals to integer types
+
+.. code-block:: C++
+  int a = false
+  vector v(true); // Makes vector of one element
+
+  // Changes it to
+  int a = 0;
+  vector v(1); // Makes vector of one element
+
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
@@ -76,6 +76,7 @@
misc-unused-parameters
misc-unused-raii
misc-virtual-near-miss
+   modernize-bool-to-integer-conversion
modernize-deprecated-headers
modernize-loop-convert
modernize-make-unique
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
 
   Replaces C standard library headers with their C++ alternatives.
 
+- New `modernize-bool-to-integer-conversion
+  `_ check
+
+  Replaces implicit cast from bool literals to integers to int literals.
+
 - New `modernize-raw-string-literal
   `_ check
 
Index: clang-tidy/modernize/ModernizeTidyModule.cpp
===
--- clang-tidy/modernize/ModernizeTidyModule.cpp
+++ clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "BoolToIntegerConversionCheck.h"
 #include "DeprecatedHeadersCheck.h"
 #include "LoopConvertCheck.h"
 #include "MakeUniqueCheck.h"
@@ -32,6 +33,8 @@
 class ModernizeModule : public ClangTidyModule {
 pu

Re: [PATCH] D18265: [clang-tidy] New: checker misc-assign-operator-return

2016-04-06 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware added inline comments.


Comment at: clang-tidy/misc/AssignOperatorCheck.cpp:63
@@ +62,3 @@
+
+  Finder->addMatcher(returnStmt(IsBadReturnStatement, 
hasAncestor(IsGoodAssign))
+ .bind("returnStmt"),

sbenza wrote:
> baloghadamsoftware wrote:
> > sbenza wrote:
> > > I dislike these uses of hasAnscestor. They are kind of slow.
> > > But more importantly, they break with nested functions/types.
> > > This particular example is not checking that the return statement is from 
> > > the assignment operator, only that it is within it. For example, it would 
> > > match a lambda.
> > > I think this would trip the check:
> > > 
> > > F& operator=(const F& o) {
> > >   std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; 
> > > });
> > >   return *this;
> > > }
> > I can change it to hasDescendant if it is faster, but it does not solve the 
> > lambda problem. No solution for that comes to my mind with the existing 
> > matchers. Maybe a new matcher hasDescendantStatement could help which only 
> > traverses statements down the AST. Is this the right way to go?
> hasDescendant has the same problem has hasAnscestor.
> I think the best is to write a matcher like:
> 
> AST_MATCHER_P(ReturnStmt, forFunction, internal::Matcher, 
> InnerMatcher) {
>   ...
> }
> 
> In there we can find the right FunctionDecl that encloses the return 
> statement and apply the matcher.
> This matcher seems like a good candidate to add to ASTMatchers.h
Maybe I am wrong, but your proposal also seems a bottom-up matcher which is 
slow. That is the reason I proposed a top-down matcher, e.g. 
hasDescendantStatement or something like this which is top-down and only 
traverses statements so it does not search in a lambda which is a declaration.


http://reviews.llvm.org/D18265



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


r265530 - [OPENMP] Parsing and Sema support for 'omp declare target' directive

2016-04-06 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Wed Apr  6 06:38:59 2016
New Revision: 265530

URL: http://llvm.org/viewvc/llvm-project?rev=265530&view=rev
Log:
[OPENMP] Parsing and Sema support for 'omp declare target' directive

Add parsing, sema analysis for 'declare target' construct for OpenMP 4.0
(4.5 support will be added in separate patch).

The declare target directive specifies that variables, functions (C, C++
and Fortran), and subroutines (Fortran) are mapped to a device. The declare
target directive is a declarative directive. In Clang declare target is
implemented as implicit attribute for the declaration.

The syntax of the declare target directive is as follows:

 #pragma omp declare target
 declarations-definition-seq
 #pragma omp end declare target

Based on patch from Michael Wong http://reviews.llvm.org/D15321

Added:
cfe/trunk/test/OpenMP/declare_target_ast_print.cpp   (with props)
cfe/trunk/test/OpenMP/declare_target_messages.cpp   (with props)
Modified:
cfe/trunk/include/clang/AST/ASTMutationListener.h
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTCommon.h
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=265530&r1=265529&r2=265530&view=diff
==
--- cfe/trunk/include/clang/AST/ASTMutationListener.h (original)
+++ cfe/trunk/include/clang/AST/ASTMutationListener.h Wed Apr  6 06:38:59 2016
@@ -107,6 +107,12 @@ public:
   /// \param D the declaration marked OpenMP threadprivate.
   virtual void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) {}
 
+  /// \brief A declaration is marked as OpenMP declaretarget which was not
+  /// previously marked as declaretarget.
+  ///
+  /// \param D the declaration marked OpenMP declaretarget.
+  virtual void DeclarationMarkedOpenMPDeclareTarget(const Decl *D) {}
+
   /// \brief A definition has been made visible by being redefined locally.
   ///
   /// \param D The definition that was previously not visible.

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=265530&r1=265529&r2=265530&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Apr  6 06:38:59 2016
@@ -2276,6 +2276,15 @@ def OMPDeclareSimdDecl : Attr {
   }];
 }
 
+def OMPDeclareTargetDecl : Attr {
+  let Spellings = [Pragma<"omp", "declare target">];
+  let SemaHandler = 0;
+  let Documentation = [OMPDeclareTargetDocs];
+  let AdditionalMembers = [{
+void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) 
const {}
+  }];
+}
+
 def InternalLinkage : InheritableAttr {
   let Spellings = [GNU<"internal_linkage">, CXX11<"clang", 
"internal_linkage">];
   let Subjects = SubjectList<[Var, Function, CXXRecord]>;

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=265530&r1=265529&r2=265530&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed Apr  6 06:38:59 2016
@@ -1941,6 +1941,23 @@ where clause is one of the following:
   }];
 }
 
+def OMPDeclareTargetDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "#pragma omp declare target";
+  let Content = [{
+The `declare target` directive specifies that variables and functions are 
mapped
+to a device for OpenMP offload mechanism.
+
+The syntax of the declare target directive is as follows:
+
+  .. code-block:: c
+
+  #pragma omp declare target new-line
+  declarations-definition-seq
+  #pragma omp end declare target new-line
+  }];
+}
+
 def NotTailCalledDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Dia

Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

2016-04-06 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin closed this revision.
DmitryPolukhin added a comment.

Committed as http://reviews.llvm.org/rL265530


http://reviews.llvm.org/D18542



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


[clang-tools-extra] r265532 - [clang-tidy] Extension of checker misc-misplaced-widening-cast

2016-04-06 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Wed Apr  6 07:04:51 2016
New Revision: 265532

URL: http://llvm.org/viewvc/llvm-project?rev=265532&view=rev
Log:
[clang-tidy] Extension of checker misc-misplaced-widening-cast

Summary:
Existing checker misc-misplaced-widening-cast was extended:
- New use cases: casted expression as lhs or rhs of a logical comparison or 
function argument
- New types: beside int, long and long long various char types, short and 
int128 added
- New option to check implicit casts: forgetting a cast is at least as common 
and as dangerous as misplacing it. This option can be disabled.

This patch depends on AST Matcher patches D17986 and D18243 and also contains 
fix for checker misc-bool-pointer-implicit-conversion needed because of the fix 
in the AST Matcher patch.

Reviewers: hokein, alexfh

Subscribers: o.gyorgy, xazax.hun, cfe-commits

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

Added:

clang-tools-extra/trunk/test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
Modified:

clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-misplaced-widening-cast.rst
clang-tools-extra/trunk/test/clang-tidy/misc-misplaced-widening-cast.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp?rev=265532&r1=265531&r2=265532&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversionCheck.cpp 
Wed Apr  6 07:04:51 2016
@@ -61,7 +61,8 @@ void BoolPointerImplicitConversionCheck:
  *Result.Context).empty() ||
   // FIXME: We should still warn if the paremater is implicitly converted 
to
   // bool.
-  !match(findAll(callExpr(hasAnyArgument(DeclRef))), *If, *Result.Context)
+  !match(findAll(callExpr(hasAnyArgument(ignoringParenImpCasts(DeclRef,
+ *If, *Result.Context)
.empty() ||
   !match(findAll(cxxDeleteExpr(has(expr(DeclRef, *If, *Result.Context)
.empty())

Modified: clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp?rev=265532&r1=265531&r2=265532&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp Wed 
Apr  6 07:04:51 2016
@@ -10,6 +10,7 @@
 #include "MisplacedWideningCastCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/DenseMap.h"
 
 using namespace clang::ast_matchers;
 
@@ -17,6 +18,16 @@ namespace clang {
 namespace tidy {
 namespace misc {
 
+MisplacedWideningCastCheck::MisplacedWideningCastCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  CheckImplicitCasts(Options.get("CheckImplicitCasts", true)) {}
+
+void MisplacedWideningCastCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "CheckImplicitCasts", CheckImplicitCasts);
+}
+
 void MisplacedWideningCastCheck::registerMatchers(MatchFinder *Finder) {
   auto Calc = expr(anyOf(binaryOperator(anyOf(
  hasOperatorName("+"), hasOperatorName("-"),
@@ -25,14 +36,22 @@ void MisplacedWideningCastCheck::registe
hasType(isInteger()))
   .bind("Calc");
 
-  auto Cast = explicitCastExpr(anyOf(cStyleCastExpr(), cxxStaticCastExpr(),
- cxxReinterpretCastExpr()),
-   hasDestinationType(isInteger()), has(Calc))
-  .bind("Cast");
-
-  Finder->addMatcher(varDecl(has(Cast)), this);
-  Finder->addMatcher(returnStmt(has(Cast)), this);
+  auto ExplicitCast =
+  explicitCastExpr(hasDestinationType(isInteger()), has(Calc));
+  auto ImplicitCast =
+  implicitCastExpr(hasImplicitDestinationType(isInteger()), has(Calc));
+  auto Cast = expr(anyOf(ExplicitCast, ImplicitCast)).bind("Cast");
+
+  Finder->addMatcher(varDecl(hasInitializer(Cast)), this);
+  Finder->addMatcher(returnStmt(hasReturnValue(Cast)), this);
+  Finder->addMatcher(callExpr(hasAnyArgument(Cast)), this);
   Finder->addMatcher(binaryOperator(hasOperatorName("="), hasRHS(Cast)), this);
+  Finder->addMatcher(
+  binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!="),
+   hasOperatorNam

Re: [PATCH] D18821: Add modernize-bool-to-integer-conversion

2016-04-06 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

Maybe we should merge it with http://reviews.llvm.org/D18745 and name it 
'modernize-wrong-literal-cast'. The other question is, will it be better to 
move it to readability?


http://reviews.llvm.org/D18821



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


[PATCH] D18823: Implementation of VlA of GNU C++ extension

2016-04-06 Thread Vladimir Yakovlev via cfe-commits
vbyakovl created this revision.
vbyakovl added a reviewer: aaron.s.wishnick.
vbyakovl added subscribers: DmitryPolukhin, cfe-commits.

This implements GNU C++ extension "Variable length array". This works under 
-std=gnu++98.

http://reviews.llvm.org/D18823

Files:
  llvm/tools/clang/lib/CodeGen/CGClass.cpp
  llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp
  llvm/tools/clang/lib/CodeGen/CodeGenFunction.h
  llvm/tools/clang/lib/Sema/SemaType.cpp
  llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp
  llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp
  llvm/tools/clang/test/SemaCXX/vla.cpp

Index: llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp
===
--- llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp
+++ llvm/tools/clang/lib/CodeGen/CGExprCXX.cpp
@@ -472,8 +472,8 @@
 }
   }
   
-  if (const ConstantArrayType *arrayType 
-= getContext().getAsConstantArrayType(E->getType())) {
+  if (const ArrayType *arrayType
+= getContext().getAsArrayType(E->getType())) {
 EmitCXXAggrConstructorCall(CD, arrayType, Dest.getAddress(), E);
   } else {
 CXXCtorType Type = Ctor_Complete;
Index: llvm/tools/clang/lib/CodeGen/CGClass.cpp
===
--- llvm/tools/clang/lib/CodeGen/CGClass.cpp
+++ llvm/tools/clang/lib/CodeGen/CGClass.cpp
@@ -1915,7 +1915,7 @@
 /// \param zeroInitialize true if each element should be
 ///   zero-initialized before it is constructed
 void CodeGenFunction::EmitCXXAggrConstructorCall(
-const CXXConstructorDecl *ctor, const ConstantArrayType *arrayType,
+const CXXConstructorDecl *ctor, const ArrayType *arrayType,
 Address arrayBegin, const CXXConstructExpr *E, bool zeroInitialize) {
   QualType elementType;
   llvm::Value *numElements =
Index: llvm/tools/clang/lib/CodeGen/CodeGenFunction.h
===
--- llvm/tools/clang/lib/CodeGen/CodeGenFunction.h
+++ llvm/tools/clang/lib/CodeGen/CodeGenFunction.h
@@ -1872,7 +1872,7 @@
   const CXXConstructExpr *E);
 
   void EmitCXXAggrConstructorCall(const CXXConstructorDecl *D,
-  const ConstantArrayType *ArrayTy,
+  const ArrayType *ArrayTy,
   Address ArrayPtr,
   const CXXConstructExpr *E,
   bool ZeroInitialization = false);
Index: llvm/tools/clang/lib/Sema/SemaType.cpp
===
--- llvm/tools/clang/lib/Sema/SemaType.cpp
+++ llvm/tools/clang/lib/Sema/SemaType.cpp
@@ -2155,7 +2155,8 @@
   }
   // If this is not C99, extwarn about VLA's and C99 array size modifiers.
   if (!getLangOpts().C99) {
-if (T->isVariableArrayType()) {
+if (T->isVariableArrayType() &&
+!(getLangOpts().CPlusPlus && getLangOpts().GNUMode)) {
   // Prohibit the use of non-POD types in VLAs.
   QualType BaseT = Context.getBaseElementType(T);
   if (!T->isDependentType() && isCompleteType(Loc, BaseT) &&
Index: llvm/tools/clang/test/SemaCXX/vla.cpp
===
--- llvm/tools/clang/test/SemaCXX/vla.cpp
+++ llvm/tools/clang/test/SemaCXX/vla.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -std=c++98 -verify %s
 
 // PR11925
 int n;
Index: llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp
===
--- llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp
+++ llvm/tools/clang/test/SemaCXX/c99-variable-length-array.cpp
@@ -1,4 +1,7 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wvla-extension %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++98 -DCPP98 -verify -Wvla-extension %s
+// RUN: %clang_cc1 -fsyntax-only -std=gnu++98 -DGNU98 -verify -Wvla-extension %s
+
+#ifdef CPP98
 struct NonPOD {
   NonPOD();
 };
@@ -123,16 +126,20 @@
 (void)new vla_type; // expected-error{{variably}}
   }
 }
+#endif // CPP98
 
+#ifdef GNU98 
 namespace rdar8733881 { // rdar://8733881
 
 static const int k_cVal3 = (int)(1000*0.2f);
   int f() {
 // Ok, fold to a constant size array as an extension.
 char rgch[k_cVal3] = {0};
-  }
+  } // expected-warning{{control reaches end of non-void function}}
 }
+#endif // GNU98
 
+#ifdef CPP98
 namespace PR11744 {
   template int f(int n) {
 T arr[3][n]; // expected-warning 3 {{variable length arrays are a C99 feature}}
@@ -161,3 +168,4 @@
 func2();
   }
 }
+#endif // CPP98
Index: llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp
===
--- llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp
+++ llvm/tools/clang/test/CodeGenCXX/vla-consruct.cpp
@@ -0,0 +1,139 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -std=gnu++98 -O0 %s -emit-llvm -o 

Re: [PATCH] D18803: [clang-tidy] fix building clang-tidy documentation.

2016-04-06 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG. Thank you!


http://reviews.llvm.org/D18803



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


Re: [PATCH] D18806: [clang-tidy] filter plugins and plugin arguments of the command-line

2016-04-06 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG in general. A few nits.



Comment at: clang-tidy/ClangTidy.cpp:439
@@ +438,3 @@
+CommandLineArguments AdjustedArgs;
+for (size_t i = 0, e = Args.size(); i != e; ++i) {
+  if (i + 4 < Args.size() &&

Variable names should start with an upper-case character. Also, I prefer `I < 
E` as a loop condition in case of numeric `I` and `E`.


Comment at: clang-tidy/ClangTidy.cpp:441
@@ +440,3 @@
+  if (i + 4 < Args.size() &&
+  Args[i + 0] == "-Xclang" &&
+  (Args[i + 1] == "-load" ||

`i + 0` confuses more than helps, please change to just `i`. 


Comment at: clang-tidy/ClangTidy.cpp:446
@@ +445,3 @@
+  Args[i + 2] == "-Xclang") {
+// skip all arguments.
+i += 3;

The comment doesn't help much. I'd just drop it.


Comment at: clang-tidy/ClangTidy.cpp:448
@@ +447,3 @@
+i += 3;
+  }
+  else AdjustedArgs.push_back(Args[i + 0]);

clang-format -style=llvm (or -style=file), please.


http://reviews.llvm.org/D18806



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


r265540 - clang-format: Fix incorrect function annotation detection.

2016-04-06 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Apr  6 08:58:09 2016
New Revision: 265540

URL: http://llvm.org/viewvc/llvm-project?rev=265540&view=rev
Log:
clang-format: Fix incorrect function annotation detection.

Before:
  MACRO(
  abc).function() // wrap
  << abc;

After:
  MACRO(abc).function() // wrap
  << abc;

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=265540&r1=265539&r2=265540&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Apr  6 08:58:09 2016
@@ -1002,7 +1002,8 @@ private:
 Current.Type = TT_CastRParen;
   if (Current.MatchingParen && Current.Next &&
   !Current.Next->isBinaryOperator() &&
-  !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace))
+  !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
+ tok::period, tok::arrow, tok::coloncolon))
 if (FormatToken *BeforeParen = Current.MatchingParen->Previous)
   if (BeforeParen->is(tok::identifier) &&
   BeforeParen->TokenText == BeforeParen->TokenText.upper() &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=265540&r1=265539&r2=265540&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Apr  6 08:58:09 2016
@@ -3997,6 +3997,12 @@ TEST_F(FormatTest, FunctionAnnotations)
"<< b");
   verifyFormat("TEST_F(ThisIsATestFixture,\n"
"   ThisIsATestWithAReallyReallyReallyReallyLongName) {}");
+  verifyFormat("MACRO(abc).function() // wrap\n"
+   "<< abc;");
+  verifyFormat("MACRO(abc)->function() // wrap\n"
+   "<< abc;");
+  verifyFormat("MACRO(abc)::function() // wrap\n"
+   "<< abc;");
 }
 
 TEST_F(FormatTest, BreaksDesireably) {


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


[clang-tools-extra] r265539 - [clang-tidy] fix building clang-tidy documentation.

2016-04-06 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed Apr  6 08:57:22 2016
New Revision: 265539

URL: http://llvm.org/viewvc/llvm-project?rev=265539&view=rev
Log:
[clang-tidy] fix building clang-tidy documentation.

Summary:
The clang-tidy documentation can't be generated because of broken links.

```
Warning, treated as error:
/home/etienneb/llvm/llvm/tools/clang/tools/extra/docs/clang-tidy/checks/google-readability-function-size.rst::
 WARNING: document isn't included in any toctree
```

Reviewers: alexfh

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=265539&r1=265538&r2=265539&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Wed Apr  6 08:57:22 
2016
@@ -31,9 +31,9 @@ Clang-Tidy Checks
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to 
readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to 
readability-braces-around-statements) 

google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 

+   google-readability-function-size (redirects to readability-function-size) 

google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst?rev=265539&r1=265538&r2=265539&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-static-definition-in-anonymous-namespace.rst
 Wed Apr  6 08:57:22 2016
@@ -9,6 +9,7 @@ In this case, ``static`` is redundant, b
 visibility of definitions to a single translation unit.
 
 .. code:: c++
+
   namespace {
 static int a = 1; // Warning.
 static const b = 1; // Warning.


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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-06 Thread Alexander Kornienko via cfe-commits
alexfh added a comment.

A couple of nits for now. Will take a closer look later.



Comment at: clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp:22
@@ +21,3 @@
+static unsigned int GetCharAt(const StringLiteral *SL, size_t offset) {
+  if (offset >= SL->getLength()) return 0;
+  return SL->getCodeUnit(offset);

Should this be an assert instead?


Comment at: clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp:38
@@ +37,3 @@
+  // The remaining checks only apply to C++.
+  if (!getLangOpts().CPlusPlus) return;
+

clang-format -style=LLVM (or -style=file), please.


http://reviews.llvm.org/D18783



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


[clang-tools-extra] r265542 - [clang-tidy] filter plugins and plugin arguments of the command-line

2016-04-06 Thread Etienne Bergeron via cfe-commits
Author: etienneb
Date: Wed Apr  6 09:07:51 2016
New Revision: 265542

URL: http://llvm.org/viewvc/llvm-project?rev=265542&view=rev
Log:
[clang-tidy] filter plugins and plugin arguments of the command-line

Summary:
This patch remove the plugin argument from the command-line.

Loading plugins was making clang-tidy to fail when running over chromium 
(linux).

Example of a command-line executed when running clang-tidy over chromium (from 
the compilation database).

```
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF 
obj/third_party/WebKit/Source/core/fetch/webcore_shared.Resource.o.d 
-DV8_DEPRECATION_WARNINGS -DCLD_VERSION=2 -D_FILE_OFFSET_BITS=64 
-DCHROMIUM_BUILD -DCR_CLANG_REVISION=264915-1 -DCOMPONENT_BUILD 
-DUI_COMPOSITOR_IMAGE_TRANSPORT -DUSE_AURA=1 -DUSE_PANGO=1 -DUSE_CAIRO=1 
-DUSE_DEFAULT_RENDER_THEME=1 -DUSE_LIBJPEG_TURBO=1 -DUSE_X11=1 
-DUSE_CLIPBOARD_AURAX11=1 -DENABLE_WEBRTC=1 -DENABLE_MEDIA_ROUTER=1 
-DENABLE_PEPPER_CDMS -DENABLE_NOTIFICATIONS -DENABLE_TOPCHROME_MD=1 -DUSE_UDEV 
-DFIELDTRIAL_TESTING_ENABLED -DENABLE_TASK_MANAGER=1 -DENABLE_EXTENSIONS=1 
-DENABLE_PDF=1 -DENABLE_PLUGINS=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_THEMES=1 
-DENABLE_AUTOFILL_DIALOG=1 -DENABLE_PRINTING=1 -DENABLE_BASIC_PRINTING=1 
-DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 
-DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_APP_LIST=1 -DENABLE_SETTINGS_APP=1 
-DENABLE_SUPERVISED_USERS=1 -DENABLE_MDNS=1 -DENABLE_SERVICE_DISCOVERY=1 
-DV8_USE_EXTERNAL_STARTU
 P_DATA -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL 
-DBLINK_CORE_IMPLEMENTATION=1 -DBLINK_IMPLEMENTATION=1 -DINSIDE_BLINK 
-DGL_GLEXT_PROTOTYPES -DMOJO_USE_SYSTEM_IMPL -DCHROME_PNG_WRITE_SUPPORT 
-DPNG_USER_CONFIG -DENABLE_LAYOUT_UNIT_IN_INLINE_BOXES=0 -DENABLE_OILPAN=1 
-DWTF_USE_CONCATENATED_IMPULSE_RESPONSES=1 -DENABLE_INPUT_MULTIPLE_FIELDS_UI=1 
-DWTF_USE_ICCJPEG=1 -DWTF_USE_QCMSLIB=1 -DWTF_USE_WEBAUDIO_FFMPEG=1 
-DWTF_USE_DEFAULT_RENDER_THEME=1 -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 
-DU_NOEXCEPT= -DSKIA_DLL -DGR_GL_IGNORE_ES3_MSAA=0 -DSK_SUPPORT_GPU=1 
-DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS -DLIBXML_STATIC -DLIBXSLT_STATIC 
-DV8_SHARED -DUSING_V8_SHARED -DUSE_LIBPCI=1 -DUSE_OPENSSL=1 -DUSE_GLIB=1 
-DUSE_NSS_CERTS=1 -DUSE_NSS_VERIFIER=1 -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -DDYNAMIC_ANNOTATIONS_ENABLED=1 
-DWTF_USE_DYNAMIC_ANNOTATIONS=1 -D_DEBUG -D_GLIBCXX_DEBUG=1 -Igen 
-I../../third_party/WebKit/Source -Igen/blink -I../../third_party/WebKit -I../
 ../third_party/WebKit/Source/core/testing 
-I../../third_party/WebKit/Source/core/testing/v8 -I../.. -I../../skia/config 
-I../../third_party/khronos -I../../gpu -Igen/angle 
-I../../third_party/angle/include -I../../third_party/ffmpeg 
-Igen/third_party/WebKit -I../../third_party/iccjpeg -I../../third_party/libpng 
-I../../third_party/libwebp -I../../third_party/ots/include 
-I../../third_party/zlib -I../../third_party/libjpeg_turbo 
-I../../third_party/icu/source/i18n -I../../third_party/icu/source/common 
-I../../skia/ext -I../../third_party/skia/include/core 
-I../../third_party/skia/include/effects -I../../third_party/skia/include/pdf 
-I../../third_party/skia/include/gpu -I../../third_party/skia/include/lazy 
-I../../third_party/skia/include/pathops -I../../third_party/skia/include/pipe 
-I../../third_party/skia/include/ports -I../../third_party/skia/include/utils 
-I../../third_party/libxml/linux/include -I../../third_party/libxml/src/include 
-I../../third_party/libxslt -I../../third_part
 y/npapi -I../../third_party/npapi/bindings -I../../third_party/qcms/src 
-I../../third_party/snappy/linux -I../../third_party/snappy/src 
-I../../v8/include -fstack-protector --param=ssp-buffer-size=4 -Werror -pthread 
-fno-strict-aliasing -Wall -Wextra -Wno-unused-parameter 
-Wno-missing-field-initializers -fvisibility=hidden -pipe -fPIC -Xclang -load 
-Xclang 
/home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so
 -Xclang -add-plugin -Xclang find-bad-constructs -Xclang 
-plugin-arg-find-bad-constructs -Xclang check-templates -Xclang 
-plugin-arg-find-bad-constructs -Xclang follow-macro-expansion 
-fcolor-diagnostics 
-B/home/etienneb/chromium/src/third_party/binutils/Linux_x64/Release/bin 
-Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration 
-Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing 
-Wno-deprecated-register -Wno-inconsistent-missing-override 
-Wno-shift-negative-value -Wglobal-constructors -Wexit-time-destr
 uctors -fno-strict-aliasing -Xclang -load -Xclang 
/home/etienneb/chromium/src/third_party/llvm-build/Release+Asserts/lib/libBlinkGCPlugin.so
 -Xclang -add-plugin -Xclang blink-gc-plugin -Xclang 
-plugin-arg-blink-gc-plugin -Xclang enable-oilpan -Xclang 
-plugin-arg-blink-gc-plugin -Xclang warn-raw-ptr -pthread 
-I/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysroot/usr/include/glib-2.0
 
-I/home/etienneb/chromium/src/build/linux/debian_wheezy_amd64-sysr

Re: [PATCH] D18806: [clang-tidy] filter plugins and plugin arguments of the command-line

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 52788.
etienneb marked 4 inline comments as done.
etienneb added a comment.

alexfh@ comments.


http://reviews.llvm.org/D18806

Files:
  clang-tidy/ClangTidy.cpp

Index: clang-tidy/ClangTidy.cpp
===
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -107,9 +107,7 @@
 DiagPrinter->BeginSourceFile(LangOpts);
   }
 
-  SourceManager& getSourceManager() {
-return SourceMgr;
-  }
+  SourceManager &getSourceManager() { return SourceMgr; }
 
   void reportDiagnostic(const ClangTidyError &Error) {
 const ClangTidyMessage &Message = Error.Message;
@@ -141,7 +139,7 @@
   Range = SourceRange(FixLoc, FixEndLoc);
   Diag << FixItHint::CreateReplacement(Range, 
Fix.getReplacementText());
 }
-  
+
 ++TotalFixes;
 if (ApplyFixes) {
   bool Success = Fix.isApplicable() && Fix.apply(Rewrite);
@@ -417,19 +415,39 @@
  std::vector *Errors, ProfileData *Profile) {
   ClangTool Tool(Compilations, InputFiles);
   clang::tidy::ClangTidyContext Context(std::move(OptionsProvider));
-  ArgumentsAdjuster PerFileExtraArgumentsInserter = [&Context](
-  const CommandLineArguments &Args, StringRef Filename) {
-ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
-CommandLineArguments AdjustedArgs;
-if (Opts.ExtraArgsBefore)
-  AdjustedArgs = *Opts.ExtraArgsBefore;
-AdjustedArgs.insert(AdjustedArgs.begin(), Args.begin(), Args.end());
-if (Opts.ExtraArgs)
-  AdjustedArgs.insert(AdjustedArgs.end(), Opts.ExtraArgs->begin(),
-  Opts.ExtraArgs->end());
-return AdjustedArgs;
-  };
+
+  // Add extra arguments passed by the clang-tidy command-line.
+  ArgumentsAdjuster PerFileExtraArgumentsInserter =
+  [&Context](const CommandLineArguments &Args, StringRef Filename) {
+ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
+CommandLineArguments AdjustedArgs;
+if (Opts.ExtraArgsBefore)
+  AdjustedArgs = *Opts.ExtraArgsBefore;
+AdjustedArgs.insert(AdjustedArgs.begin(), Args.begin(), Args.end());
+if (Opts.ExtraArgs)
+  AdjustedArgs.insert(AdjustedArgs.end(), Opts.ExtraArgs->begin(),
+  Opts.ExtraArgs->end());
+return AdjustedArgs;
+  };
+
+  // Remove plugins arguments.
+  ArgumentsAdjuster PluginArgumentsRemover =
+  [&Context](const CommandLineArguments &Args, StringRef Filename) {
+CommandLineArguments AdjustedArgs;
+for (size_t I = 0, E = Args.size(); I < E; ++I) {
+  if (I + 4 < Args.size() && Args[I] == "-Xclang" &&
+  (Args[I + 1] == "-load" || Args[I + 1] == "-add-plugin" ||
+   StringRef(Args[I + 1]).startswith("-plugin-arg-")) &&
+  Args[I + 2] == "-Xclang") {
+I += 3;
+  } else
+AdjustedArgs.push_back(Args[I]);
+}
+return AdjustedArgs;
+  };
+
   Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
+  Tool.appendArgumentsAdjuster(PluginArgumentsRemover);
   if (Profile)
 Context.setCheckProfileData(Profile);
 


Index: clang-tidy/ClangTidy.cpp
===
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -107,9 +107,7 @@
 DiagPrinter->BeginSourceFile(LangOpts);
   }
 
-  SourceManager& getSourceManager() {
-return SourceMgr;
-  }
+  SourceManager &getSourceManager() { return SourceMgr; }
 
   void reportDiagnostic(const ClangTidyError &Error) {
 const ClangTidyMessage &Message = Error.Message;
@@ -141,7 +139,7 @@
   Range = SourceRange(FixLoc, FixEndLoc);
   Diag << FixItHint::CreateReplacement(Range, Fix.getReplacementText());
 }
-  
+
 ++TotalFixes;
 if (ApplyFixes) {
   bool Success = Fix.isApplicable() && Fix.apply(Rewrite);
@@ -417,19 +415,39 @@
  std::vector *Errors, ProfileData *Profile) {
   ClangTool Tool(Compilations, InputFiles);
   clang::tidy::ClangTidyContext Context(std::move(OptionsProvider));
-  ArgumentsAdjuster PerFileExtraArgumentsInserter = [&Context](
-  const CommandLineArguments &Args, StringRef Filename) {
-ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
-CommandLineArguments AdjustedArgs;
-if (Opts.ExtraArgsBefore)
-  AdjustedArgs = *Opts.ExtraArgsBefore;
-AdjustedArgs.insert(AdjustedArgs.begin(), Args.begin(), Args.end());
-if (Opts.ExtraArgs)
-  AdjustedArgs.insert(AdjustedArgs.end(), Opts.ExtraArgs->begin(),
-  Opts.ExtraArgs->end());
-return AdjustedArgs;
-  };
+
+  // Add extra arguments passed by the clang-tidy command-line.
+  ArgumentsAdjuster PerFileExtraArgumentsInserter =
+  [&Context](const CommandLineArguments &Args, StringRef Filename) {
+ClangTidyOptions Opts = Context.getOpt

Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 52791.
etienneb marked 2 inline comments as done.
etienneb added a comment.

alexfh comments.


http://reviews.llvm.org/D18783

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
  test/clang-tidy/misc-string-literal-with-embedded-nul.cpp

Index: test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
@@ -0,0 +1,85 @@
+// RUN: %check_clang_tidy %s misc-string-literal-with-embedded-nul %t
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template 
+struct basic_string {
+  typedef basic_string _Type;
+  basic_string();
+  basic_string(const C *p, const A &a = A());
+
+  _Type& operator+=(const C* s);
+  _Type& operator=(const C* s);
+};
+
+typedef basic_string, std::allocator> string;
+typedef basic_string, std::allocator> wstring;
+}
+
+bool operator==(const std::string&, const char*);
+bool operator==(const char*, const std::string&);
+
+
+const char Valid[] = "This is valid \x12.";
+const char Strange[] = "This is strange \0x12 and must be fixed";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: suspicious embedded NUL character [misc-string-literal-with-embedded-nul]
+
+const char textA[] = "\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious embedded NUL character
+const wchar_t textW[] = L"\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious embedded NUL character
+
+const char A[] = "\0";
+const char B[] = "\0x";
+const char C[] = "\0x1";
+const char D[] = "\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+const wchar_t E[] = L"\0";
+const wchar_t F[] = L"\0x";
+const wchar_t G[] = L"\0x1";
+const wchar_t H[] = L"\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious embedded NUL character
+
+const char I[] = "\000\000\000\000";
+const char J[] = "\0\0\0\0\0\0";
+const char K[] = "";
+
+const char L[] = "\0x12" "\0x12" "\0x12" "\0x12";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+void TestA() {
+  std::string str1 = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str2 = "\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str3("\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+  std::string str4{"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+
+  std::string str;
+  str += "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: truncated string literal
+  str = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: truncated string literal
+
+  if (str == "abc\0def") return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: truncated string literal
+  if ("abc\0def" == str) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: truncated string literal
+}
+
+void TestW() {
+  std::wstring str1 = L"abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str2 = L"\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str3(L"\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+  std::wstring str4{L"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+}
Index: docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
@@ -0,0 +1,37 @@
+.. title:: clang-tidy - misc-string-literal-with-embedded-nul
+
+misc-string-literal-with-embedded-nul
+=
+
+Find occurences of string literal with embedded NUL character and validate
+their usage.
+
+
+Invalid escaping
+
+
+Special characters can be escaped within a string literal by using their
+hexadecimal encoding like ``\x42``. A common mistake is to escape them
+like this ``\0x42`` where the ``\0`` stands for the NUL character.
+
+.. code:: c++
+
+  const char* Example[] = "Invalid character: \0x12 should be \x12";
+  const char* Bytes[] = "\x03\0x02\0x01\0x00\0xFF\0xFF\0xFF";
+
+
+Truncated literal
+^
+
+String-like classes can manipulate strings with embedded NUL as they are
+keeping track of the bytes and the length. This is not the case for an
+``char*`` (NUL-terminated) string.
+
+A common mistake is to pass a string-literal (NUL-terminated) to a string
+constructor. The bytes after the first NUL character are

Re: [PATCH] D18398: Compilation for Intel MCU (Part 1/3)

2016-04-06 Thread Andrey Turetskiy via cfe-commits
aturetsk updated this revision to Diff 52789.
aturetsk added a comment.

Fix remarks,


http://reviews.llvm.org/D18398

Files:
  include/clang/Driver/Options.td
  lib/Driver/Driver.cpp
  lib/Driver/Tools.cpp
  test/Driver/miamcu-opt.c

Index: test/Driver/miamcu-opt.c
===
--- /dev/null
+++ test/Driver/miamcu-opt.c
@@ -0,0 +1,21 @@
+// RUN: %clang -miamcu %s -### -o %t.o 2>&1 | FileCheck %s
+// RUN: %clang -miamcu -m32 %s -### -o %t.o 2>&1 | FileCheck %s
+// RUN: %clang -miamcu -target x86_64-unknown-linux-gnu %s -### -o %t.o 2>&1 | FileCheck %s
+// RUN: %clang -miamcu -m64 %s -### -o %t.o 2>&1 | FileCheck %s -check-prefix=M64
+// RUN: %clang -miamcu -dynamic %s -### -o %t.o 2>&1 | FileCheck %s -check-prefix=DYNAMIC
+// RUN: %clang -miamcu -target armv8-eabi %s -### -o %t.o 2>&1 | FileCheck %s -check-prefix=NOT-X86
+
+// M64: error: invalid argument '-miamcu' not allowed with '-m64'
+
+// DYNAMIC: error: invalid argument '-dynamic' not allowed with '-static'
+
+// NOT-X86: error: unsupported option '-miamcu' for target 'armv8---eabi'
+
+// CHECK: "-cc1"
+// CHECK: "-triple" "i586-intel-elfiamcu"
+// CHECK: "-static-define"
+// CHECK: "-mfloat-abi" "soft"
+// CHECK: "-mstack-alignment=4"
+
+// CHECK: bin/gcc
+// CHECK: "-static"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -2119,6 +2119,13 @@
   << A->getOption().getName() << Value;
 }
   }
+
+  // Set flags to support MCU ABI.
+  if (Args.hasArg(options::OPT_miamcu)) {
+CmdArgs.push_back("-mfloat-abi");
+CmdArgs.push_back("soft");
+CmdArgs.push_back("-mstack-alignment=4");
+  }
 }
 
 void Clang::AddHexagonTargetArgs(const ArgList &Args,
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -278,6 +278,10 @@
 DAL->append(A);
   }
 
+  // Enforce -static if -miamcu is present.
+  if (Args.hasArg(options::OPT_miamcu))
+DAL->AddFlagArg(0, Opts->getOption(options::OPT_static));
+
 // Add a default value of -mlinker-version=, if one was given and the user
 // didn't specify one.
 #if defined(HOST_LINK_VERSION)
@@ -296,7 +300,8 @@
 ///
 /// This routine provides the logic to compute a target triple from various
 /// args passed to the driver and the default triple string.
-static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple,
+static llvm::Triple computeTargetTriple(const Driver &D,
+StringRef DefaultTargetTriple,
 const ArgList &Args,
 StringRef DarwinArchName = "") {
   // FIXME: Already done in Compilation *Driver::BuildCompilation
@@ -341,8 +346,9 @@
 return Target;
 
   // Handle pseudo-target flags '-m64', '-mx32', '-m32' and '-m16'.
-  if (Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32,
-   options::OPT_m32, options::OPT_m16)) {
+  Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32,
+   options::OPT_m32, options::OPT_m16);
+  if (A) {
 llvm::Triple::ArchType AT = llvm::Triple::UnknownArch;
 
 if (A->getOption().matches(options::OPT_m64)) {
@@ -367,6 +373,25 @@
   Target.setArch(AT);
   }
 
+  // Handle -miamcu flag.
+  if (Args.hasArg(options::OPT_miamcu)) {
+if (Target.get32BitArchVariant().getArch() != llvm::Triple::x86)
+  D.Diag(diag::err_drv_unsupported_opt_for_target) << "-miamcu"
+   << Target.str();
+
+if (A && !A->getOption().matches(options::OPT_m32))
+  D.Diag(diag::err_drv_argument_not_allowed_with)
+  << "-miamcu" << A->getBaseArg().getAsString(Args);
+
+Target.setArch(llvm::Triple::x86);
+Target.setArchName("i586");
+Target.setEnvironment(llvm::Triple::UnknownEnvironment);
+Target.setEnvironmentName("");
+Target.setOS(llvm::Triple::ELFIAMCU);
+Target.setVendor(llvm::Triple::UnknownVendor);
+Target.setVendorName("intel");
+  }
+
   return Target;
 }
 
@@ -501,8 +526,8 @@
   DerivedArgList *TranslatedArgs = TranslateInputArgs(*UArgs);
 
   // Owned by the host.
-  const ToolChain &TC =
-  getToolChain(*UArgs, computeTargetTriple(DefaultTargetTriple, *UArgs));
+  const ToolChain &TC = getToolChain(
+  *UArgs, computeTargetTriple(*this, DefaultTargetTriple, *UArgs));
 
   // The compilation takes ownership of Args.
   Compilation *C = new Compilation(*this, TC, UArgs.release(), TranslatedArgs);
@@ -1957,9 +1982,9 @@
 const char *ArchName = BAA->getArchName();
 
 if (ArchName)
-  TC = &getToolChain(
-  C.getArgs(),
-  computeTargetTriple(DefaultTargetTriple, C.getArgs(), ArchName));
+  TC = &getToolChain(C.getArgs(),
+ computeTargetTriple(*this, DefaultTargetTriple,
+

Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 52793.
etienneb added a comment.

nits.


http://reviews.llvm.org/D18783

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp
  clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
  test/clang-tidy/misc-string-literal-with-embedded-nul.cpp

Index: test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-string-literal-with-embedded-nul.cpp
@@ -0,0 +1,85 @@
+// RUN: %check_clang_tidy %s misc-string-literal-with-embedded-nul %t
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template 
+struct basic_string {
+  typedef basic_string _Type;
+  basic_string();
+  basic_string(const C *p, const A &a = A());
+
+  _Type& operator+=(const C* s);
+  _Type& operator=(const C* s);
+};
+
+typedef basic_string, std::allocator> string;
+typedef basic_string, std::allocator> wstring;
+}
+
+bool operator==(const std::string&, const char*);
+bool operator==(const char*, const std::string&);
+
+
+const char Valid[] = "This is valid \x12.";
+const char Strange[] = "This is strange \0x12 and must be fixed";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: suspicious embedded NUL character [misc-string-literal-with-embedded-nul]
+
+const char textA[] = "\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious embedded NUL character
+const wchar_t textW[] = L"\0x01\0x02\0x03\0x04";
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious embedded NUL character
+
+const char A[] = "\0";
+const char B[] = "\0x";
+const char C[] = "\0x1";
+const char D[] = "\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+const wchar_t E[] = L"\0";
+const wchar_t F[] = L"\0x";
+const wchar_t G[] = L"\0x1";
+const wchar_t H[] = L"\0x11";
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious embedded NUL character
+
+const char I[] = "\000\000\000\000";
+const char J[] = "\0\0\0\0\0\0";
+const char K[] = "";
+
+const char L[] = "\0x12" "\0x12" "\0x12" "\0x12";
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: suspicious embedded NUL character
+
+void TestA() {
+  std::string str1 = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str2 = "\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: truncated string literal
+  std::string str3("\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+  std::string str4{"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: truncated string literal
+
+  std::string str;
+  str += "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: truncated string literal
+  str = "abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: truncated string literal
+
+  if (str == "abc\0def") return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: truncated string literal
+  if ("abc\0def" == str) return;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: truncated string literal
+}
+
+void TestW() {
+  std::wstring str1 = L"abc\0def";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str2 = L"\0";
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: truncated string literal
+  std::wstring str3(L"\0");
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+  std::wstring str4{L"\x00\x01\x02\x03"};
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: truncated string literal
+}
Index: docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-string-literal-with-embedded-nul.rst
@@ -0,0 +1,37 @@
+.. title:: clang-tidy - misc-string-literal-with-embedded-nul
+
+misc-string-literal-with-embedded-nul
+=
+
+Find occurences of string literal with embedded NUL character and validate
+their usage.
+
+
+Invalid escaping
+
+
+Special characters can be escaped within a string literal by using their
+hexadecimal encoding like ``\x42``. A common mistake is to escape them
+like this ``\0x42`` where the ``\0`` stands for the NUL character.
+
+.. code:: c++
+
+  const char* Example[] = "Invalid character: \0x12 should be \x12";
+  const char* Bytes[] = "\x03\0x02\0x01\0x00\0xFF\0xFF\0xFF";
+
+
+Truncated literal
+^
+
+String-like classes can manipulate strings with embedded NUL as they are
+keeping track of the bytes and the length. This is not the case for an
+``char*`` (NUL-terminated) string.
+
+A common mistake is to pass a string-literal (NUL-terminated) to a string
+constructor. The bytes after the first NUL character are truncated.
+
+.. code:: c++
+
+  std::string str("abc

Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

I finally get rid of the GetCharAt function.



Comment at: clang-tidy/misc/StringLiteralWithEmbeddedNulCheck.cpp:22
@@ +21,3 @@
+static unsigned int GetCharAt(const StringLiteral *SL, size_t offset) {
+  if (offset >= SL->getLength()) return 0;
+  return SL->getCodeUnit(offset);

alexfh wrote:
> Should this be an assert instead?
No, because we are not doing bounds check later:

  if (GetCharAt(SL, i) == 0 &&
  GetCharAt(SL, i + 1) == 'x' &&
  isDigit(GetCharAt(SL, i + 2)) &&
  isDigit(GetCharAt(SL, i + 3))) {

We can move this as an assert, and in this case... we can modify the "if" to 
check the length.


http://reviews.llvm.org/D18783



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


Re: [PATCH] D18398: Compilation for Intel MCU (Part 1/3)

2016-04-06 Thread Andrey Turetskiy via cfe-commits
aturetsk added a comment.

Hi Bruno,

Thanks for the review.



Comment at: include/clang/Driver/Options.td:1281
@@ -1280,1 +1280,3 @@
+def miamcu : Flag<["-"], "miamcu">, Group, Flags<[DriverOption, 
CoreOption]>,
+  HelpText<"Use Intel MCU ABI">;
 def malign_functions_EQ : Joined<["-"], "malign-functions=">, 
Group;

Fixed.


Comment at: lib/Driver/Driver.cpp:282
@@ +281,3 @@
+  // Enforce -static if -miamcu is present.
+  if (Args.hasArg(options::OPT_miamcu))
+DAL->AddFlagArg(0, Opts->getOption(options::OPT_static));

You're right.
The warning was removed and the test was updated.


Comment at: lib/Driver/Driver.cpp:380
@@ +379,3 @@
+  D.Diag(diag::err_drv_unsupported_opt_for_target) << "-miamcu"
+   << Target.str();
+

I made driver to show an error if '-miamcu' is used with anything but x86.
The corresponding test was added.


Comment at: lib/Driver/Tools.cpp:2130
@@ -2122,3 +2129,3 @@
 }
 
 void Clang::AddHexagonTargetArgs(const ArgList &Args,

No, the idea is for -miamcu to specify only ABI and it shouldn't be bound to 
Lakemont at all. Which target CPU to use is the choice of the user and it 
should be explicitly specified through -march.
I believe GCC does the same.


http://reviews.llvm.org/D18398



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


Re: [PATCH] D18776: NFC: make AtomicOrdering an enum class

2016-04-06 Thread James Y Knight via cfe-commits
jyknight accepted this revision.
jyknight added a comment.

BTW, this change doesn't actually depend on the LLVM change; it could be 
committed first, as a "normal" enum puts its members both inside the enum 
name's scope and outside.


http://reviews.llvm.org/D18776



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


Re: [PATCH] D18694: [ClangTidy] Add an 'explain-checks' option to diagnose where each checks comes from.

2016-04-06 Thread Haojian Wu via cfe-commits
hokein updated this revision to Diff 52797.
hokein marked an inline comment as done.
hokein added a comment.

Correct the processing orders.


http://reviews.llvm.org/D18694

Files:
  clang-tidy/ClangTidyOptions.cpp
  clang-tidy/ClangTidyOptions.h
  clang-tidy/tool/ClangTidyMain.cpp
  test/clang-tidy/Inputs/explain-config/.clang-tidy
  test/clang-tidy/explain-checks.cpp

Index: test/clang-tidy/explain-checks.cpp
===
--- /dev/null
+++ test/clang-tidy/explain-checks.cpp
@@ -0,0 +1,12 @@
+// RUN: clang-tidy -checks=-*,modernize-use-nullptr -explain-config | FileCheck --check-prefix=CHECK-MESSAGE1 %s
+// RUN: clang-tidy -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE2 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE3 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,-modernize-use-nullptr'}" %S/Inputs/explain-config/a.cc -explain-config | FileCheck --check-prefix=CHECK-MESSAGE4 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-*'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE5 %s
+// RUN: clang-tidy -explain-config %S/Inputs/explain-config/a.cc | grep "'modernize-use-nullptr' is enabled in the %S/Inputs/explain-config/.clang-tidy."
+
+// CHECK-MESSAGE1: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE2: 'modernize-use-nullptr' is enabled in the command-line option '-config'.
+// CHECK-MESSAGE3: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE4: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE5: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
Index: test/clang-tidy/Inputs/explain-config/.clang-tidy
===
--- /dev/null
+++ test/clang-tidy/Inputs/explain-config/.clang-tidy
@@ -0,0 +1 @@
+Checks: '-*,modernize-use-nullptr'
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -128,6 +128,12 @@
 )"),
 cl::init(false), cl::cat(ClangTidyCategory));
 
+static cl::opt ExplainConfig("explain-config", cl::desc(R"(
+for each enabled check explains, where it is enabled, i.e. in clang-tidy binary,
+command line or a specific configuration file.
+)"),
+   cl::init(false), cl::cat(ClangTidyCategory));
+
 static cl::opt Config("config", cl::desc(R"(
 Specifies a configuration in YAML/JSON format:
   -config="{Checks: '*',
@@ -256,6 +262,8 @@
 
   ClangTidyOptions DefaultOptions;
   DefaultOptions.Checks = DefaultChecks;
+  DefaultOptions.CheckSources[ClangTidyOptions::DefaultBinary].push_back(
+  ClangTidyOptions::StringPair(DefaultChecks, "clang-tidy binary"));
   DefaultOptions.WarningsAsErrors = "";
   DefaultOptions.HeaderFilterRegex = HeaderFilter;
   DefaultOptions.SystemHeaders = SystemHeaders;
@@ -266,8 +274,12 @@
 DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
 
   ClangTidyOptions OverrideOptions;
-  if (Checks.getNumOccurrences() > 0)
+  if (Checks.getNumOccurrences() > 0) {
 OverrideOptions.Checks = Checks;
+OverrideOptions.CheckSources[ClangTidyOptions::ChecksCommandlineOption]
+.push_back(ClangTidyOptions::StringPair(
+Checks, "command-line option '-checks'"));
+  }
   if (WarningsAsErrors.getNumOccurrences() > 0)
 OverrideOptions.WarningsAsErrors = WarningsAsErrors;
   if (HeaderFilter.getNumOccurrences() > 0)
@@ -280,6 +292,12 @@
   if (!Config.empty()) {
 if (llvm::ErrorOr ParsedConfig =
 parseConfiguration(Config)) {
+  if (ParsedConfig->Checks) {
+ParsedConfig
+->CheckSources[ClangTidyOptions::ConfigCommandlineOptionOrFile]
+.push_back(ClangTidyOptions::StringPair(
+*ParsedConfig->Checks, "command-line option '-config'"));
+  }
   return llvm::make_unique(
   GlobalOptions, ClangTidyOptions::getDefaults()
  .mergeWith(DefaultOptions)
@@ -311,6 +329,29 @@
   ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName);
   std::vector EnabledChecks = getCheckNames(EffectiveOptions);
 
+  if (ExplainConfig) {
+for (const std::string& Check : EnabledChecks) {
+  // Keeps the processing order of different check sources.
+  for (auto SourceType : {ClangTidyOptions::ChecksCommandlineOption,
+  ClangTidyOptions::ConfigCommandlineOptionOrFile,
+  ClangTidyOptions::DefaultBinary}) {
+bool FindMatch = false;
+for (auto It = EffectiveOptions.CheckSources[SourceTyp

Re: [PATCH] D18694: [ClangTidy] Add an 'explain-checks' option to diagnose where each checks comes from.

2016-04-06 Thread Haojian Wu via cfe-commits
hokein updated this revision to Diff 52798.
hokein added a comment.

More comments.


http://reviews.llvm.org/D18694

Files:
  clang-tidy/ClangTidyOptions.cpp
  clang-tidy/ClangTidyOptions.h
  clang-tidy/tool/ClangTidyMain.cpp
  test/clang-tidy/Inputs/explain-config/.clang-tidy
  test/clang-tidy/explain-checks.cpp

Index: test/clang-tidy/explain-checks.cpp
===
--- /dev/null
+++ test/clang-tidy/explain-checks.cpp
@@ -0,0 +1,12 @@
+// RUN: clang-tidy -checks=-*,modernize-use-nullptr -explain-config | FileCheck --check-prefix=CHECK-MESSAGE1 %s
+// RUN: clang-tidy -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE2 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-use-nullptr'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE3 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,-modernize-use-nullptr'}" %S/Inputs/explain-config/a.cc -explain-config | FileCheck --check-prefix=CHECK-MESSAGE4 %s
+// RUN: clang-tidy -checks=modernize-use-nullptr -config="{Checks: '-*,modernize-*'}" -explain-config | FileCheck --check-prefix=CHECK-MESSAGE5 %s
+// RUN: clang-tidy -explain-config %S/Inputs/explain-config/a.cc | grep "'modernize-use-nullptr' is enabled in the %S/Inputs/explain-config/.clang-tidy."
+
+// CHECK-MESSAGE1: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE2: 'modernize-use-nullptr' is enabled in the command-line option '-config'.
+// CHECK-MESSAGE3: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE4: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
+// CHECK-MESSAGE5: 'modernize-use-nullptr' is enabled in the command-line option '-checks'.
Index: test/clang-tidy/Inputs/explain-config/.clang-tidy
===
--- /dev/null
+++ test/clang-tidy/Inputs/explain-config/.clang-tidy
@@ -0,0 +1 @@
+Checks: '-*,modernize-use-nullptr'
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -128,6 +128,12 @@
 )"),
 cl::init(false), cl::cat(ClangTidyCategory));
 
+static cl::opt ExplainConfig("explain-config", cl::desc(R"(
+for each enabled check explains, where it is enabled, i.e. in clang-tidy binary,
+command line or a specific configuration file.
+)"),
+   cl::init(false), cl::cat(ClangTidyCategory));
+
 static cl::opt Config("config", cl::desc(R"(
 Specifies a configuration in YAML/JSON format:
   -config="{Checks: '*',
@@ -256,6 +262,8 @@
 
   ClangTidyOptions DefaultOptions;
   DefaultOptions.Checks = DefaultChecks;
+  DefaultOptions.CheckSources[ClangTidyOptions::DefaultBinary].push_back(
+  ClangTidyOptions::StringPair(DefaultChecks, "clang-tidy binary"));
   DefaultOptions.WarningsAsErrors = "";
   DefaultOptions.HeaderFilterRegex = HeaderFilter;
   DefaultOptions.SystemHeaders = SystemHeaders;
@@ -266,8 +274,12 @@
 DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
 
   ClangTidyOptions OverrideOptions;
-  if (Checks.getNumOccurrences() > 0)
+  if (Checks.getNumOccurrences() > 0) {
 OverrideOptions.Checks = Checks;
+OverrideOptions.CheckSources[ClangTidyOptions::ChecksCommandlineOption]
+.push_back(ClangTidyOptions::StringPair(
+Checks, "command-line option '-checks'"));
+  }
   if (WarningsAsErrors.getNumOccurrences() > 0)
 OverrideOptions.WarningsAsErrors = WarningsAsErrors;
   if (HeaderFilter.getNumOccurrences() > 0)
@@ -280,6 +292,12 @@
   if (!Config.empty()) {
 if (llvm::ErrorOr ParsedConfig =
 parseConfiguration(Config)) {
+  if (ParsedConfig->Checks) {
+ParsedConfig
+->CheckSources[ClangTidyOptions::ConfigCommandlineOptionOrFile]
+.push_back(ClangTidyOptions::StringPair(
+*ParsedConfig->Checks, "command-line option '-config'"));
+  }
   return llvm::make_unique(
   GlobalOptions, ClangTidyOptions::getDefaults()
  .mergeWith(DefaultOptions)
@@ -311,6 +329,29 @@
   ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FileName);
   std::vector EnabledChecks = getCheckNames(EffectiveOptions);
 
+  if (ExplainConfig) {
+for (const std::string& Check : EnabledChecks) {
+  // Keeps the processing order of different check sources.
+  for (auto SourceType : {ClangTidyOptions::ChecksCommandlineOption,
+  ClangTidyOptions::ConfigCommandlineOptionOrFile,
+  ClangTidyOptions::DefaultBinary}) {
+bool FindMatch = false;
+for (auto It = EffectiveOptions.CheckSources[SourceType].rbegin();
+ It != EffectiveOptions.CheckSo

Re: [PATCH] D18694: [ClangTidy] Add an 'explain-checks' option to diagnose where each checks comes from.

2016-04-06 Thread Haojian Wu via cfe-commits
hokein marked an inline comment as done.
hokein added a comment.

http://reviews.llvm.org/D18694



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


[clang-tools-extra] r265544 - [clang-tidy] Assertion fix in misc-misplaced-widening-cast check.

2016-04-06 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Wed Apr  6 09:49:15 2016
New Revision: 265544

URL: http://llvm.org/viewvc/llvm-project?rev=265544&view=rev
Log:
[clang-tidy] Assertion fix in misc-misplaced-widening-cast check.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp?rev=265544&r1=265543&r2=265544&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MisplacedWideningCastCheck.cpp Wed 
Apr  6 09:49:15 2016
@@ -95,7 +95,7 @@ static unsigned getMaxCalculationWidth(A
 }
 
 static llvm::SmallDenseMap createRelativeIntSizesMap() {
-  llvm::SmallDenseMap Result(14);
+  llvm::SmallDenseMap Result;
   Result[BuiltinType::UChar] = 1;
   Result[BuiltinType::SChar] = 1;
   Result[BuiltinType::Char_U] = 1;
@@ -114,7 +114,7 @@ static llvm::SmallDenseMap cre
 }
 
 static llvm::SmallDenseMap createRelativeCharSizesMap() {
-  llvm::SmallDenseMap Result(6);
+  llvm::SmallDenseMap Result;
   Result[BuiltinType::UChar] = 1;
   Result[BuiltinType::SChar] = 1;
   Result[BuiltinType::Char_U] = 1;
@@ -125,7 +125,7 @@ static llvm::SmallDenseMap cre
 }
 
 static llvm::SmallDenseMap createRelativeCharSizesWMap() {
-  llvm::SmallDenseMap Result(6);
+  llvm::SmallDenseMap Result;
   Result[BuiltinType::UChar] = 1;
   Result[BuiltinType::SChar] = 1;
   Result[BuiltinType::Char_U] = 1;


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


r265545 - clang-format: Support labels in brace-less ifs.

2016-04-06 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Apr  6 10:02:46 2016
New Revision: 265545

URL: http://llvm.org/viewvc/llvm-project?rev=265545&view=rev
Log:
clang-format: Support labels in brace-less ifs.

While I am not personally convinced about the usefulness of this
construct, we should break it.

Before:
  if (a) label:
  f();

After:
  if (a)
  label:
f();

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=265545&r1=265544&r2=265545&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Apr  6 10:02:46 2016
@@ -1010,6 +1010,7 @@ void UnwrappedLineParser::parseStructura
   // not labels.
   Style.Language != FormatStyle::LK_JavaScript) {
 if (FormatTok->Tok.is(tok::colon) && !Line->MustBeDeclaration) {
+  Line->Tokens.begin()->Tok->MustBreakBefore = true;
   parseLabel();
   return;
 }
@@ -1572,6 +1573,8 @@ void UnwrappedLineParser::parseLabel() {
 addUnwrappedLine();
   }
   Line->Level = OldLineLevel;
+  if (FormatTok->isNot(tok::l_brace))
+parseStructuralElement();
 }
 
 void UnwrappedLineParser::parseCaseLabel() {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=265545&r1=265544&r2=265545&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Apr  6 10:02:46 2016
@@ -301,6 +301,12 @@ TEST_F(FormatTest, FormatIfWithoutCompou
"  // comment\n"
"  f();",
AllowsMergedIf);
+  verifyFormat("{\n"
+   "  if (a)\n"
+   "  label:\n"
+   "f();\n"
+   "}",
+   AllowsMergedIf);
   verifyFormat("if (a)\n"
"  ;",
AllowsMergedIf);


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


Re: [PATCH] D18713: [OpenCL] Generate bitcast when target address space does not change.

2016-04-06 Thread Yaxun Liu via cfe-commits
yaxunl updated the summary for this revision.
yaxunl updated this revision to Diff 52800.
yaxunl added a comment.

Add more checks for w/o -ffake-address-space-map to the test.


http://reviews.llvm.org/D18713

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGenOpenCL/address-spaces-conversions.cl

Index: test/CodeGenOpenCL/address-spaces-conversions.cl
===
--- test/CodeGenOpenCL/address-spaces-conversions.cl
+++ test/CodeGenOpenCL/address-spaces-conversions.cl
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 
-ffake-address-space-map -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -cl-std=CL2.0 
-emit-llvm -o - | FileCheck --check-prefix=CHECK-NOFAKE %s
+// When -ffake-address-space-map is not used, all addr space mapped to 0 for 
x86_64.
 
 // test that we generate address space casts everywhere we need conversions of
 // pointers to different address spaces
@@ -7,16 +9,33 @@
   int var_priv;
   arg_gen = arg_glob; // implicit cast global -> generic
   // CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 
addrspace(4)*
+  // CHECK-NOFAKE-NOT: addrspacecast
+
   arg_gen = &var_priv; // implicit cast with obtaining adr, private -> generic
   // CHECK: %{{[0-9]+}} = addrspacecast i32* %var_priv to i32 addrspace(4)*
+  // CHECK-NOFAKE-NOT: addrspacecast
+
   arg_glob = (global int *)arg_gen; // explicit cast
   // CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(4)* %{{[0-9]+}} to i32 
addrspace(1)*
+  // CHECK-NOFAKE-NOT: addrspacecast
+
   global int *var_glob =
   (global int *)arg_glob; // explicit cast in the same address space
   // CHECK-NOT: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to 
i32 addrspace(1)*
+  // CHECK-NOFAKE-NOT: addrspacecast
+
   var_priv = arg_gen - arg_glob; // arithmetic operation
   // CHECK: %{{.*}} = ptrtoint i32 addrspace(4)* %{{.*}} to i64
   // CHECK: %{{.*}} = ptrtoint i32 addrspace(1)* %{{.*}} to i64
+  // CHECK-NOFAKE: %{{.*}} = ptrtoint i32* %{{.*}} to i64
+  // CHECK-NOFAKE: %{{.*}} = ptrtoint i32* %{{.*}} to i64
+
   var_priv = arg_gen > arg_glob; // comparison
   // CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 
addrspace(4)*
+
+  generic void *var_gen_v = arg_glob;
+  // CHECK: addrspacecast
+  // CHECK-NOT: bitcast
+  // CHECK-NOFAKE: bitcast
+  // CHECK-NOFAKE-NOT: addrspacecast
 }
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1411,7 +1411,10 @@
   }
   case CK_AddressSpaceConversion: {
 Value *Src = Visit(const_cast(E));
-return Builder.CreateAddrSpaceCast(Src, ConvertType(DestTy));
+// Since target may map different address spaces in AST to the same address
+// space, an address space conversion may end up as a bitcast.
+return Builder.CreatePointerBitCastOrAddrSpaceCast(Src,
+   ConvertType(DestTy));
   }
   case CK_AtomicToNonAtomic:
   case CK_NonAtomicToAtomic:


Index: test/CodeGenOpenCL/address-spaces-conversions.cl
===
--- test/CodeGenOpenCL/address-spaces-conversions.cl
+++ test/CodeGenOpenCL/address-spaces-conversions.cl
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -ffake-address-space-map -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -O0 -cl-std=CL2.0 -emit-llvm -o - | FileCheck --check-prefix=CHECK-NOFAKE %s
+// When -ffake-address-space-map is not used, all addr space mapped to 0 for x86_64.
 
 // test that we generate address space casts everywhere we need conversions of
 // pointers to different address spaces
@@ -7,16 +9,33 @@
   int var_priv;
   arg_gen = arg_glob; // implicit cast global -> generic
   // CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 addrspace(4)*
+  // CHECK-NOFAKE-NOT: addrspacecast
+
   arg_gen = &var_priv; // implicit cast with obtaining adr, private -> generic
   // CHECK: %{{[0-9]+}} = addrspacecast i32* %var_priv to i32 addrspace(4)*
+  // CHECK-NOFAKE-NOT: addrspacecast
+
   arg_glob = (global int *)arg_gen; // explicit cast
   // CHECK: %{{[0-9]+}} = addrspacecast i32 addrspace(4)* %{{[0-9]+}} to i32 addrspace(1)*
+  // CHECK-NOFAKE-NOT: addrspacecast
+
   global int *var_glob =
   (global int *)arg_glob; // explicit cast in the same address space
   // CHECK-NOT: %{{[0-9]+}} = addrspacecast i32 addrspace(1)* %{{[0-9]+}} to i32 addrspace(1)*
+  // CHECK-NOFAKE-NOT: addrspacecast
+
   var_priv = arg_gen - arg_glob; // arithmetic operation
   // CHECK: %{{.*}} = ptrtoint i32 addrspace(4)* %{{.*}} to i64
   // CHECK: %{{.*}} = ptrtoint i32 addrspace(1)* %{{.*}} to i64
+  // CHECK-NOFAKE: %{{.*}} = ptrtoint i32* %{{.*}} to i64
+  // CHECK-N

Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-06 Thread David Blaikie via cfe-commits
On Tue, Apr 5, 2016 at 10:17 PM, Eric Christopher via llvm-commits <
llvm-comm...@lists.llvm.org> wrote:

> echristo added inline comments.
>
> 
> Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:477-479
> @@ -476,2 +476,5 @@
> +  unsigned DebugCUs = 0;
>for (MDNode *N : CU_Nodes->operands()) {
>  auto *CUNode = cast(N);
> +if (CUNode->getEmissionKind() == DICompileUnit::NoDebug)
> +  continue;
> 
> Instead of this pattern would it make more sense to have an iterator over
> the nodes that checks for !NoDebug?
>

Yeah, that sounds like something that might be nice.

Adrian - I recall one of your initial ideas was to just have a different
named metadata node for these subprograms. What was the motivation for not
going with that plan? (which would've meant these sort of loops would've
remained OK, and only the loops in the verifier and such would need to
examine both nodes?) Perhaps this relates to your comment about LTOing
debug+nodebug CUs? I didn't quite follow what was wrong with that in the
first place & how this addresses it, could you explain it?


>
> 
> Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1127-1128
> @@ -1115,3 +1126,4 @@
>if (!MMI->hasDebugInfo() || LScopes.empty() ||
> -  !MF->getFunction()->getSubprogram()) {
> +  !MF->getFunction()->getSubprogram() ||
> +  !SPMap.lookup(MF->getFunction()->getSubprogram())) {
>  // If we don't have a lexical scope for this function then there will
> 
> Comment.
>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D18808
>
>
>
> ___
> llvm-commits mailing list
> llvm-comm...@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18565: Implement an "I'm dtrace, please retain all debug types" option.

2016-04-06 Thread David Blaikie via cfe-commits
Okey dokey - I know one of the things we did (& I don't know when it
happened compared to this change) is emit a hard list of variables onto any
subprogram for an optimized (non -O0) function. So we never lose variables
due to optimizations, or at least that's the intent.

As for D18477, I'm not sure why collectDeadVariables became dead with your
change - I imagine we still want to stuff dead variables into the
subprograms we did create (the ones that weren't /entirely/ optimized away
(ones with remaining inlined instances, etc)) - but maybe we do that
elsewhere?

On Tue, Apr 5, 2016 at 3:14 PM, Adrian Prantl via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> aprantl abandoned this revision.
> aprantl added a comment.
>
> Meanwhile I made an experiment and compiled XNU with
> http://reviews.llvm.org/D18477 and compared the debug info from before
> and after and found no missing types at all. It is plausible that r107027
> was added to work around the fact that six years ago LLVM was a lot worse
> at preserving debug info for local variables. It is also possible that the
> call graph of the kernel changed in the mean time or a combination of both.
>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D18565
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D18829: [clang-tidy] Fix FP with readability-redundant-string-init for default arguments

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

Clang-tidy is reporting a warning of redundant string initialisation
on a string parameter initialized with empty string.

See bug: 27087

The reported example is:
```
#include 
void fn(std::string a = "");
```

http://reviews.llvm.org/D18829

Files:
  clang-tidy/readability/RedundantStringInitCheck.cpp
  test/clang-tidy/readability-redundant-string-init.cpp

Index: test/clang-tidy/readability-redundant-string-init.cpp
===
--- test/clang-tidy/readability-redundant-string-init.cpp
+++ test/clang-tidy/readability-redundant-string-init.cpp
@@ -131,3 +131,10 @@
 
   std::string d = "u", e = "u", f = "u";
 }
+
+// These cases should not generate warnings.
+extern void Param1(std::string param = "");
+extern void Param2(const std::string& param = "");
+void Param3(std::string param = "") {}
+void Param4(STRING param = "") {}
+
Index: clang-tidy/readability/RedundantStringInitCheck.cpp
===
--- clang-tidy/readability/RedundantStringInitCheck.cpp
+++ clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -61,7 +61,8 @@
 hasInitializer(
 expr(anyOf(EmptyStringCtorExpr,
EmptyStringCtorExprWithTemporaries))
-.bind("expr"
+.bind("expr"))),
+unless(parmVarDecl()))
   .bind("decl"),
   this);
 }


Index: test/clang-tidy/readability-redundant-string-init.cpp
===
--- test/clang-tidy/readability-redundant-string-init.cpp
+++ test/clang-tidy/readability-redundant-string-init.cpp
@@ -131,3 +131,10 @@
 
   std::string d = "u", e = "u", f = "u";
 }
+
+// These cases should not generate warnings.
+extern void Param1(std::string param = "");
+extern void Param2(const std::string& param = "");
+void Param3(std::string param = "") {}
+void Param4(STRING param = "") {}
+
Index: clang-tidy/readability/RedundantStringInitCheck.cpp
===
--- clang-tidy/readability/RedundantStringInitCheck.cpp
+++ clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -61,7 +61,8 @@
 hasInitializer(
 expr(anyOf(EmptyStringCtorExpr,
EmptyStringCtorExprWithTemporaries))
-.bind("expr"
+.bind("expr"))),
+unless(parmVarDecl()))
   .bind("decl"),
   this);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r265546 - Enable PIE for CloudABI.

2016-04-06 Thread Ed Schouten via cfe-commits
Author: ed
Date: Wed Apr  6 10:37:06 2016
New Revision: 265546

URL: http://llvm.org/viewvc/llvm-project?rev=265546&view=rev
Log:
Enable PIE for CloudABI.

As we're currently working on making CloudABI executables easier to
emulate in userspace (e.g., on OS X and Windows), it makes a whole lot
of sense to build these using PIE. By using PIE, they can simply be
loaded into the existing process address space without clashes.

PIE support got added to CloudABI's C library and seems to work pretty
well. CloudABI does not make use of an ld.so, so the binary's _start()
has all the logic in it to do the relocations.

Now that all but one bug in LLD relating to PIE support have been
squashed (and a patch for that is already in code review), I'd like to
go ahead and force the use of PIE for Clang 3.9. When released, we'll
also switch over to using LLD exclusively.

Modified:
cfe/trunk/lib/Driver/ToolChains.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/cloudabi.c
cfe/trunk/test/Driver/cloudabi.cpp

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=265546&r1=265545&r2=265546&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Wed Apr  6 10:37:06 2016
@@ -617,7 +617,7 @@ public:
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
 
-  bool isPIEDefault() const override { return false; }
+  bool isPIEDefault() const override { return true; }
 
   SanitizerMask getSupportedSanitizers() const override;
   SanitizerMask getDefaultSanitizers() const override;

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=265546&r1=265545&r2=265546&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Apr  6 10:37:06 2016
@@ -7110,6 +7110,12 @@ void cloudabi::Linker::ConstructJob(Comp
 
   // CloudABI only supports static linkage.
   CmdArgs.push_back("-Bstatic");
+
+  // CloudABI uses Position Independent Executables exclusively.
+  CmdArgs.push_back("-pie");
+  CmdArgs.push_back("--no-dynamic-linker");
+  CmdArgs.push_back("-zrelro");
+
   CmdArgs.push_back("--eh-frame-hdr");
   CmdArgs.push_back("--gc-sections");
 

Modified: cfe/trunk/test/Driver/cloudabi.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cloudabi.c?rev=265546&r1=265545&r2=265546&view=diff
==
--- cfe/trunk/test/Driver/cloudabi.c (original)
+++ cfe/trunk/test/Driver/cloudabi.c Wed Apr  6 10:37:06 2016
@@ -1,8 +1,8 @@
 // RUN: %clang %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s 
-check-prefix=SAFESTACK
 // SAFESTACK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} 
"-ffunction-sections" "-fdata-sections" {{.*}} "-fsanitize=safe-stack"
-// SAFESTACK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" 
"crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
+// SAFESTACK: "-Bstatic" "-pie" "--no-dynamic-linker" "-zrelro" 
"--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" 
"{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
 
 // RUN: %clang %s -### -target x86_64-unknown-cloudabi 
-fno-sanitize=safe-stack 2>&1 | FileCheck %s -check-prefix=NOSAFESTACK
 // NOSAFESTACK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} 
"-ffunction-sections" "-fdata-sections"
 // NOSAFESTACK-NOT: "-fsanitize=safe-stack"
-// NOSAFESTACK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" 
"crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
+// NOSAFESTACK: "-Bstatic" "-pie" "--no-dynamic-linker" "-zrelro" 
"--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" 
"{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"

Modified: cfe/trunk/test/Driver/cloudabi.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cloudabi.cpp?rev=265546&r1=265545&r2=265546&view=diff
==
--- cfe/trunk/test/Driver/cloudabi.cpp (original)
+++ cfe/trunk/test/Driver/cloudabi.cpp Wed Apr  6 10:37:06 2016
@@ -1,8 +1,8 @@
 // RUN: %clangxx %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s 
-check-prefix=SAFESTACK
 // SAFESTACK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} 
"-ffunction-sections" "-fdata-sections" {{.*}} "-fsanitize=safe-stack"
-// SAFESTACK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" 
"crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc++" "-lc++abi" "-lunwind" "-lc" 
"-lcompiler_rt" "crtend.o"
+// SAFESTACK: "-Bstatic" "-pie" "--no-dynamic-linker" "-zrelro" 
"--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o"

Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-06 Thread Adrian Prantl via cfe-commits

> On Apr 6, 2016, at 8:16 AM, David Blaikie  wrote:
> 
> 
> 
> On Tue, Apr 5, 2016 at 10:17 PM, Eric Christopher via llvm-commits 
> mailto:llvm-comm...@lists.llvm.org>> wrote:
> echristo added inline comments.
> 
> 
> Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:477-479
> @@ -476,2 +476,5 @@
> +  unsigned DebugCUs = 0;
>for (MDNode *N : CU_Nodes->operands()) {
>  auto *CUNode = cast(N);
> +if (CUNode->getEmissionKind() == DICompileUnit::NoDebug)
> +  continue;
> 
> Instead of this pattern would it make more sense to have an iterator over the 
> nodes that checks for !NoDebug?
> 
> Yeah, that sounds like something that might be nice.
> 
> Adrian - I recall one of your initial ideas was to just have a different 
> named metadata node for these subprograms.

Huh. I think I had this idea in the context of collectDeadVariables (to collect 
dead subprograms), but I see how it would apply here, too.

> What was the motivation for not going with that plan? (which would've meant 
> these sort of loops would've remained OK, and only the loops in the verifier 
> and such would need to examine both nodes?) Perhaps this relates to your 
> comment about LTOing debug+nodebug CUs? I didn't quite follow what was wrong 
> with that in the first place & how this addresses it, could you explain it?

Most of the patches I’ve been committing recently are in preparation reversing 
the ownership between DICompileUnit and DISubprogram (which will help ThinLTO 
to lazy-load debug info).
DICompileUnit will no longer have a list of “subprograms:" and instead each 
DISubprogram will have a “unit:" field that points to the owning CU.

While it would be possible to leave the unit field empty and have a NamedMDNode 
hold on to these subprograms, having a mandatory “unit:" point to a CU that is 
explicitly marked NoDebug is a more regular and readable representation. It’s 
straightforward to verify and easier to debug especially in the LTO case.

-- adrian

>  
> 
> 
> Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1127-1128
> @@ -1115,3 +1126,4 @@
>if (!MMI->hasDebugInfo() || LScopes.empty() ||
> -  !MF->getFunction()->getSubprogram()) {
> +  !MF->getFunction()->getSubprogram() ||
> +  !SPMap.lookup(MF->getFunction()->getSubprogram())) {
>  // If we don't have a lexical scope for this function then there will
> 
> Comment.
> 
> 
> Repository:
>   rL LLVM
> 
> http://reviews.llvm.org/D18808 
> 
> 
> 
> ___
> llvm-commits mailing list
> llvm-comm...@lists.llvm.org 
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits 
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18369: [OpenCL] Upstreaming khronos OpenCL 1.2/2.0 header files.

2016-04-06 Thread Yaxun Liu via cfe-commits
yaxunl added a comment.

We need to discuss the layout of the header file.

For the builtin functions, I plan to follow the order of the spec and extension 
spec. If there are difference in 1.2 and 2.0, use condition macro.

For functions with double or half arguments, we have two options:

1. keep all functions with double arguments as one section, keep all functions 
with half arguments as another section. This is the current layout of 
opencl-20.h
2. keep functions with the same name together so that they follow the spec 
order.

Any suggestions? Thanks.


http://reviews.llvm.org/D18369



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


Re: [PATCH] D18369: [OpenCL] Upstreaming khronos OpenCL 1.2/2.0 header files.

2016-04-06 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

In http://reviews.llvm.org/D18369#393323, @yaxunl wrote:

> We need to discuss the layout of the header file.
>
> For the builtin functions, I plan to follow the order of the spec and 
> extension spec. If there are difference in 1.2 and 2.0, use condition macro.
>
> For functions with double or half arguments, we have two options:
>
> 1. keep all functions with double arguments as one section, keep all 
> functions with half arguments as another section. This is the current layout 
> of opencl-20.h
> 2. keep functions with the same name together so that they follow the spec 
> order.
>
>   Any suggestions? Thanks.


I am fine with either option actually.

Thanks,
Anastasia


http://reviews.llvm.org/D18369



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


Re: [PATCH] D18713: [OpenCL] Generate bitcast when target address space does not change.

2016-04-06 Thread Anastasia Stulova via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


http://reviews.llvm.org/D18713



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


Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-06 Thread Richard via cfe-commits
LegalizeAdulthood added a subscriber: LegalizeAdulthood.


Comment at: docs/clang-tidy/checks/modernize-use-bool-literals.rst:17
@@ +16,1 @@
+  std::ios_base::sync_with_stdio(false);
\ No newline at end of file


Please ensure the file ends with a newline.


Comment at: test/clang-tidy/modernize-use-bool-literals.cpp:3
@@ +2,3 @@
+
+bool bar1 = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: implicitly converting integer 
literal to bool, use bool literal instead [modernize-use-bool-literals]

There is more initialization syntax than just assignment.  Here are the ones I 
can think of:

What happens when I write `bool foo{1};` or `bool foo(1);`?

What happens when I write:

```
class foo {
public:
  foo() : b(0) {}
  foo(int) : b{0} {}
private:
  bool b;
  bool c{0};
  bool d(0);
  bool e = 0;
};
```

Should we warn an a `bool` is initialized by a call to a `constexpr` function 
that returns an integral type?


http://reviews.llvm.org/D18745



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


Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-06 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a comment.

In http://reviews.llvm.org/D18745#391210, @Prazek wrote:

> In http://reviews.llvm.org/D18745#390739, @Eugene.Zelenko wrote:
>
> > Isn't readability-implicit-bool-cast¶ should catch such issues? If not, I 
> > think will be good idea to improve that check instead of introducing new 
> > one.
>
>
> I wouldn't add this functionality there. I see that 
> readability-implicit-bool-cast aims much different problem.


We have a lot of casts related checks, so may be will be good idea to introduce 
dedicated group for such them?


http://reviews.llvm.org/D18745



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


r265557 - clang-format: Fix label-in-if statement in macros where it is actually used.

2016-04-06 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Apr  6 11:41:39 2016
New Revision: 265557

URL: http://llvm.org/viewvc/llvm-project?rev=265557&view=rev
Log:
clang-format: Fix label-in-if statement in macros where it is actually used.

Before:
  #define A \
if (a)  \
label:  \
f()

After:
  #define A \
if (a)  \
label:  \
  f()

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=265557&r1=265556&r2=265557&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Apr  6 11:41:39 2016
@@ -1573,8 +1573,10 @@ void UnwrappedLineParser::parseLabel() {
 addUnwrappedLine();
   }
   Line->Level = OldLineLevel;
-  if (FormatTok->isNot(tok::l_brace))
+  if (FormatTok->isNot(tok::l_brace)) {
 parseStructuralElement();
+addUnwrappedLine();
+  }
 }
 
 void UnwrappedLineParser::parseCaseLabel() {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=265557&r1=265556&r2=265557&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Apr  6 11:41:39 2016
@@ -296,6 +296,7 @@ TEST_F(FormatTest, FormatIfWithoutCompou
   verifyFormat("if (a)\n  if (b) {\nf();\n  }\ng();");
 
   FormatStyle AllowsMergedIf = getLLVMStyle();
+  AllowsMergedIf.AlignEscapedNewlinesLeft = true;
   AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
   verifyFormat("if (a)\n"
"  // comment\n"
@@ -307,6 +308,11 @@ TEST_F(FormatTest, FormatIfWithoutCompou
"f();\n"
"}",
AllowsMergedIf);
+  verifyFormat("#define A \\\n"
+   "  if (a)  \\\n"
+   "  label:  \\\n"
+   "f()",
+   AllowsMergedIf);
   verifyFormat("if (a)\n"
"  ;",
AllowsMergedIf);


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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

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

There are some APIs where a series of strings are passed as a single `char *` 
with NUL separators between the strings and the last string is indicated by two 
NUL characters in a row.  For instance, see the MSDN documentation 

 for the `lpDependencies` argument to `CreateService` 
.
  Such strings literals in the code look like:

  LPCTSTR dependencies = _T("one\0two\0three\0four\0");

I don't see any annotation on this argument in `` where this function 
is declared, so there's no hint from the header about this argument.  In this 
case, the biggest mistake people make is omitting the final NUL character, 
thinking that the `\0` acts as a string separator and not a terminator:

  LPCTSTR dependencies = _T("one\0two\0three\0four");

If you're lucky this results in a crash right away.  If you're unlucky the 
compiler placed this constant in an area of memory with zero padding and it 
works by accident on your machine until it ships to a customer and then breaks 
on their machine mysteriously.

I was never a fan of these magic string array arguments and they mostly appear 
in the older portions of the Win32 API, but they are there nonetheless.  I 
would hate for this check to signal a bunch of false positives on such strings.


http://reviews.llvm.org/D18783



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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb added a comment.

In http://reviews.llvm.org/D18783#393367, @LegalizeAdulthood wrote:

> There are some APIs where a series of strings are passed as a single `char *` 
> with NUL separators between the strings and the last string is indicated by 
> two NUL characters in a row.  For instance, see the MSDN documentation 
> 
>  for the `lpDependencies` argument to `CreateService` 
> .
>   Such strings literals in the code look like:
>
>   LPCTSTR dependencies = _T("one\0two\0three\0four\0");
>
>
> I don't see any annotation on this argument in `` where this 
> function is declared, so there's no hint from the header about this argument. 
>  In this case, the biggest mistake people make is omitting the final NUL 
> character, thinking that the `\0` acts as a string separator and not a 
> terminator:
>
>   LPCTSTR dependencies = _T("one\0two\0three\0four");
>
>
> If you're lucky this results in a crash right away.  If you're unlucky the 
> compiler placed this constant in an area of memory with zero padding and it 
> works by accident on your machine until it ships to a customer and then 
> breaks on their machine mysteriously.
>
> I was never a fan of these magic string array arguments and they mostly 
> appear in the older portions of the Win32 API, but they are there 
> nonetheless.  I would hate for this check to signal a bunch of false 
> positives on such strings.


I know about these kind functions, and they are not covered by the current 
state of this check.
The current check only apply if there is a conversion from char* -> std::string 
(implicit constructor).
For now, I want to keep the false-positive ratio low.

I made a prototype to detect instances passed to 'func(char*)' but there are 
too many false-positives.


http://reviews.llvm.org/D18783



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


Re: [PATCH] D17821: [OpenCL] Complete image types support

2016-04-06 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

Regarding, extending this approach for OpenCL pipe types too. I was thinking we 
could change current implementation to have ReadPipeType and WritePipeType. 
They can both be derived from PipeType that we already have now (we can make it 
an abstract class to avoid its instantiation?).

Similarly to images, since read and write pipes will be mapped to different 
Clang types, we won't need any extra semantical checking but just need to add 
extra code in CodeGen of pipe type and builtins to accept two separate types 
for read only and write only cases.

Would this make sense?



Comment at: include/clang/AST/ASTContext.h:903
@@ +902,3 @@
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
+  CanQualType SingletonId;
+#include "clang/AST/OpenCLImageTypes.def"

bader wrote:
> mgrang wrote:
> > remove extra spacing in front of the \
> Sorry for delay...
> I used clang-format tool to format that code. I expect it to be in agreement 
> with LLVM coding style guide.
> Did I miss something or it's clang-format bug?
I would have thought clang-format should be fine.

But it does look a bit weird here. There are other places in this patch that 
have the same formatting.

I can't find anything relevant in coding style description:
http://llvm.org/docs/CodingStandards.html#source-code-width




http://reviews.llvm.org/D17821



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


r265569 - NFC: make AtomicOrdering an enum class

2016-04-06 Thread JF Bastien via cfe-commits
Author: jfb
Date: Wed Apr  6 12:26:42 2016
New Revision: 265569

URL: http://llvm.org/viewvc/llvm-project?rev=265569&view=rev
Log:
NFC: make AtomicOrdering an enum class

Summary: See LLVM change D18775 for details, this change depends on it.

Reviewers: jyknight, reames

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=265569&r1=265568&r2=265569&view=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Wed Apr  6 12:26:42 2016
@@ -221,11 +221,13 @@ namespace {
 /// \param IsWeak true if atomic operation is weak, false otherwise.
 /// \returns Pair of values: previous value from storage (value type) and
 /// boolean flag (i1 type) with true if success and false otherwise.
-std::pair EmitAtomicCompareExchange(
-RValue Expected, RValue Desired,
-llvm::AtomicOrdering Success = llvm::SequentiallyConsistent,
-llvm::AtomicOrdering Failure = llvm::SequentiallyConsistent,
-bool IsWeak = false);
+std::pair
+EmitAtomicCompareExchange(RValue Expected, RValue Desired,
+  llvm::AtomicOrdering Success =
+  llvm::AtomicOrdering::SequentiallyConsistent,
+  llvm::AtomicOrdering Failure =
+  llvm::AtomicOrdering::SequentiallyConsistent,
+  bool IsWeak = false);
 
 /// \brief Emits atomic update.
 /// \param AO Atomic ordering.
@@ -260,13 +262,17 @@ namespace {
 /// \brief Emits atomic compare-and-exchange op as a libcall.
 llvm::Value *EmitAtomicCompareExchangeLibcall(
 llvm::Value *ExpectedAddr, llvm::Value *DesiredAddr,
-llvm::AtomicOrdering Success = llvm::SequentiallyConsistent,
-llvm::AtomicOrdering Failure = llvm::SequentiallyConsistent);
+llvm::AtomicOrdering Success =
+llvm::AtomicOrdering::SequentiallyConsistent,
+llvm::AtomicOrdering Failure =
+llvm::AtomicOrdering::SequentiallyConsistent);
 /// \brief Emits atomic compare-and-exchange op as LLVM instruction.
 std::pair EmitAtomicCompareExchangeOp(
 llvm::Value *ExpectedVal, llvm::Value *DesiredVal,
-llvm::AtomicOrdering Success = llvm::SequentiallyConsistent,
-llvm::AtomicOrdering Failure = llvm::SequentiallyConsistent,
+llvm::AtomicOrdering Success =
+llvm::AtomicOrdering::SequentiallyConsistent,
+llvm::AtomicOrdering Failure =
+llvm::AtomicOrdering::SequentiallyConsistent,
 bool IsWeak = false);
 /// \brief Emit atomic update as libcalls.
 void
@@ -289,17 +295,17 @@ namespace {
 AtomicExpr::AtomicOrderingKind
 AtomicInfo::translateAtomicOrdering(const llvm::AtomicOrdering AO) {
   switch (AO) {
-  case llvm::Unordered:
-  case llvm::NotAtomic:
-  case llvm::Monotonic:
+  case llvm::AtomicOrdering::Unordered:
+  case llvm::AtomicOrdering::NotAtomic:
+  case llvm::AtomicOrdering::Monotonic:
 return AtomicExpr::AO_ABI_memory_order_relaxed;
-  case llvm::Acquire:
+  case llvm::AtomicOrdering::Acquire:
 return AtomicExpr::AO_ABI_memory_order_acquire;
-  case llvm::Release:
+  case llvm::AtomicOrdering::Release:
 return AtomicExpr::AO_ABI_memory_order_release;
-  case llvm::AcquireRelease:
+  case llvm::AtomicOrdering::AcquireRelease:
 return AtomicExpr::AO_ABI_memory_order_acq_rel;
-  case llvm::SequentiallyConsistent:
+  case llvm::AtomicOrdering::SequentiallyConsistent:
 return AtomicExpr::AO_ABI_memory_order_seq_cst;
   }
   llvm_unreachable("Unhandled AtomicOrdering");
@@ -431,14 +437,14 @@ static void emitAtomicCmpXchgFailureSet(
   if (llvm::ConstantInt *FO = dyn_cast(FailureOrderVal)) {
 switch (FO->getSExtValue()) {
 default:
-  FailureOrder = llvm::Monotonic;
+  FailureOrder = llvm::AtomicOrdering::Monotonic;
   break;
 case AtomicExpr::AO_ABI_memory_order_consume:
 case AtomicExpr::AO_ABI_memory_order_acquire:
-  FailureOrder = llvm::Acquire;
+  FailureOrder = llvm::AtomicOrdering::Acquire;
   break;
 case AtomicExpr::AO_ABI_memory_order_seq_cst:
-  FailureOrder = llvm::SequentiallyConsistent;
+  FailureOrder = llvm::AtomicOrdering::SequentiallyConsistent;
   break;
 }
 if (FailureOrder >= SuccessOrder) {
@@ -455,9 +461,10 @@ static void emitAtomicCmpXchgFailureSet(
   llvm::BasicBlock *Monotonic

Re: [PATCH] D18776: NFC: make AtomicOrdering an enum class

2016-04-06 Thread JF Bastien via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL265569: NFC: make AtomicOrdering an enum class (authored by 
jfb).

Changed prior to commit:
  http://reviews.llvm.org/D18776?vs=52637&id=52820#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18776

Files:
  cfe/trunk/lib/CodeGen/CGAtomic.cpp
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/lib/CodeGen/CGExprScalar.cpp
  cfe/trunk/lib/CodeGen/CGObjC.cpp
  cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
  cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp

Index: cfe/trunk/lib/CodeGen/CGAtomic.cpp
===
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp
@@ -221,11 +221,13 @@
 /// \param IsWeak true if atomic operation is weak, false otherwise.
 /// \returns Pair of values: previous value from storage (value type) and
 /// boolean flag (i1 type) with true if success and false otherwise.
-std::pair EmitAtomicCompareExchange(
-RValue Expected, RValue Desired,
-llvm::AtomicOrdering Success = llvm::SequentiallyConsistent,
-llvm::AtomicOrdering Failure = llvm::SequentiallyConsistent,
-bool IsWeak = false);
+std::pair
+EmitAtomicCompareExchange(RValue Expected, RValue Desired,
+  llvm::AtomicOrdering Success =
+  llvm::AtomicOrdering::SequentiallyConsistent,
+  llvm::AtomicOrdering Failure =
+  llvm::AtomicOrdering::SequentiallyConsistent,
+  bool IsWeak = false);
 
 /// \brief Emits atomic update.
 /// \param AO Atomic ordering.
@@ -260,13 +262,17 @@
 /// \brief Emits atomic compare-and-exchange op as a libcall.
 llvm::Value *EmitAtomicCompareExchangeLibcall(
 llvm::Value *ExpectedAddr, llvm::Value *DesiredAddr,
-llvm::AtomicOrdering Success = llvm::SequentiallyConsistent,
-llvm::AtomicOrdering Failure = llvm::SequentiallyConsistent);
+llvm::AtomicOrdering Success =
+llvm::AtomicOrdering::SequentiallyConsistent,
+llvm::AtomicOrdering Failure =
+llvm::AtomicOrdering::SequentiallyConsistent);
 /// \brief Emits atomic compare-and-exchange op as LLVM instruction.
 std::pair EmitAtomicCompareExchangeOp(
 llvm::Value *ExpectedVal, llvm::Value *DesiredVal,
-llvm::AtomicOrdering Success = llvm::SequentiallyConsistent,
-llvm::AtomicOrdering Failure = llvm::SequentiallyConsistent,
+llvm::AtomicOrdering Success =
+llvm::AtomicOrdering::SequentiallyConsistent,
+llvm::AtomicOrdering Failure =
+llvm::AtomicOrdering::SequentiallyConsistent,
 bool IsWeak = false);
 /// \brief Emit atomic update as libcalls.
 void
@@ -289,17 +295,17 @@
 AtomicExpr::AtomicOrderingKind
 AtomicInfo::translateAtomicOrdering(const llvm::AtomicOrdering AO) {
   switch (AO) {
-  case llvm::Unordered:
-  case llvm::NotAtomic:
-  case llvm::Monotonic:
+  case llvm::AtomicOrdering::Unordered:
+  case llvm::AtomicOrdering::NotAtomic:
+  case llvm::AtomicOrdering::Monotonic:
 return AtomicExpr::AO_ABI_memory_order_relaxed;
-  case llvm::Acquire:
+  case llvm::AtomicOrdering::Acquire:
 return AtomicExpr::AO_ABI_memory_order_acquire;
-  case llvm::Release:
+  case llvm::AtomicOrdering::Release:
 return AtomicExpr::AO_ABI_memory_order_release;
-  case llvm::AcquireRelease:
+  case llvm::AtomicOrdering::AcquireRelease:
 return AtomicExpr::AO_ABI_memory_order_acq_rel;
-  case llvm::SequentiallyConsistent:
+  case llvm::AtomicOrdering::SequentiallyConsistent:
 return AtomicExpr::AO_ABI_memory_order_seq_cst;
   }
   llvm_unreachable("Unhandled AtomicOrdering");
@@ -431,14 +437,14 @@
   if (llvm::ConstantInt *FO = dyn_cast(FailureOrderVal)) {
 switch (FO->getSExtValue()) {
 default:
-  FailureOrder = llvm::Monotonic;
+  FailureOrder = llvm::AtomicOrdering::Monotonic;
   break;
 case AtomicExpr::AO_ABI_memory_order_consume:
 case AtomicExpr::AO_ABI_memory_order_acquire:
-  FailureOrder = llvm::Acquire;
+  FailureOrder = llvm::AtomicOrdering::Acquire;
   break;
 case AtomicExpr::AO_ABI_memory_order_seq_cst:
-  FailureOrder = llvm::SequentiallyConsistent;
+  FailureOrder = llvm::AtomicOrdering::SequentiallyConsistent;
   break;
 }
 if (FailureOrder >= SuccessOrder) {
@@ -455,9 +461,10 @@
   llvm::BasicBlock *MonotonicBB = nullptr, *AcquireBB = nullptr,
*SeqCstBB = nullptr;
   MonotonicBB = CGF.createBasicBlock("monotonic_fail", CGF.CurFn);
-  if (SuccessOrder != llvm::Monotonic && SuccessOrder != llvm::Release)
+  if (SuccessOrder != llvm::AtomicOrdering::Monotonic &&
+  SuccessOrder != llvm::AtomicOrdering::Release)
 AcquireBB = CGF.createBasic

r265571 - Diagnose template alias declarations in local classes.

2016-04-06 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Apr  6 12:38:58 2016
New Revision: 265571

URL: http://llvm.org/viewvc/llvm-project?rev=265571&view=rev
Log:
Diagnose template alias declarations in local classes.

Patch by Erik Pilkington!

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p2.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=265571&r1=265570&r2=265571&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Apr  6 12:38:58 2016
@@ -8585,6 +8585,10 @@ Decl *Sema::ActOnAliasDeclaration(Scope
 }
 TemplateParameterList *TemplateParams = TemplateParamLists[0];
 
+// Check that we can declare a template here.
+if (CheckTemplateDeclScope(S, TemplateParams))
+  return nullptr;
+
 // Only consider previous declarations in the same scope.
 FilterLookupForScope(Previous, CurContext, S, /*ConsiderLinkage*/false,
  /*ExplicitInstantiationOrSpecialization*/false);

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p2.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p2.cpp?rev=265571&r1=265570&r2=265571&view=diff
==
--- cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p2.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.mem/p2.cpp Wed Apr  6 12:38:58 2016
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
 
 template 
 void quux();
@@ -8,5 +8,7 @@ void fun() {
 template  struct bar {};  // expected-error{{templates cannot be 
declared inside of a local class}}
 template  void baz() {}   // expected-error{{templates cannot be 
declared inside of a local class}}
 template  void qux(); // expected-error{{templates cannot be 
declared inside of a local class}}
+template  using corge = int; // expected-error{{templates cannot 
be declared inside of a local class}}
+template  static T grault; // expected-error{{static data 
member}} expected-error{{templates cannot be declared inside of a local class}}
   };
 }


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


Re: [PATCH] D18653: [Sema] Diagnose template alias declaration in local class

2016-04-06 Thread Richard Smith via cfe-commits
rsmith closed this revision.
rsmith added a comment.

Landed as r265571.


http://reviews.llvm.org/D18653



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


[PATCH] D18833: [clang-tidy] Fix infinite loop in MisplacedWideningCastCheck.

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.

In Release mode, the check was infinite looping over chromium code base.

It seems there is something strange with the creation of the Maps.
I believe the compiler is making some assumption with the implicit conversion 
from enum <-> int.

By moving the map to a standard switch/cases, we no longer allocate memory and 
we can keep the same behavior. For a small amount of elements, this is fine.

http://reviews.llvm.org/D18833

Files:
  clang-tidy/misc/MisplacedWideningCastCheck.cpp

Index: clang-tidy/misc/MisplacedWideningCastCheck.cpp
===
--- clang-tidy/misc/MisplacedWideningCastCheck.cpp
+++ clang-tidy/misc/MisplacedWideningCastCheck.cpp
@@ -10,7 +10,6 @@
 #include "MisplacedWideningCastCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "llvm/ADT/DenseMap.h"
 
 using namespace clang::ast_matchers;
 
@@ -29,18 +28,19 @@
 }
 
 void MisplacedWideningCastCheck::registerMatchers(MatchFinder *Finder) {
-  auto Calc = expr(anyOf(binaryOperator(anyOf(
- hasOperatorName("+"), hasOperatorName("-"),
- hasOperatorName("*"), hasOperatorName("<<"))),
- unaryOperator(hasOperatorName("~"))),
-   hasType(isInteger()))
-  .bind("Calc");
+  const auto Calc =
+  expr(anyOf(binaryOperator(
+ anyOf(hasOperatorName("+"), hasOperatorName("-"),
+   hasOperatorName("*"), hasOperatorName("<<"))),
+ unaryOperator(hasOperatorName("~"))),
+   hasType(isInteger()))
+  .bind("Calc");
 
-  auto ExplicitCast =
+  const auto ExplicitCast =
   explicitCastExpr(hasDestinationType(isInteger()), has(Calc));
-  auto ImplicitCast =
+  const auto ImplicitCast =
   implicitCastExpr(hasImplicitDestinationType(isInteger()), has(Calc));
-  auto Cast = expr(anyOf(ExplicitCast, ImplicitCast)).bind("Cast");
+  const auto Cast = expr(anyOf(ExplicitCast, ImplicitCast)).bind("Cast");
 
   Finder->addMatcher(varDecl(hasInitializer(Cast)), this);
   Finder->addMatcher(returnStmt(hasReturnValue(Cast)), this);
@@ -50,20 +50,19 @@
   binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!="),
hasOperatorName("<"), hasOperatorName("<="),
hasOperatorName(">"), hasOperatorName(">=")),
- anyOf(hasLHS(Cast), hasRHS(Cast))),
+ hasEitherOperand(Cast)),
   this);
 }
 
-static unsigned getMaxCalculationWidth(ASTContext &Context, const Expr *E) {
+static unsigned getMaxCalculationWidth(const ASTContext &Context,
+   const Expr *E) {
   E = E->IgnoreParenImpCasts();
 
   if (const auto *Bop = dyn_cast(E)) {
 unsigned LHSWidth = getMaxCalculationWidth(Context, Bop->getLHS());
 unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS());
-if (Bop->getOpcode() == BO_Mul)
-  return LHSWidth + RHSWidth;
-if (Bop->getOpcode() == BO_Add)
-  return std::max(LHSWidth, RHSWidth) + 1;
+if (Bop->getOpcode() == BO_Mul) return LHSWidth + RHSWidth;
+if (Bop->getOpcode() == BO_Add) return std::max(LHSWidth, RHSWidth) + 1;
 if (Bop->getOpcode() == BO_Rem) {
   llvm::APSInt Val;
   if (Bop->getRHS()->EvaluateAsInt(Val, Context))
@@ -82,8 +81,7 @@
 }
   } else if (const auto *Uop = dyn_cast(E)) {
 // There is truncation when ~ is used.
-if (Uop->getOpcode() == UO_Not)
-  return 1024U;
+if (Uop->getOpcode() == UO_Not) return 1024U;
 
 QualType T = Uop->getType();
 return T->isIntegerType() ? Context.getIntWidth(T) : 1024U;
@@ -94,111 +92,134 @@
   return Context.getIntWidth(E->getType());
 }
 
-static llvm::SmallDenseMap createRelativeIntSizesMap() {
-  llvm::SmallDenseMap Result(14);
-  Result[BuiltinType::UChar] = 1;
-  Result[BuiltinType::SChar] = 1;
-  Result[BuiltinType::Char_U] = 1;
-  Result[BuiltinType::Char_S] = 1;
-  Result[BuiltinType::UShort] = 2;
-  Result[BuiltinType::Short] = 2;
-  Result[BuiltinType::UInt] = 3;
-  Result[BuiltinType::Int] = 3;
-  Result[BuiltinType::ULong] = 4;
-  Result[BuiltinType::Long] = 4;
-  Result[BuiltinType::ULongLong] = 5;
-  Result[BuiltinType::LongLong] = 5;
-  Result[BuiltinType::UInt128] = 6;
-  Result[BuiltinType::Int128] = 6;
-  return Result;
-}
-
-static llvm::SmallDenseMap createRelativeCharSizesMap() {
-  llvm::SmallDenseMap Result(6);
-  Result[BuiltinType::UChar] = 1;
-  Result[BuiltinType::SChar] = 1;
-  Result[BuiltinType::Char_U] = 1;
-  Result[BuiltinType::Char_S] = 1;
-  Result[BuiltinType::Char16] = 2;
-  Result[BuiltinType::Char32] = 3;
-  return Result;
-}
-
-static llvm::SmallDenseMap createRelativeCharSizesWMap() {
-  llvm::SmallDenseMap Result(6);
-  Result[BuiltinType::UChar] = 1;
-  Resu

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

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.
etienneb added a comment.

I like this :)


http://reviews.llvm.org/D18509



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


Re: [PATCH] D17821: [OpenCL] Complete image types support

2016-04-06 Thread Alexey Bader via cfe-commits
bader added a comment.

In http://reviews.llvm.org/D17821#393387, @Anastasia wrote:

> Regarding, extending this approach for OpenCL pipe types too. I was thinking 
> we could change current implementation to have ReadPipeType and 
> WritePipeType. They can both be derived from PipeType that we already have 
> now (we can make it an abstract class to avoid its instantiation?).
>
> Similarly to images, since read and write pipes will be mapped to different 
> Clang types, we won't need any extra semantical checking but just need to add 
> extra code in CodeGen of pipe type and builtins to accept two separate types 
> for read only and write only cases.
>
> Would this make sense?


Sure. Do you want me to add it here or it's okay if we fix pipes in a separate 
patch?



Comment at: include/clang/AST/ASTContext.h:903
@@ +902,3 @@
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix)   
\
+  CanQualType SingletonId;
+#include "clang/AST/OpenCLImageTypes.def"

Anastasia wrote:
> bader wrote:
> > mgrang wrote:
> > > remove extra spacing in front of the \
> > Sorry for delay...
> > I used clang-format tool to format that code. I expect it to be in 
> > agreement with LLVM coding style guide.
> > Did I miss something or it's clang-format bug?
> I would have thought clang-format should be fine.
> 
> But it does look a bit weird here. There are other places in this patch that 
> have the same formatting.
> 
> I can't find anything relevant in coding style description:
> http://llvm.org/docs/CodingStandards.html#source-code-width
> 
> 
I'll remove extra spacing.


http://reviews.llvm.org/D17821



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


Re: [PATCH] D18821: Add modernize-bool-to-integer-conversion

2016-04-06 Thread Krystyna via cfe-commits
krystyna added inline comments.


Comment at: docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst:9
@@ +8,3 @@
+.. code-block:: C++
+  int a = false
+  vector v(true); // Makes vector of one element

int a = false;


http://reviews.llvm.org/D18821



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


Re: [PATCH] D18551: Added Fixer implementation and fix() interface in clang-format for removing redundant code.

2016-04-06 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 52832.
ioeric marked 4 inline comments as done.
ioeric added a comment.

- Change implementation of fixer to iterate by lines. TODO: refactor Formatter 
and Fixer to reduce duplication.


http://reviews.llvm.org/D18551

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/TokenAnnotator.h
  unittests/Format/CMakeLists.txt
  unittests/Format/FixTest.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11274,6 +11274,44 @@
   Code, formatReplacements(Code, Replaces, Style)));
 }
 
+TEST_F(ReplacementTest, FixCodeAfterReplacements) {
+  std::string Code = "class A {\n"
+ "  A() : X(0), Y(0) { }\n"
+ "};";
+  std::string Expected = "class A {\n"
+ "  A() : X(0) {}\n"
+ "};";
+  FileID ID = Context.createInMemoryFile("format.cpp", Code);
+  tooling::Replacements Replaces;
+  Replaces.insert(tooling::Replacement(
+  Context.Sources, Context.getLocation(ID, 2, 15), 4, ""));
+
+  format::FormatStyle Style = format::getLLVMStyle();
+  auto FinalReplaces =
+  formatReplacements(Code, fixReplacements(Code, Replaces, Style), Style);
+  EXPECT_EQ(Expected, applyAllReplacements(Code, FinalReplaces));
+}
+
+TEST_F(ReplacementTest, DoNotReformatCodeNotAffectedByReplacements) {
+  std::string Code = "class A {\n"
+ "  A() : X(0), Y(0) {}\n"
+ "  f( intx)= 0;"
+ "};";
+  std::string Expected = "class A {\n"
+ "  A() : X(0) {}\n"
+ "  f( intx)= 0;"
+ "};";
+  FileID ID = Context.createInMemoryFile("format.cpp", Code);
+  tooling::Replacements Replaces;
+  Replaces.insert(tooling::Replacement(Context.Sources,
+   Context.getLocation(ID, 2, 15), 4, ""));
+
+  format::FormatStyle Style = format::getLLVMStyle();
+  auto FinalReplaces =
+  formatReplacements(Code, fixReplacements(Code, Replaces, Style), Style);
+  EXPECT_EQ(Expected, applyAllReplacements(Code, FinalReplaces));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: unittests/Format/FixTest.cpp
===
--- /dev/null
+++ unittests/Format/FixTest.cpp
@@ -0,0 +1,195 @@
+//===- unittest/Format/FixTest.cpp - Code fixing unit tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "clang/Tooling/Core/Replacement.h"
+
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace format {
+namespace {
+
+class FixTest : public ::testing::Test {
+protected:
+  std::string fix(llvm::StringRef Code,
+  const std::vector &Ranges,
+  const FormatStyle &Style = getLLVMStyle()) {
+tooling::Replacements Replaces = format::fix(Style, Code, Ranges);
+
+std::string Result = applyAllReplacements(Code, Replaces);
+EXPECT_NE("", Result);
+return Result;
+  }
+};
+
+TEST_F(FixTest, CtorInitializationSimpleRedundantComma) {
+  std::string Code = "class A {\nA() : , {} };";
+  std::string Expected = "class A {\nA()  {} };";
+  std::vector Ranges;
+  Ranges.push_back(tooling::Range(17, 0));
+  Ranges.push_back(tooling::Range(19, 0));
+  std::string Result = fix(Code, Ranges);
+  EXPECT_EQ(Expected, Result);
+
+  Code = "class A {\nA() : x(1), {} };";
+  Expected = "class A {\nA() : x(1) {} };";
+  Ranges.clear();
+  Ranges.push_back(tooling::Range(23, 0));
+  Result = fix(Code, Ranges);
+  EXPECT_EQ(Expected, Result);
+}
+
+TEST_F(FixTest, CtorInitializationBracesInParens) {
+  std::string Code = "class A {\nA() : x({1}),, {} };";
+  std::string Expected = "class A {\nA() : x({1}) {} };";
+  std::vector Ranges;
+  Ranges.push_back(tooling::Range(24, 0));
+  Ranges.push_back(tooling::Range(26, 0));
+  std::string Result = fix(Code, Ranges);
+  EXPECT_EQ(Expected, Result);
+}
+
+TEST_F(FixTest, RedundantCommaNotInAffectedRanges) {
+  std::string Code =
+  "class A {\nA() : x({1}), /* comment */, { int x = 0; } };";
+  std::string Expected =
+  "class A {\nA() : x({1}), /* comment */, { int x = 0; } };";
+  // Set the affected range to be "int x = 0", which does not intercept the
+  // constructor initialization list.
+  std::vector Ranges(1, tooling::Range(42, 9));
+  std::string Result = fix(Code, Ranges);
+  EXPECT_EQ(Expected, Result);
+
+  Code = "class A {\nA() : x(1), {} };";
+ 

Re: [PATCH] D18073: Add memory allocating functions

2016-04-06 Thread Alexander Riccio via cfe-commits
ariccio added a comment.

In http://reviews.llvm.org/D18073#392972, @zaks.anna wrote:

> > So for _wcsdup_dbg, I should leave only testWinWcsdupDbg?
>
>
> Yes.


Ok, that I can do. Will upload patch later this afternoon/tonight.

In http://reviews.llvm.org/D18073#392972, @zaks.anna wrote:

> Also, since there will be many of these "alternate" functions, could you 
> create a separate test file for them?


But, that contradicts removing them? Huh?


http://reviews.llvm.org/D18073



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


r265592 - Restore slightly less dodgy diagnostic handler for inline asm

2016-04-06 Thread Tim Northover via cfe-commits
Author: tnorthover
Date: Wed Apr  6 14:58:07 2016
New Revision: 265592

URL: http://llvm.org/viewvc/llvm-project?rev=265592&view=rev
Log:
Restore slightly less dodgy diagnostic handler for inline asm

Turns out it was there mostly to prevent Clang asking people to report a bug.
This time we report something to Clang's real diagnostics handler so that it
exits with something approximating a real error and tidies up after itself.

Modified:
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
cfe/trunk/test/CodeGen/asm-errors.c

Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=265592&r1=265591&r2=265592&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Wed Apr  6 14:58:07 2016
@@ -756,6 +756,28 @@ CodeGenAction::CreateASTConsumer(Compile
   return std::move(Result);
 }
 
+static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM,
+ void *Context,
+ unsigned LocCookie) {
+  SM.print(nullptr, llvm::errs());
+
+  auto Diags = static_cast(Context);
+  unsigned DiagID;
+  switch (SM.getKind()) {
+  case llvm::SourceMgr::DK_Error:
+DiagID = diag::err_fe_inline_asm;
+break;
+  case llvm::SourceMgr::DK_Warning:
+DiagID = diag::warn_fe_inline_asm;
+break;
+  case llvm::SourceMgr::DK_Note:
+DiagID = diag::note_fe_inline_asm;
+break;
+  }
+
+  Diags->Report(DiagID).AddString("cannot compile inline asm");
+}
+
 void CodeGenAction::ExecuteAction() {
   // If this is an IR file, we have to treat it specially.
   if (getCurrentFileKind() == IK_LLVM_IR) {
@@ -804,6 +826,9 @@ void CodeGenAction::ExecuteAction() {
   TheModule->setTargetTriple(TargetOpts.Triple);
 }
 
+LLVMContext &Ctx = TheModule->getContext();
+Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,
+  &CI.getDiagnostics());
 EmitBackendOutput(CI.getDiagnostics(), CI.getCodeGenOpts(), TargetOpts,
   CI.getLangOpts(), CI.getTarget().getDataLayout(),
   TheModule.get(), BA, OS);

Modified: cfe/trunk/test/CodeGen/asm-errors.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asm-errors.c?rev=265592&r1=265591&r2=265592&view=diff
==
--- cfe/trunk/test/CodeGen/asm-errors.c (original)
+++ cfe/trunk/test/CodeGen/asm-errors.c Wed Apr  6 14:58:07 2016
@@ -2,11 +2,11 @@
 
 // RUN: not %clang_cc1 -triple i386-apple-darwin10 -emit-obj %s -o /dev/null > 
%t 2>&1
 // RUN: FileCheck %s < %t
-// RUN: %clang_cc1 -triple i386-apple-darwin10 -emit-llvm-bc %s -o %t.bc
-// RUN: not %clang_cc1 -triple i386-apple-darwin10 -emit-obj %t.bc -o 
/dev/null 2>&1 | \
+// RUN: not %clang -target i386-apple-darwin10 -fembed-bitcode -c %s -o 
/dev/null 2>&1 | \
 // RUN:   FileCheck --check-prefix=CRASH-REPORT %s
 // CRASH-REPORT: :
 // CRASH-REPORT: error: invalid instruction mnemonic 'abc'
+// CRASH-REPORT: error: cannot compile inline asm
 // CRASH-REPORT-NOT: note: diagnostic msg:
 
 int test1(int X) {


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


Re: r265038 - Diagnostics: remove dodgy handler for bitcode inlineasm diagnostics.

2016-04-06 Thread Tim Northover via cfe-commits
> Generally good. How about only report error when SM.getKind() == DK_Error?

Good idea. I've committed it with more flexible diagnostic kinds as r265592.

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


Re: [PATCH] D18073: Add memory allocating functions

2016-04-06 Thread Anna Zaks via cfe-commits
zaks.anna added a comment.

You will have to add one test function to smoke test that the newly added API 
is modeled correctly. We also have a lot of existing tests that verify that 
each of the original APIs (malloc. free, new) function correctly in all 
possible settings. What is the contradiction in asking to add the smoke tests 
in a separate file?


http://reviews.llvm.org/D18073



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


Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-06 Thread Adrian Prantl via cfe-commits
aprantl removed rL LLVM as the repository for this revision.
aprantl updated this revision to Diff 52842.
aprantl added a comment.

This patch adds a DICompileUnit iterator to Module that skips over NoDebug CUs.


http://reviews.llvm.org/D18808

Files:
  include/llvm/IR/DIBuilder.h
  include/llvm/IR/DebugInfo.h
  include/llvm/IR/Module.h
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  lib/IR/DIBuilder.cpp
  lib/IR/DebugInfo.cpp
  lib/IR/Module.cpp
  test/DebugInfo/X86/mixed-nodebug-cu.ll
  tools/clang/lib/CodeGen/CGDebugInfo.cpp
  tools/clang/test/Frontend/optimization-remark.c
  tools/clang/test/Frontend/profile-sample-use-loc-tracking.c
  tools/opt/BreakpointPrinter.cpp

Index: tools/clang/test/Frontend/profile-sample-use-loc-tracking.c
===
--- tools/clang/test/Frontend/profile-sample-use-loc-tracking.c
+++ tools/clang/test/Frontend/profile-sample-use-loc-tracking.c
@@ -10,9 +10,10 @@
 // CHECK: , !dbg !
 // CHECK-NOT: DW_TAG_base_type
 
-// But llvm.dbg.cu should be missing (to prevent writing debug info to
+// The CU should be marked NoDebug (to prevent writing debug info to
 // the final output).
-// CHECK-NOT: !llvm.dbg.cu = !{
+// CHECK: !llvm.dbg.cu = !{![[CU:.*]]}
+// CHECK: ![[CU]] = distinct !DICompileUnit({{.*}}emissionKind: NoDebug
 
 int bar(int j) {
   return (j + j - 2) * (j - 2) * j;
Index: tools/clang/test/Frontend/optimization-remark.c
===
--- tools/clang/test/Frontend/optimization-remark.c
+++ tools/clang/test/Frontend/optimization-remark.c
@@ -27,9 +27,10 @@
 // CHECK: , !dbg !
 // CHECK-NOT: DW_TAG_base_type
 
-// But llvm.dbg.cu should be missing (to prevent writing debug info to
+// The CU should be marked NoDebug (to prevent writing debug info to
 // the final output).
-// CHECK-NOT: !llvm.dbg.cu = !{
+// CHECK: !llvm.dbg.cu = !{![[CU:.*]]}
+// CHECK: ![[CU]] = distinct !DICompileUnit({{.*}}emissionKind: NoDebug
 
 int foo(int x, int y) __attribute__((always_inline));
 int foo(int x, int y) { return x + y; }
Index: tools/clang/lib/CodeGen/CGDebugInfo.cpp
===
--- tools/clang/lib/CodeGen/CGDebugInfo.cpp
+++ tools/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -396,16 +396,27 @@
   if (LO.ObjC1)
 RuntimeVers = LO.ObjCRuntime.isNonFragile() ? 2 : 1;
 
+  llvm::DICompileUnit::DebugEmissionKind EmissionKind;
+  switch (DebugKind) {
+  case codegenoptions::NoDebugInfo:
+  case codegenoptions::LocTrackingOnly:
+EmissionKind = llvm::DICompileUnit::NoDebug;
+break;
+  case codegenoptions::DebugLineTablesOnly:
+EmissionKind = llvm::DICompileUnit::LineTablesOnly;
+break;
+  case codegenoptions::LimitedDebugInfo:
+  case codegenoptions::FullDebugInfo:
+EmissionKind = llvm::DICompileUnit::FullDebug;
+break;
+  }
+
   // Create new compile unit.
   // FIXME - Eliminate TheCU.
   TheCU = DBuilder.createCompileUnit(
   LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
-  CGM.getCodeGenOpts().SplitDwarfFile,
-  DebugKind <= codegenoptions::DebugLineTablesOnly
-  ? llvm::DICompileUnit::LineTablesOnly
-  : llvm::DICompileUnit::FullDebug,
-  0 /* DWOid */, DebugKind != codegenoptions::LocTrackingOnly);
+  CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
Index: tools/opt/BreakpointPrinter.cpp
===
--- tools/opt/BreakpointPrinter.cpp
+++ tools/opt/BreakpointPrinter.cpp
@@ -45,9 +45,7 @@
 
   bool runOnModule(Module &M) override {
 TypeIdentifierMap.clear();
-NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu");
-if (CU_Nodes)
-  TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
+TypeIdentifierMap = generateDITypeIdentifierMap(M);
 
 StringSet<> Processed;
 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
Index: test/DebugInfo/X86/mixed-nodebug-cu.ll
===
--- /dev/null
+++ test/DebugInfo/X86/mixed-nodebug-cu.ll
@@ -0,0 +1,50 @@
+; RUN: llc %s -o %t -filetype=obj
+; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s
+; CHECK: DW_TAG_compile_unit
+; CHECK:   DW_TAG_subprogram
+; CHECK: DW_AT_name{{.*}}"f"
+; CHECK-NOT: DW_TAG_compile_unit
+;
+; created from
+;   void f() {} // compile with -g
+;   void g() {} // compile with -Rpass=inline
+; and llvm-linking the result.
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
+; Function Attrs: nounwind ssp uwtable
+define void @f() #0 !dbg !4 {
+entry:
+  ret void, !dbg !15
+}
+
+; Function Attrs: nounwind ssp uwtable
+define void @g() #0 !dbg !9 {
+entry:
+  ret void, !dbg !16
+}
+
+attributes #0 = { 

Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-06 Thread Adrian Prantl via cfe-commits
aprantl added a comment.

Oh. And I also discovered a completely bit-rotted pass called BreakpointPrinter 
that can impossible function because it looks at llvm.dbg.sp. Looks like it 
could be easily updated, though.


http://reviews.llvm.org/D18808



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


r265594 - Minor simplifications.

2016-04-06 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Apr  6 15:12:34 2016
New Revision: 265594

URL: http://llvm.org/viewvc/llvm-project?rev=265594&view=rev
Log:
Minor simplifications.

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

Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=265594&r1=265593&r2=265594&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Wed Apr  6 15:12:34 2016
@@ -477,9 +477,7 @@ private:
   unsigned getSubmoduleID(Module *Mod);
 
   /// \brief Write the given subexpression to the bitstream.
-  void WriteSubStmt(Stmt *S,
-llvm::DenseMap &SubStmtEntries,
-llvm::DenseSet &ParentStmts);
+  void WriteSubStmt(Stmt *S);
 
   void WriteBlockInfoBlock();
   uint64_t WriteControlBlock(Preprocessor &PP, ASTContext &Context,

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=265594&r1=265593&r2=265594&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Wed Apr  6 15:12:34 2016
@@ -52,7 +52,7 @@ namespace clang {
 
   auto Offset = Record.Emit(Code, AbbrevToUse);
 
-  // Flush any expressions, base specifiers, and ctor initializers that
+  // Flush any base specifiers and ctor initializers that
   // were written as part of this declaration.
   Writer.FlushPendingAfterDecl();
 

Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=265594&r1=265593&r2=265594&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Wed Apr  6 15:12:34 2016
@@ -29,7 +29,6 @@ using namespace clang;
 namespace clang {
 
   class ASTStmtWriter : public StmtVisitor {
-friend class OMPClauseWriter;
 ASTWriter &Writer;
 ASTRecordWriter Record;
 
@@ -43,7 +42,7 @@ namespace clang {
 
 ASTStmtWriter(const ASTStmtWriter&) = delete;
 
-uint64_t Emit(Stmt *S) {
+uint64_t Emit() {
   assert(Code != serialization::STMT_NULL_PTR &&
  "unhandled sub-statement writing AST file");
   return Record.EmitStmt(Code, AbbrevToUse);
@@ -2380,9 +2379,7 @@ void ASTWriter::ClearSwitchCaseIDs() {
 
 /// \brief Write the given substatement or subexpression to the
 /// bitstream.
-void ASTWriter::WriteSubStmt(Stmt *S,
- llvm::DenseMap &SubStmtEntries,
- llvm::DenseSet &ParentStmts) {
+void ASTWriter::WriteSubStmt(Stmt *S) {
   RecordData Record;
   ASTStmtWriter Writer(*this, Record);
   ++NumStatements;
@@ -2420,7 +2417,7 @@ void ASTWriter::WriteSubStmt(Stmt *S,
 
   Writer.Visit(S);
   
-  SubStmtEntries[S] = Writer.Emit(S);
+  SubStmtEntries[S] = Writer.Emit();
 }
 
 /// \brief Flush all of the statements that have been added to the
@@ -2432,7 +2429,7 @@ void ASTRecordWriter::FlushStmts() {
   assert(Writer->ParentStmts.empty() && "unexpected entries in parent stmt 
map");
 
   for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
-Writer->WriteSubStmt(StmtsToEmit[I], Writer->SubStmtEntries, 
Writer->ParentStmts);
+Writer->WriteSubStmt(StmtsToEmit[I]);
 
 assert(N == StmtsToEmit.size() && "record modified while being written!");
 
@@ -2453,8 +2450,7 @@ void ASTRecordWriter::FlushSubStmts() {
   // that a simple stack machine can be used when loading), and don't emit a
   // STMT_STOP after each one.
   for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
-Writer->WriteSubStmt(StmtsToEmit[N - I - 1],
- Writer->SubStmtEntries, Writer->ParentStmts);
+Writer->WriteSubStmt(StmtsToEmit[N - I - 1]);
 assert(N == StmtsToEmit.size() && "record modified while being written!");
   }
 


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


r265597 - [modules] Don't try to add lookup results to non-lookup contexts.

2016-04-06 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Wed Apr  6 15:56:03 2016
New Revision: 265597

URL: http://llvm.org/viewvc/llvm-project?rev=265597&view=rev
Log:
[modules] Don't try to add lookup results to non-lookup contexts.

Fixes https://llvm.org/bugs/show_bug.cgi?id=27186

Patch reviewed by Richard Smith.


Modified:
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=265597&r1=265596&r2=265597&view=diff
==
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Wed Apr  6 15:56:03 2016
@@ -1559,9 +1559,12 @@ void DeclContext::makeDeclVisibleInConte
 bool Recoverable) {
   assert(this == getPrimaryContext() && "expected a primary DC");
 
-  // Skip declarations within functions.
-  if (isFunctionOrMethod())
+  if (!isLookupContext()) {
+if (isTransparentContext())
+  getParent()->getPrimaryContext()
+->makeDeclVisibleInContextWithFlags(D, Internal, Recoverable);
 return;
+  }
 
   // Skip declarations which should be invisible to name lookup.
   if (shouldBeHidden(D))

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=265597&r1=265596&r2=265597&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed Apr  6 15:56:03 2016
@@ -5736,6 +5736,9 @@ static bool isImportedDeclContext(ASTRea
 }
 
 void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) {
+   assert(DC->isLookupContext() &&
+  "Should not add lookup results to non-lookup contexts!");
+
   // TU is handled elsewhere.
   if (isa(DC))
 return;


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


r265598 - Fix order-of-evaluation bug (causing GCC buildbots to fail).

2016-04-06 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Apr  6 15:57:53 2016
New Revision: 265598

URL: http://llvm.org/viewvc/llvm-project?rev=265598&view=rev
Log:
Fix order-of-evaluation bug (causing GCC buildbots to fail).

Modified:
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=265598&r1=265597&r2=265598&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Wed Apr  6 15:57:53 2016
@@ -2417,7 +2417,8 @@ void ASTWriter::WriteSubStmt(Stmt *S) {
 
   Writer.Visit(S);
   
-  SubStmtEntries[S] = Writer.Emit();
+  uint64_t Offset = Writer.Emit();
+  SubStmtEntries[S] = Offset;
 }
 
 /// \brief Flush all of the statements that have been added to the


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


r265599 - [modules] Add forgotten test case to r265597.

2016-04-06 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Wed Apr  6 15:58:12 2016
New Revision: 265599

URL: http://llvm.org/viewvc/llvm-project?rev=265599&view=rev
Log:
[modules] Add forgotten test case to r265597.

Added:
cfe/trunk/test/Modules/Inputs/PR27186/
cfe/trunk/test/Modules/Inputs/PR27186/Rtypes.h
cfe/trunk/test/Modules/Inputs/PR27186/module.modulemap
cfe/trunk/test/Modules/Inputs/PR27186/stddef.h
cfe/trunk/test/Modules/Inputs/PR27186/time.h
cfe/trunk/test/Modules/pr27186.cpp

Added: cfe/trunk/test/Modules/Inputs/PR27186/Rtypes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27186/Rtypes.h?rev=265599&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR27186/Rtypes.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27186/Rtypes.h Wed Apr  6 15:58:12 2016
@@ -0,0 +1,2 @@
+#include 
+typedef struct timespec timespec_t;

Added: cfe/trunk/test/Modules/Inputs/PR27186/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27186/module.modulemap?rev=265599&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR27186/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/PR27186/module.modulemap Wed Apr  6 15:58:12 
2016
@@ -0,0 +1,5 @@
+module "Rtypes.h" { header "Rtypes.h" }
+module a [extern_c] {
+  header "stddef.h"
+  header "time.h"
+}

Added: cfe/trunk/test/Modules/Inputs/PR27186/stddef.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27186/stddef.h?rev=265599&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR27186/stddef.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27186/stddef.h Wed Apr  6 15:58:12 2016
@@ -0,0 +1 @@
+

Added: cfe/trunk/test/Modules/Inputs/PR27186/time.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/PR27186/time.h?rev=265599&view=auto
==
--- cfe/trunk/test/Modules/Inputs/PR27186/time.h (added)
+++ cfe/trunk/test/Modules/Inputs/PR27186/time.h Wed Apr  6 15:58:12 2016
@@ -0,0 +1 @@
+struct timespec;

Added: cfe/trunk/test/Modules/pr27186.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/pr27186.cpp?rev=265599&view=auto
==
--- cfe/trunk/test/Modules/pr27186.cpp (added)
+++ cfe/trunk/test/Modules/pr27186.cpp Wed Apr  6 15:58:12 2016
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -I%S/Inputs/PR27186  -I%S/Inputs/PR27186/subdir/ 
-verify %s
+// RUN: %clang_cc1  -nostdsysteminc -std=c++11 -fmodules  
-fmodule-map-file=%S/Inputs/PR27186/module.modulemap -fmodules-cache-path=%t 
-I%S/Inputs/PR27186/ -verify %s
+
+#include "Rtypes.h"
+
+// expected-no-diagnostics


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


Re: [PATCH] D18821: Add modernize-bool-to-integer-conversion

2016-04-06 Thread Piotr Padlewski via cfe-commits
Prazek marked an inline comment as done.
Prazek added a comment.

In http://reviews.llvm.org/D18821#393556, @mnbvmar wrote:

> This check throws a warning also on the conversion to floats (probably very 
> rare ones):
>
>   double number = true;
>
>
> Even though this behavior is correct, the code warns about the implicit 
> conversion to **integers**.


That case is extremaly rare. I will see what I can do


http://reviews.llvm.org/D18821



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


r265601 - Revert "Set the default C standard to C99 when targeting the PS4."

2016-04-06 Thread Sean Silva via cfe-commits
Author: silvas
Date: Wed Apr  6 16:06:52 2016
New Revision: 265601

URL: http://llvm.org/viewvc/llvm-project?rev=265601&view=rev
Log:
Revert "Set the default C standard to C99 when targeting the PS4."

This reverts r265359.

It breaks
- llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast
- llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast

Failing Tests (5):
Clang :: FixIt/fixit-errors.c
Clang :: Preprocessor/init.c
Clang :: Sema/attr-deprecated.c
Clang :: Sema/nullability.c
Clang :: SemaObjC/objcbridge-attribute-arc.m

Modified:
cfe/trunk/include/clang/Frontend/CompilerInvocation.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInvocation.h?rev=265601&r1=265600&r2=265601&view=diff
==
--- cfe/trunk/include/clang/Frontend/CompilerInvocation.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h Wed Apr  6 16:06:52 
2016
@@ -153,10 +153,8 @@ public:
   ///
   /// \param Opts - The LangOptions object to set up.
   /// \param IK - The input language.
-  /// \param T - The target triple.
   /// \param LangStd - The input language standard.
   static void setLangDefaults(LangOptions &Opts, InputKind IK,
-   const llvm::Triple &T,
LangStandard::Kind LangStd = 
LangStandard::lang_unspecified);
   
   /// \brief Retrieve a module hash string that is suitable for uniquely 

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=265601&r1=265600&r2=265601&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Apr  6 16:06:52 2016
@@ -1357,7 +1357,6 @@ static void ParseHeaderSearchArgs(Header
 }
 
 void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
- const llvm::Triple &T,
  LangStandard::Kind LangStd) {
   // Set some properties which depend solely on the input kind; it would be 
nice
   // to move these to the language standard, and have the driver resolve the
@@ -1390,11 +1389,7 @@ void CompilerInvocation::setLangDefaults
 case IK_PreprocessedC:
 case IK_ObjC:
 case IK_PreprocessedObjC:
-  // The PS4 uses C99 as the default C standard.
-  if (T.isPS4())
-LangStd = LangStandard::lang_gnu99;
-  else
-LangStd = LangStandard::lang_gnu11;
+  LangStd = LangStandard::lang_gnu11;
   break;
 case IK_CXX:
 case IK_PreprocessedCXX:
@@ -1548,8 +1543,7 @@ static void ParseLangArgs(LangOptions &O
   LangStd = OpenCLLangStd;
   }
 
-  llvm::Triple T(TargetOpts.Triple);
-  CompilerInvocation::setLangDefaults(Opts, IK, T, LangStd);
+  CompilerInvocation::setLangDefaults(Opts, IK, LangStd);
 
   // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension
   // keywords. This behavior is provided by GCC's poorly named '-fasm' flag,
@@ -1872,6 +1866,7 @@ static void ParseLangArgs(LangOptions &O
   // Provide diagnostic when a given target is not expected to be an OpenMP
   // device or host.
   if (Opts.OpenMP && !Opts.OpenMPIsDevice) {
+llvm::Triple T(TargetOpts.Triple);
 switch (T.getArch()) {
 default:
   break;

Modified: cfe/trunk/test/Preprocessor/init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=265601&r1=265600&r2=265601&view=diff
==
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Wed Apr  6 16:06:52 2016
@@ -8358,7 +8358,6 @@
 // PS4:#define __SSE2__ 1
 // PS4:#define __SSE_MATH__ 1
 // PS4:#define __SSE__ 1
-// PS4:#define __STDC_VERSION__ 199901L
 // PS4:#define __UINTMAX_TYPE__ long unsigned int
 // PS4:#define __USER_LABEL_PREFIX__
 // PS4:#define __WCHAR_MAX__ 65535


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


Re: r265359 - Set the default C standard to C99 when targeting the PS4.

2016-04-06 Thread Sean Silva via cfe-commits
I've had to revert this in r265601 because it was breaking the PS4 bots.

In the future, please keep an eye on them! It's a total bummer leaving them
red for 2 days.

http://lab.llvm.org:8011/waterfall?builder=llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast&builder=llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast&reload=120

-- Sean Silva

On Mon, Apr 4, 2016 at 3:56 PM, Sunil Srivastava via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ssrivastava
> Date: Mon Apr  4 17:56:05 2016
> New Revision: 265359
>
> URL: http://llvm.org/viewvc/llvm-project?rev=265359&view=rev
> Log:
> Set the default C standard to C99 when targeting the PS4.
>
> Patch by Douglas Yung!
>
> Differential Revision: http://reviews.llvm.org/D18708
>
> Modified:
> cfe/trunk/include/clang/Frontend/CompilerInvocation.h
> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> cfe/trunk/test/Preprocessor/init.c
>
> Modified: cfe/trunk/include/clang/Frontend/CompilerInvocation.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInvocation.h?rev=265359&r1=265358&r2=265359&view=diff
>
> ==
> --- cfe/trunk/include/clang/Frontend/CompilerInvocation.h (original)
> +++ cfe/trunk/include/clang/Frontend/CompilerInvocation.h Mon Apr  4
> 17:56:05 2016
> @@ -153,8 +153,10 @@ public:
>///
>/// \param Opts - The LangOptions object to set up.
>/// \param IK - The input language.
> +  /// \param T - The target triple.
>/// \param LangStd - The input language standard.
>static void setLangDefaults(LangOptions &Opts, InputKind IK,
> +   const llvm::Triple &T,
> LangStandard::Kind LangStd =
> LangStandard::lang_unspecified);
>
>/// \brief Retrieve a module hash string that is suitable for uniquely
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=265359&r1=265358&r2=265359&view=diff
>
> ==
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Apr  4 17:56:05 2016
> @@ -1355,6 +1355,7 @@ static void ParseHeaderSearchArgs(Header
>  }
>
>  void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
> + const llvm::Triple &T,
>   LangStandard::Kind LangStd) {
>// Set some properties which depend solely on the input kind; it would
> be nice
>// to move these to the language standard, and have the driver resolve
> the
> @@ -1387,7 +1388,11 @@ void CompilerInvocation::setLangDefaults
>  case IK_PreprocessedC:
>  case IK_ObjC:
>  case IK_PreprocessedObjC:
> -  LangStd = LangStandard::lang_gnu11;
> +  // The PS4 uses C99 as the default C standard.
> +  if (T.isPS4())
> +LangStd = LangStandard::lang_gnu99;
> +  else
> +LangStd = LangStandard::lang_gnu11;
>break;
>  case IK_CXX:
>  case IK_PreprocessedCXX:
> @@ -1541,7 +1546,8 @@ static void ParseLangArgs(LangOptions &O
>LangStd = OpenCLLangStd;
>}
>
> -  CompilerInvocation::setLangDefaults(Opts, IK, LangStd);
> +  llvm::Triple T(TargetOpts.Triple);
> +  CompilerInvocation::setLangDefaults(Opts, IK, T, LangStd);
>
>// We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension
>// keywords. This behavior is provided by GCC's poorly named '-fasm'
> flag,
> @@ -1861,7 +1867,6 @@ static void ParseLangArgs(LangOptions &O
>// Provide diagnostic when a given target is not expected to be an
> OpenMP
>// device or host.
>if (Opts.OpenMP && !Opts.OpenMPIsDevice) {
> -llvm::Triple T(TargetOpts.Triple);
>  switch (T.getArch()) {
>  default:
>break;
>
> Modified: cfe/trunk/test/Preprocessor/init.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=265359&r1=265358&r2=265359&view=diff
>
> ==
> --- cfe/trunk/test/Preprocessor/init.c (original)
> +++ cfe/trunk/test/Preprocessor/init.c Mon Apr  4 17:56:05 2016
> @@ -8358,6 +8358,7 @@
>  // PS4:#define __SSE2__ 1
>  // PS4:#define __SSE_MATH__ 1
>  // PS4:#define __SSE__ 1
> +// PS4:#define __STDC_VERSION__ 199901L
>  // PS4:#define __UINTMAX_TYPE__ long unsigned int
>  // PS4:#define __USER_LABEL_PREFIX__
>  // PS4:#define __WCHAR_MAX__ 65535
>
>
> ___
> 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] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-06 Thread Krystyna via cfe-commits
krystyna added a comment.

lgtm


http://reviews.llvm.org/D18745



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


Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-06 Thread Jakub Staroń via cfe-commits
staronj updated this revision to Diff 52843.
staronj added a comment.

1. Adds newline at the end of modernize-use-bool-literals.rst file.
2. Change names in check test for better readability.
3. Adds some new test cases.


http://reviews.llvm.org/D18745

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

Index: test/clang-tidy/modernize-use-bool-literals.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-bool-literals.cpp
@@ -0,0 +1,63 @@
+// RUN: %check_clang_tidy %s modernize-use-bool-literals %t
+
+bool IntToTrue = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicitly converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool IntToTrue = true;{{$}}
+
+bool IntToFalse(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool IntToFalse(false);{{$}}
+
+bool LongLongToTrue{0x123ABCLL};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool LongLongToTrue{true};{{$}}
+
+#define TRUE_MACRO 1
+
+bool MacroIntToTrue = TRUE_MACRO; // Not ok, but can't replace
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: implicitly converting integer literal to bool inside macro, use bool literal instead [modernize-use-bool-literals]
+
+#define FALSE_MACRO bool(0)
+
+bool TrueBool = true; // OK
+
+bool FalseBool = FALSE_MACRO;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: {{.*}}
+
+void boolFunction(bool bar) {
+
+}
+
+char Character = 0; // OK
+unsigned long long LongInteger = 1; // OK
+
+int main() {
+  boolFunction(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}boolFunction(true);{{$}}
+
+  boolFunction(false); // OK
+
+  IntToTrue = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}IntToTrue = true;{{$}}
+}
+
+class FooClass {
+  public:
+  FooClass() : JustBool(0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}FooClass() : JustBool(false) {}{{$}}
+  FooClass(int) : JustBool{0} {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}FooClass(int) : JustBool{false} {}{{$}}
+  private:
+  bool JustBool;
+  bool BoolWithBraces{0};
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool BoolWithBraces{false};{{$}}
+  bool BoolFromInt = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool BoolFromInt = false;{{$}}
+  bool SimpleBool = true; // OK
+};
Index: docs/clang-tidy/checks/modernize-use-bool-literals.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-bool-literals.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - modernize-use-bool-literals
+
+modernize-use-bool-literals
+===
+
+Finds integer literals, which are implicitly cast to bool.
+
+.. code-block:: c++
+
+  bool p = 1;
+  std::ios_base::sync_with_stdio(0);
+
+  // transforms to
+
+  bool p = true;
+  std::ios_base::sync_with_stdio(false);
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
@@ -85,6 +85,7 @@
modernize-replace-auto-ptr
modernize-shrink-to-fit
modernize-use-auto
+   modernize-use-bool-literals
modernize-use-default
modernize-use-nullptr
modernize-use-override
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -119,6 +119,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-bool-literals
+  `_ check
+
+  Finds integer literals, which are implicitly cast to bool.
+
 - New `performance-faster-string-find
   

Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-06 Thread Marek Sokołowski via cfe-commits
mnbvmar added a comment.

You could also think whether char literals should be converted to true/false, 
too. Apart from this (and other people's doubts), everything's fine.


http://reviews.llvm.org/D18745



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


Re: [PATCH] D18821: Add modernize-bool-to-integer-conversion

2016-04-06 Thread Marek Sokołowski via cfe-commits
mnbvmar added a comment.

This check throws a warning also on the conversion to floats (probably very 
rare ones):

  double number = true;

Even though this behavior is correct, the code warns about the implicit 
conversion to **integers**.



Comment at: docs/ReleaseNotes.rst:119
@@ +118,3 @@
+
+  Replaces implicit cast from bool literals to integers to int literals.
+

**with** int literals


http://reviews.llvm.org/D18821



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


Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-06 Thread Adrian Prantl via cfe-commits
aprantl added a comment.

Duncan: There already exists a verifier check that ensures each DICompileUnit 
is listed in llvm.dbg.cu.
This didn't break existing users of sample-based profiling, because the 
Verifier cannot *find* the orphaned DICompileUnits. After the DISubprogram / 
DICompileUnit pointer reversal, however, this will be possible and the 
verification will fail.


http://reviews.llvm.org/D18808



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


Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-06 Thread Duncan P. N. Exon Smith via cfe-commits
Okay, weird.  So the DICompileUnit wouldn't even get written out to
bitcode, IIUC.  LGTM then.

> On 2016-Apr-06, at 14:31, Adrian Prantl  wrote:
> 
> aprantl added a comment.
> 
> Duncan: There already exists a verifier check that ensures each DICompileUnit 
> is listed in llvm.dbg.cu.
> This didn't break existing users of sample-based profiling, because the 
> Verifier cannot *find* the orphaned DICompileUnits. After the DISubprogram / 
> DICompileUnit pointer reversal, however, this will be possible and the 
> verification will fail.
> 
> 
> http://reviews.llvm.org/D18808
> 
> 
> 

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


Re: [PATCH] D18821: Add modernize-bool-to-integer-conversion

2016-04-06 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 52851.
Prazek marked an inline comment as done.

http://reviews.llvm.org/D18821

Files:
  clang-tidy/modernize/BoolToIntegerConversionCheck.cpp
  clang-tidy/modernize/BoolToIntegerConversionCheck.h
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
  test/clang-tidy/modernize-bool-to-integer-conversion.cpp

Index: test/clang-tidy/modernize-bool-to-integer-conversion.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-bool-to-integer-conversion.cpp
@@ -0,0 +1,44 @@
+// RUN: %check_clang_tidy %s modernize-bool-to-integer-conversion %t
+
+const int is42Answer = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicitly converting bool literal to 'int'. Use integer literal instead [modernize-bool-to-integer-conversion]
+// CHECK-FIXES: const int is42Answer = 1;{{$}}
+
+volatile int noItsNot = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicitly converting bool literal to 'int'. {{..}}
+// CHECK-FIXES: volatile int noItsNot = 0;{{$}}
+int a = 42;
+int az = a;
+
+long long ll = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: implicitly converting bool literal to 'long long'.{{..}}
+// CHECK-FIXES: long long ll = 1;{{$}}
+
+void fun(int) {}
+#define ONE true
+
+// No fixup for macros.
+int one = ONE;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicitly converting bool literal to 'int' inside macro. Use integer literal instead [modernize-bool-to-integer-conversion]
+
+void test() {
+  fun(ONE);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: implicitly converting bool{{..}}
+
+  fun(42);
+  fun(true);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: implicitly {{..}}
+// CHECK-FIXES: fun(1);{{$}}
+}
+
+char c = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: implicitly {{..}}
+// CHECK-FIXES: char c = 1;
+
+float f = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicitly converting bool literal to 'float'.{{..}}
+// CHECK-FIXES: float f = 0;
+
+char c2 = 1;
+char c3 = '0';
+bool b = true;
Index: docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - modernize-bool-to-integer-conversion
+
+modernize-bool-to-integer-conversion
+
+
+This check looks for implicit conversion from bool literals to integer types
+
+.. code-block:: C++
+  int a = false;
+  vector v(true); // Makes vector of one element
+
+  // Changes it to
+  int a = 0;
+  vector v(1); // Makes vector of one element
+
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
@@ -76,6 +76,7 @@
misc-unused-parameters
misc-unused-raii
misc-virtual-near-miss
+   modernize-bool-to-integer-conversion
modernize-deprecated-headers
modernize-loop-convert
modernize-make-unique
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
 
   Replaces C standard library headers with their C++ alternatives.
 
+- New `modernize-bool-to-integer-conversion
+  `_ check
+
+  Replaces implicit cast from bool literals to integers with int literals.
+
 - New `modernize-raw-string-literal
   `_ check
 
Index: clang-tidy/modernize/ModernizeTidyModule.cpp
===
--- clang-tidy/modernize/ModernizeTidyModule.cpp
+++ clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "BoolToIntegerConversionCheck.h"
 #include "DeprecatedHeadersCheck.h"
 #include "LoopConvertCheck.h"
 #include "MakeUniqueCheck.h"
@@ -32,6 +33,8 @@
 class ModernizeModule : public ClangTidy

Buildbot numbers for the week of 3/20/2016 - 3/26/2016

2016-04-06 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the week of 3/20/2016 - 3/26/2016.

Thanks

Galina


"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green):

 buildername| builds |
changes | status change ratio
++-+-
 perf-x86_64-penryn-O3-polly| 55 |
30 |54.5
 libcxx-libcxxabi-x86_64-linux-debian-noexceptions  |  2
|   1 |50.0
 libcxx-libcxxabi-x86_64-linux-debian   |  2
|   1 |50.0
 clang-ppc64le-linux-lnt| 77 |
37 |48.1
 perf-x86_64-penryn-O3-polly-parallel-fast  |219 |
99 |45.2
 lldb-x86_64-darwin-13.4|110 |
46 |41.8
 clang-cmake-mipsel | 13
|   4 |30.8
 clang-cmake-aarch64-full   | 39 |
11 |28.2
 clang-x86-win2008-selfhost |107 |
20 |18.7
 clang-x64-ninja-win7   |168 |
30 |17.9
 sanitizer-ppc64le-linux| 46
|   8 |17.4
 llvm-mips-linux| 60 |
10 |16.7
 clang-ppc64be-linux-multistage |120 |
20 |16.7
 sanitizer-x86_64-linux-bootstrap   | 53
|   8 |15.1
 lldb-windows7-android  | 88 |
13 |14.8
 libomp-clang-x86_64-linux-debian   |  7
|   1 |14.3
 clang-cmake-mips   | 88 |
12 |13.6
 clang-cmake-armv7-a15-full | 96 |
13 |13.5
 clang-atom-d525-fedora-rel | 85 |
10 |11.8
 clang-cmake-thumbv7-a15|159 |
18 |11.3
 sanitizer-x86_64-linux | 80
|   9 |11.3
 clang-ppc64le-linux|183 |
20 |10.9
 clang-cmake-aarch64-quick  |133 |
14 |10.5
 llvm-clang-lld-x86_64-debian-fast  |165 |
17 |10.3
 clang-cmake-armv7-a15  |142 |
14 | 9.9
 clang-cmake-aarch64-42vma  |147 |
14 | 9.5
 clang-ppc64be-linux-lnt|217 |
20 | 9.2
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast   |370 |
34 | 9.2
 clang-cmake-thumbv7-a15-full-sh| 22
|   2 | 9.1
 sanitizer-x86_64-linux-fast|161 |
14 | 8.7
 clang-s390x-linux  |259 |
22 | 8.5
 clang-bpf-build|294 |
24 | 8.2
 clang-x86_64-debian-fast   |126 |
10 | 7.9
 clang-ppc64be-linux|262 |
20 | 7.6
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast |369 |
28 | 7.6
 lldb-x86_64-ubuntu-14.04-android   |109
|   8 | 7.3
 lldb-x86-windows-msvc2015  |153 |
11 | 7.2
 sanitizer-ppc64be-linux| 92
|   6 | 6.5
 clang-native-arm-lnt   | 97
|   6 | 6.2
 lldb-x86_64-ubuntu-14.04-cmake |191 |
11 | 5.8
 lldb-amd64-ninja-netbsd7   |140
|   8 | 5.7
 lld-x86_64-win7|111
|   6 | 5.4
 llvm-hexagon-elf   |214 |
10 | 4.7
 lldb-x86_64-ubuntu-14.04-buildserver   |132
|   6 | 4.5
 sanitizer-windows  |340 |
15 | 4.4
 clang-cmake-armv7-a15-selfhost-neon| 25
|   1 | 4.0
 perf-x86_64-penryn-O3  | 

Buildbot numbers for the week of 3/27/2016 - 4/02/2016

2016-04-06 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the last week of 3/27/2016 - 4/02/2016.

Thanks

Galina


"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green):

 buildername| builds |
changes | status change ratio
++-+-
 perf-x86_64-penryn-O3-polly| 52 |
44 |84.6
 clang-ppc64le-linux-lnt| 79 |
31 |39.2
 lldb-x86_64-darwin-13.4|127 |
44 |34.6
 clang-cmake-mipsel | 14
|   4 |28.6
 clang-cmake-thumbv7-a15-full-sh| 23
|   6 |26.1
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx14 |  4
|   1 |25.0
 clang-x86-win2008-selfhost |127 |
30 |23.6
 sanitizer-x86_64-linux | 76 |
16 |21.1
 clang-x64-ninja-win7   |200 |
36 |18.0
 clang-cmake-aarch64-full   | 40
|   6 |15.0
 lldb-windows7-android  | 90 |
13 |14.4
 perf-x86_64-penryn-O3-polly-before-vectorizer-detect-only  | 14
|   2 |14.3
 perf-x86_64-penryn-O3-polly-before-vectorizer  | 16
|   2 |12.5
 sanitizer-ppc64le-linux| 40
|   4 |10.0
 sanitizer-x86_64-linux-bootstrap   | 51
|   5 | 9.8
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast   |425 |
39 | 9.2
 clang-atom-d525-fedora-rel | 69
|   6 | 8.7
 clang-cmake-thumbv7-a15|161 |
14 | 8.7
 clang-cmake-armv7-a15-selfhost-neon| 23
|   2 | 8.7
 clang-ppc64be-linux-lnt|236 |
20 | 8.5
 clang-cmake-armv7-a15  |154 |
12 | 7.8
 clang-cmake-aarch64-42vma  |163 |
12 | 7.4
 clang-s390x-linux  |298 |
22 | 7.4
 lldb-x86_64-ubuntu-14.04-android   |118
|   8 | 6.8
 clang-ppc64be-linux|299 |
20 | 6.7
 clang-bpf-build|330 |
22 | 6.7
 clang-cmake-armv7-a15-selfhost | 30
|   2 | 6.7
 llvm-mips-linux| 61
|   4 | 6.6
 clang-cmake-aarch64-quick  |162 |
10 | 6.2
 clang-ppc64le-linux|193 |
12 | 6.2
 clang-ppc64be-linux-multistage |132
|   8 | 6.1
 clang-x86_64-debian-fast   |140
|   8 | 5.7
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast |425 |
24 | 5.6
 llvm-clang-lld-x86_64-debian-fast  |181 |
10 | 5.5
 sanitizer-x86_64-linux-fast|183
|   9 | 4.9
 clang-cmake-mips   | 81
|   4 | 4.9
 sanitizer-windows  |383 |
18 | 4.7
 llvm-hexagon-elf   |257 |
12 | 4.7
 clang-hexagon-elf  |321 |
14 | 4.4
 lldb-x86-windows-msvc2015  |182
|   8 | 4.4
 lldb-x86_64-ubuntu-14.04-cmake |203
|   9 | 4.4
 clang-cmake-armv7-a15-full | 94
|   4 | 4.3
 sanitizer-ppc64be-linux| 98
|   4 | 4.1
 perf-x86_64-penryn-O3  | 52
|   2 | 3.8
 lld-x86_64-win7|330 |
11 | 3.3
 perf-x86_64-penryn-O3-polly-unprofitable   |212
|   6 | 2.8
 lldb-amd64-ninja-net

Re: [PATCH] D18821: Add modernize-bool-to-integer-conversion

2016-04-06 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 52855.
Prazek added a comment.

Added new test cases


http://reviews.llvm.org/D18821

Files:
  clang-tidy/modernize/BoolToIntegerConversionCheck.cpp
  clang-tidy/modernize/BoolToIntegerConversionCheck.h
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
  test/clang-tidy/modernize-bool-to-integer-conversion.cpp

Index: test/clang-tidy/modernize-bool-to-integer-conversion.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-bool-to-integer-conversion.cpp
@@ -0,0 +1,58 @@
+// RUN: %check_clang_tidy %s modernize-bool-to-integer-conversion %t
+
+const int is42Answer = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicitly converting bool literal to 'int'. Use integer literal instead [modernize-bool-to-integer-conversion]
+// CHECK-FIXES: const int is42Answer = 1;{{$}}
+
+volatile int noItsNot = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicitly converting bool literal to 'int'. {{..}}
+// CHECK-FIXES: volatile int noItsNot = 0;{{$}}
+int a = 42;
+int az = a;
+
+long long ll = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: implicitly converting bool literal to 'long long'.{{..}}
+// CHECK-FIXES: long long ll = 1;{{$}}
+
+void fun(int) {}
+#define ONE true
+
+// No fixup for macros.
+int one = ONE;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicitly converting bool literal to 'int' inside macro. Use integer literal instead [modernize-bool-to-integer-conversion]
+
+void test() {
+  fun(ONE);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: implicitly converting bool{{..}}
+
+  fun(42);
+  fun(true);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: implicitly {{..}}
+// CHECK-FIXES: fun(1);{{$}}
+}
+
+char c = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: implicitly {{..}}
+// CHECK-FIXES: char c = 1;
+
+float f = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicitly converting bool literal to 'float'.{{..}}
+// CHECK-FIXES: float f = 0;
+
+struct Blah {
+  Blah(int blah) { }
+};
+
+const int &ref = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicitly converting bool literal to 'int'{{..}}
+// CHECK-FIXES: const int &ref = 0;
+
+Blah bla = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicitly converting bool literal to 'int'{{..}}
+// CHECK-FIXES: Blah bla = 1;
+
+Blah bla2 = 1;
+
+char c2 = 1;
+char c3 = '0';
+bool b = true;
Index: docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - modernize-bool-to-integer-conversion
+
+modernize-bool-to-integer-conversion
+
+
+This check looks for implicit conversion from bool literals to integer types
+
+.. code-block:: C++
+  int a = false;
+  vector v(true); // Makes vector of one element
+
+  // Changes it to
+  int a = 0;
+  vector v(1); // Makes vector of one element
+
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
@@ -76,6 +76,7 @@
misc-unused-parameters
misc-unused-raii
misc-virtual-near-miss
+   modernize-bool-to-integer-conversion
modernize-deprecated-headers
modernize-loop-convert
modernize-make-unique
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
 
   Replaces C standard library headers with their C++ alternatives.
 
+- New `modernize-bool-to-integer-conversion
+  `_ check
+
+  Replaces implicit cast from bool literals to integers with int literals.
+
 - New `modernize-raw-string-literal
   `_ check
 
Index: clang-tidy/modernize/ModernizeTidyModule.cpp
===
--- clang-tidy/modernize/ModernizeTidyModul

Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-06 Thread David Blaikie via cfe-commits
On Wed, Apr 6, 2016 at 8:44 AM, Adrian Prantl  wrote:

>
> On Apr 6, 2016, at 8:16 AM, David Blaikie  wrote:
>
>
>
> On Tue, Apr 5, 2016 at 10:17 PM, Eric Christopher via llvm-commits <
> llvm-comm...@lists.llvm.org> wrote:
>
>> echristo added inline comments.
>>
>> 
>> Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:477-479
>> @@ -476,2 +476,5 @@
>> +  unsigned DebugCUs = 0;
>>for (MDNode *N : CU_Nodes->operands()) {
>>  auto *CUNode = cast(N);
>> +if (CUNode->getEmissionKind() == DICompileUnit::NoDebug)
>> +  continue;
>> 
>> Instead of this pattern would it make more sense to have an iterator over
>> the nodes that checks for !NoDebug?
>>
>
> Yeah, that sounds like something that might be nice.
>
> Adrian - I recall one of your initial ideas was to just have a different
> named metadata node for these subprograms.
>
>
> Huh. I think I had this idea in the context of collectDeadVariables (to
> collect dead subprograms), but I see how it would apply here, too.
>
> What was the motivation for not going with that plan? (which would've
> meant these sort of loops would've remained OK, and only the loops in the
> verifier and such would need to examine both nodes?) Perhaps this relates
> to your comment about LTOing debug+nodebug CUs? I didn't quite follow what
> was wrong with that in the first place & how this addresses it, could you
> explain it?
>
>
> Most of the patches I’ve been committing recently are in preparation
> reversing the ownership between DICompileUnit and DISubprogram (which will
> help ThinLTO to lazy-load debug info).
> DICompileUnit will no longer have a list of “subprograms:" and instead
> each DISubprogram will have a “unit:" field that points to the owning CU.
>
> While it would be possible to leave the unit field empty and have a
> NamedMDNode hold on to these subprograms, having a mandatory “unit:" point
> to a CU that is explicitly marked NoDebug is a more regular and readable
> representation. It’s straightforward to verify and easier to debug
> especially in the LTO case.
>

Not sure whether it adds much more regularity or irregularity compared to
having a null unit for the subprogram, really?

Anyone looking at the subprogram for debug purposes is going to have to
walk up and check that it's not a nodebug CU, the CU isn't really a CU
(when looking at the code/IR/etc - it'll be a weird construct)... but I
dunno.


>
> -- adrian
>
>
>
>>
>> 
>> Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1127-1128
>> @@ -1115,3 +1126,4 @@
>>if (!MMI->hasDebugInfo() || LScopes.empty() ||
>> -  !MF->getFunction()->getSubprogram()) {
>> +  !MF->getFunction()->getSubprogram() ||
>> +  !SPMap.lookup(MF->getFunction()->getSubprogram())) {
>>  // If we don't have a lexical scope for this function then there will
>> 
>> Comment.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> http://reviews.llvm.org/D18808
>>
>>
>>
>> ___
>> llvm-commits mailing list
>> llvm-comm...@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18540: [Sema] Note when we've actually encountered a failure in ExprConstant, and take that into account when looking up objects.

2016-04-06 Thread George Burgess IV via cfe-commits
george.burgess.iv updated this revision to Diff 52834.
george.burgess.iv marked 7 inline comments as done.
george.burgess.iv added a comment.

Addressed feedback


http://reviews.llvm.org/D18540

Files:
  lib/AST/ExprConstant.cpp
  test/SemaCXX/builtin-object-size-cxx14.cpp
  test/SemaCXX/constant-expression-cxx1y.cpp

Index: test/SemaCXX/constant-expression-cxx1y.cpp
===
--- test/SemaCXX/constant-expression-cxx1y.cpp
+++ test/SemaCXX/constant-expression-cxx1y.cpp
@@ -179,12 +179,10 @@
   static_assert(!test1(100), "");
   static_assert(!test1(101), ""); // expected-error {{constant expression}} expected-note {{in call to 'test1(101)'}}
 
-  // FIXME: We should be able to reject this before it's called
-  constexpr void f() {
+  constexpr void f() { // expected-error{{constexpr function never produces a constant expression}} expected-note@+2{{assignment to dereferenced one-past-the-end pointer is not allowed in a constant expression}}
 char foo[10] = { "z" }; // expected-note {{here}}
-foo[10] = 'x'; // expected-warning {{past the end}} expected-note {{assignment to dereferenced one-past-the-end pointer}}
+foo[10] = 'x'; // expected-warning {{past the end}}
   }
-  constexpr int k = (f(), 0); // expected-error {{constant expression}} expected-note {{in call}}
 }
 
 namespace array_resize {
@@ -938,3 +936,18 @@
   constexpr int testb = f(e2, 3); // expected-error {{constant expression}} expected-note {{in call}}
   constexpr int testc = f(e3, 3);
 }
+
+namespace SpeculativeEvalWrites {
+  // Ensure that we don't try to speculatively evaluate writes.
+  constexpr int add(int a, int b) { return a + b; }
+
+  constexpr int f() {
+int i = 0;
+int a = 0;
+// __builtin_object_size speculatively evaluates its first argument.
+__builtin_object_size((i = 1, &a), 0);
+return i;
+  }
+
+  static_assert(!f(), "");
+}
Index: test/SemaCXX/builtin-object-size-cxx14.cpp
===
--- /dev/null
+++ test/SemaCXX/builtin-object-size-cxx14.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
+
+namespace basic {
+// Ensuring that __bos can be used in constexpr functions without anything
+// sketchy going on...
+constexpr int bos0() {
+  int k = 5;
+  char cs[10] = {};
+  return __builtin_object_size(&cs[k], 0);
+}
+
+constexpr int bos1() {
+  int k = 5;
+  char cs[10] = {};
+  return __builtin_object_size(&cs[k], 1);
+}
+
+constexpr int bos2() {
+  int k = 5;
+  char cs[10] = {};
+  return __builtin_object_size(&cs[k], 2);
+}
+
+constexpr int bos3() {
+  int k = 5;
+  char cs[10] = {};
+  return __builtin_object_size(&cs[k], 3);
+}
+
+static_assert(bos0() == sizeof(char) * 5, "");
+static_assert(bos1() == sizeof(char) * 5, "");
+static_assert(bos2() == sizeof(char) * 5, "");
+static_assert(bos3() == sizeof(char) * 5, "");
+}
+
+namespace in_enable_if {
+// The code that prompted these changes was __bos in enable_if
+
+void copy5CharsInto(char *buf) // expected-note{{candidate}}
+__attribute__((enable_if(__builtin_object_size(buf, 0) != -1 &&
+ __builtin_object_size(buf, 0) > 5,
+ "")));
+
+// We use different EvalModes for __bos with type 0 versus 1. Ensure 1 works,
+// too...
+void copy5CharsIntoStrict(char *buf) // expected-note{{candidate}}
+__attribute__((enable_if(__builtin_object_size(buf, 1) != -1 &&
+ __builtin_object_size(buf, 1) > 5,
+ "")));
+
+struct LargeStruct {
+  int pad;
+  char buf[6];
+  int pad2;
+};
+
+struct SmallStruct {
+  int pad;
+  char buf[5];
+  int pad2;
+};
+
+void noWriteToBuf() {
+  char buf[6];
+  copy5CharsInto(buf);
+
+  LargeStruct large;
+  copy5CharsIntoStrict(large.buf);
+}
+
+void initTheBuf() {
+  char buf[6] = {};
+  copy5CharsInto(buf);
+
+  LargeStruct large = {0, {}, 0};
+  copy5CharsIntoStrict(large.buf);
+}
+
+int getI();
+void initTheBufWithALoop() {
+  char buf[6] = {};
+  for (unsigned I = getI(); I != sizeof(buf); ++I)
+buf[I] = I;
+  copy5CharsInto(buf);
+
+  LargeStruct large;
+  for (unsigned I = getI(); I != sizeof(buf); ++I)
+large.buf[I] = I;
+  copy5CharsIntoStrict(large.buf);
+}
+
+void tooSmallBuf() {
+  char buf[5];
+  copy5CharsInto(buf); // expected-error{{no matching function for call}}
+
+  SmallStruct small;
+  copy5CharsIntoStrict(small.buf); // expected-error{{no matching function for call}}
+}
+}
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -478,6 +478,9 @@
 /// fold (not just why it's not strictly a constant expression)?
 bool HasFoldFailureDiagnostic;
 
+/// \brief Whether or not we're currently speculatively evaluating.
+bool IsSpeculativelyEvaluating;
+
 enum EvaluationMode {
   /// Evaluate as a constant exp

Re: [PATCH] D15031: CFG: Add CFGElement for automatic variables that leave the scope

2016-04-06 Thread Matthias Gehre via cfe-commits
mgehre added inline comments.


Comment at: include/clang/Analysis/CFG.h:170
@@ -168,1 +169,3 @@
 
+class CFGAutomaticObjLeavesScope : public CFGElement {
+public:

rsmith wrote:
> What is this intended to model? There seem to be a few options here:
> 
>  1) The point at which the destructor would run if the object had a 
> non-trivial destructor
>  2) The point at which the storage duration for the underlying storage ends
>  3) The point at which the lifetime of the object ends
> 
> Note that these are all different -- for an object with a non-trivial 
> destructor, (1) and (3) are the same and for any other object (2) and (3) are 
> the same; (2) occurs after all destructors for the scope have run.
> 
> This matters for cases like:
> 
>   void f() {
> struct A { int *p; ~A() { *p = 0; } } a;
> int n;
> a.p = &n;
>   }
> 
> Here, the lifetime of `n` would end before the lifetime of `a` if `n` had a 
> non-trivial destructor. If `n`s lifetime actually ended there, this code 
> would have undefined behavior. But because the destruction of `n` is trivial, 
> the lifetime of `n` instead ends when its storage duration ends, which is 
> *after* `A`'s destructor runs, so the code is valid.
> 
> Please add a comment to this class to describe what it means.
The intend is to show the point after which it is undefined behavior to refer 
to an object, i.e.
   3. The point at which the lifetime of the object ends
I will add a comment to clarify this. I propose to rename the class to 
"CFGLifetimeEnds", okay?


Comment at: include/clang/Analysis/CFG.h:728
@@ +727,3 @@
+
+  // Scope leaving must be performed in reversed order. So insertion is in two
+  // steps. First we prepare space for some number of elements, then we insert

rsmith wrote:
> Why must reverse order be used? It's not possible for the effects of these 
> operations to interact with each other, is it? At least according to the C++ 
> standard, the "end of storage duration" effects all occur simultaneously.
The order is important as you showed in your example above. The liftetime 
checker should be able to detect the undefined behavior in

```
struct B { B() {}; int n; };
void f() {
  struct A {B *p; ~A() { b->n = 0; } } a;
  B b;
  a.p = &b;
}
```


http://reviews.llvm.org/D15031



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


Re: [PATCH] D18540: [Sema] Note when we've actually encountered a failure in ExprConstant, and take that into account when looking up objects.

2016-04-06 Thread George Burgess IV via cfe-commits
george.burgess.iv added inline comments.


Comment at: lib/AST/ExprConstant.cpp:853-854
@@ -825,5 +852,4 @@
   Info.EvalStatus.Diag = NewDiag;
   // If we're speculatively evaluating, we may have skipped over some
   // evaluations and missed out a side effect.
 }

rsmith wrote:
> I think this comment is now redundant / incorrect.
My bad :)


Comment at: lib/AST/ExprConstant.cpp:3280
@@ -3249,3 +3279,3 @@
   if (!EvaluateObjectArgument(Info, BO->getLHS(), LV)) {
-if (Info.keepEvaluatingAfterFailure()) {
+if (Info.noteUnrecoverableFailure()) {
   MemberPtr MemPtr;

rsmith wrote:
> Can we give this function a name that reads more naturally at the call site? 
> It's locally unclear what this condition is testing. Maybe keep the old name?
The best alternative I can come up with is 
`noteFailureAndGetShouldContinueEvaluating()`, which occupies 44 characters.

...I think I'll go back to the old name.


Comment at: lib/AST/ExprConstant.cpp:4104-4105
@@ -4069,1 +4103,4 @@
+(void)KeepGoing;
+assert(KeepGoing && "We can't evaluate after a failure in potential "
+"constant expressions?");
 CheckPotentialConstantConditional(E);

rsmith wrote:
> I think this should be an `if` rather than an `assert`. If we hit something 
> that's known to be non-constant while evaluating the condition of a `?:`, we 
> should bail out of evaluation in `checkingPotentialConstantExpression` mode. 
> `keepEvaluatingAfterFailure` should return `false` in that case (even though 
> it doesn't do so today).
I'm not sure that I fully understand what you mean by this. Are you saying that 
we (ultimately) only want to check the arms of a conditional when we're 
evaluating for overflow?

Either way, took a stab at fixing it.


Comment at: lib/AST/ExprConstant.cpp:7103
@@ -7067,2 +7102,3 @@
 Expr::EvalStatus OldEvalStatus;
+bool WasSpecEval;
   };

I'm happy to make SpeculativeEvalRAII a type that optionally restores state, if 
you think that would be better. That way, we don't need to duplicate this 
logic...

Also, I can't figure out how to test this, because it's only ever run after 
`HasSideEffects = true`, and the only thing that (I think) checks for if we're 
speculatively evaluating *also* fails in exactly the same way if we have side 
effects.


http://reviews.llvm.org/D18540



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


Re: [PATCH] D18783: [clang-tidy] add new checker for string literal with NUL character.

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb updated this revision to Diff 52856.
etienneb added a comment.

rebased.


http://reviews.llvm.org/D18783

Files:
  clang-tidy/misc/MisplacedWideningCastCheck.cpp

Index: clang-tidy/misc/MisplacedWideningCastCheck.cpp
===
--- clang-tidy/misc/MisplacedWideningCastCheck.cpp
+++ clang-tidy/misc/MisplacedWideningCastCheck.cpp
@@ -10,7 +10,6 @@
 #include "MisplacedWideningCastCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "llvm/ADT/DenseMap.h"
 
 using namespace clang::ast_matchers;
 
@@ -29,18 +28,19 @@
 }
 
 void MisplacedWideningCastCheck::registerMatchers(MatchFinder *Finder) {
-  auto Calc = expr(anyOf(binaryOperator(anyOf(
- hasOperatorName("+"), hasOperatorName("-"),
- hasOperatorName("*"), hasOperatorName("<<"))),
- unaryOperator(hasOperatorName("~"))),
-   hasType(isInteger()))
-  .bind("Calc");
+  const auto Calc =
+  expr(anyOf(binaryOperator(
+ anyOf(hasOperatorName("+"), hasOperatorName("-"),
+   hasOperatorName("*"), hasOperatorName("<<"))),
+ unaryOperator(hasOperatorName("~"))),
+   hasType(isInteger()))
+  .bind("Calc");
 
-  auto ExplicitCast =
+  const auto ExplicitCast =
   explicitCastExpr(hasDestinationType(isInteger()), has(Calc));
-  auto ImplicitCast =
+  const auto ImplicitCast =
   implicitCastExpr(hasImplicitDestinationType(isInteger()), has(Calc));
-  auto Cast = expr(anyOf(ExplicitCast, ImplicitCast)).bind("Cast");
+  const auto Cast = expr(anyOf(ExplicitCast, ImplicitCast)).bind("Cast");
 
   Finder->addMatcher(varDecl(hasInitializer(Cast)), this);
   Finder->addMatcher(returnStmt(hasReturnValue(Cast)), this);
@@ -50,20 +50,19 @@
   binaryOperator(anyOf(hasOperatorName("=="), hasOperatorName("!="),
hasOperatorName("<"), hasOperatorName("<="),
hasOperatorName(">"), hasOperatorName(">=")),
- anyOf(hasLHS(Cast), hasRHS(Cast))),
+ hasEitherOperand(Cast)),
   this);
 }
 
-static unsigned getMaxCalculationWidth(ASTContext &Context, const Expr *E) {
+static unsigned getMaxCalculationWidth(const ASTContext &Context,
+   const Expr *E) {
   E = E->IgnoreParenImpCasts();
 
   if (const auto *Bop = dyn_cast(E)) {
 unsigned LHSWidth = getMaxCalculationWidth(Context, Bop->getLHS());
 unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS());
-if (Bop->getOpcode() == BO_Mul)
-  return LHSWidth + RHSWidth;
-if (Bop->getOpcode() == BO_Add)
-  return std::max(LHSWidth, RHSWidth) + 1;
+if (Bop->getOpcode() == BO_Mul) return LHSWidth + RHSWidth;
+if (Bop->getOpcode() == BO_Add) return std::max(LHSWidth, RHSWidth) + 1;
 if (Bop->getOpcode() == BO_Rem) {
   llvm::APSInt Val;
   if (Bop->getRHS()->EvaluateAsInt(Val, Context))
@@ -82,8 +81,7 @@
 }
   } else if (const auto *Uop = dyn_cast(E)) {
 // There is truncation when ~ is used.
-if (Uop->getOpcode() == UO_Not)
-  return 1024U;
+if (Uop->getOpcode() == UO_Not) return 1024U;
 
 QualType T = Uop->getType();
 return T->isIntegerType() ? Context.getIntWidth(T) : 1024U;
@@ -94,111 +92,134 @@
   return Context.getIntWidth(E->getType());
 }
 
-static llvm::SmallDenseMap createRelativeIntSizesMap() {
-  llvm::SmallDenseMap Result;
-  Result[BuiltinType::UChar] = 1;
-  Result[BuiltinType::SChar] = 1;
-  Result[BuiltinType::Char_U] = 1;
-  Result[BuiltinType::Char_S] = 1;
-  Result[BuiltinType::UShort] = 2;
-  Result[BuiltinType::Short] = 2;
-  Result[BuiltinType::UInt] = 3;
-  Result[BuiltinType::Int] = 3;
-  Result[BuiltinType::ULong] = 4;
-  Result[BuiltinType::Long] = 4;
-  Result[BuiltinType::ULongLong] = 5;
-  Result[BuiltinType::LongLong] = 5;
-  Result[BuiltinType::UInt128] = 6;
-  Result[BuiltinType::Int128] = 6;
-  return Result;
-}
-
-static llvm::SmallDenseMap createRelativeCharSizesMap() {
-  llvm::SmallDenseMap Result;
-  Result[BuiltinType::UChar] = 1;
-  Result[BuiltinType::SChar] = 1;
-  Result[BuiltinType::Char_U] = 1;
-  Result[BuiltinType::Char_S] = 1;
-  Result[BuiltinType::Char16] = 2;
-  Result[BuiltinType::Char32] = 3;
-  return Result;
-}
-
-static llvm::SmallDenseMap createRelativeCharSizesWMap() {
-  llvm::SmallDenseMap Result;
-  Result[BuiltinType::UChar] = 1;
-  Result[BuiltinType::SChar] = 1;
-  Result[BuiltinType::Char_U] = 1;
-  Result[BuiltinType::Char_S] = 1;
-  Result[BuiltinType::WChar_U] = 2;
-  Result[BuiltinType::WChar_S] = 2;
-  return Result;
+static int RelativeIntSizes(BuiltinType::Kind kind) {
+  switch (kind) {
+case BuiltinType::UChar:
+  return 1;
+case BuiltinType::SChar:
+  return 1;
+case BuiltinType::Char_U:
+  return 1;
+case BuiltinType::Cha

[PATCH] D18843: Always have clang pass -pie-level and -pic-level values to the code generator

2016-04-06 Thread Sriraman Tallam via cfe-commits
tmsriram created this revision.
tmsriram added reviewers: rnk, davidxl.
tmsriram added a subscriber: cfe-commits.

clang does not pass pie-level and pic-level option values to the code generator 
with "-x ir" due to the following code in CompilerInvocation.cpp:

   if (DashX == IK_AST || DashX == IK_LLVM_IR) {
   ;
} else {
   ParseLangArgs(*Res.getLangOpts(), Args, DashX, Res.getTargetOpts(), 
Diags);
}
pie-level and pic-level are LangArgs and are not parsed with "-x ir". They 
define macros __PIC__ and __PIE___ when set, see 
lib/Frontend/InitPreprocessor.cpp

Not setting LangOpts.PIELevel means that Options.PositionIndependentExecutable 
is always false even when -fPIE is used.  This patch fixes that.

I considered an alternative of making pie-level and pic-level CodeGen Options.  
However, since these options are used to set macros __PIE__, __PIC__, etc. this 
looked better as LangOpts.  Please let me know what you think.

For a broader context, I am working on optimizing accesses to global variables  
with -fPIE on x86-64 and this patch is the first step to get there.  In 
particular, I noticed the following code generated with clang:

hello.cpp:

int a = 0;

int main() {
  return a;
}

$ clang -O2 -fPIE hello.cc -S
$ cat hello.s

main:   # @main
movqa@GOTPCREL(%rip), %rax
movl(%rax), %eax
retq

Creating a GOT entry for global 'a' is unnecessary as 'a' is defined in 
hello.cpp which will be linked into a position independent executable (fPIE).  
Hence, the definition of 'a' cannot be overridden and we can remove a load. The 
efficient access is this:

main:   # @main
movla(%rip), %eax
retq

I plan to address this in a separate patch.


http://reviews.llvm.org/D18843

Files:
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2142,6 +2142,12 @@
 // what the input type is.
 if (Args.hasArg(OPT_fobjc_arc))
   Res.getLangOpts()->ObjCAutoRefCount = 1;
+// PIClevel and PIELevel are needed during code generation and this should 
be
+// set regardless of the input type.
+Res.getLangOpts()->PICLevel = getLastArgIntValue(Args, OPT_pic_level,
+ 0, Diags);
+Res.getLangOpts()->PIELevel = getLastArgIntValue(Args, OPT_pie_level,
+ 0, Diags);
 parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
 Diags, Res.getLangOpts()->Sanitize);
   } else {


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2142,6 +2142,12 @@
 // what the input type is.
 if (Args.hasArg(OPT_fobjc_arc))
   Res.getLangOpts()->ObjCAutoRefCount = 1;
+// PIClevel and PIELevel are needed during code generation and this should be
+// set regardless of the input type.
+Res.getLangOpts()->PICLevel = getLastArgIntValue(Args, OPT_pic_level,
+ 0, Diags);
+Res.getLangOpts()->PIELevel = getLastArgIntValue(Args, OPT_pie_level,
+ 0, Diags);
 parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
 Diags, Res.getLangOpts()->Sanitize);
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18808: Use the NoDebug emission kind to identify compile units that no debug info should be created from.

2016-04-06 Thread Adrian Prantl via cfe-commits

> On Apr 6, 2016, at 2:56 PM, David Blaikie  wrote:
> 
> 
> 
> On Wed, Apr 6, 2016 at 8:44 AM, Adrian Prantl  > wrote:
> 
>> On Apr 6, 2016, at 8:16 AM, David Blaikie > > wrote:
>> 
>> 
>> 
>> On Tue, Apr 5, 2016 at 10:17 PM, Eric Christopher via llvm-commits 
>> mailto:llvm-comm...@lists.llvm.org>> wrote:
>> echristo added inline comments.
>> 
>> 
>> Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:477-479
>> @@ -476,2 +476,5 @@
>> +  unsigned DebugCUs = 0;
>>for (MDNode *N : CU_Nodes->operands()) {
>>  auto *CUNode = cast(N);
>> +if (CUNode->getEmissionKind() == DICompileUnit::NoDebug)
>> +  continue;
>> 
>> Instead of this pattern would it make more sense to have an iterator over 
>> the nodes that checks for !NoDebug?
>> 
>> Yeah, that sounds like something that might be nice.
>> 
>> Adrian - I recall one of your initial ideas was to just have a different 
>> named metadata node for these subprograms.
> 
> Huh. I think I had this idea in the context of collectDeadVariables (to 
> collect dead subprograms), but I see how it would apply here, too.
> 
>> What was the motivation for not going with that plan? (which would've meant 
>> these sort of loops would've remained OK, and only the loops in the verifier 
>> and such would need to examine both nodes?) Perhaps this relates to your 
>> comment about LTOing debug+nodebug CUs? I didn't quite follow what was wrong 
>> with that in the first place & how this addresses it, could you explain it?
> 
> Most of the patches I’ve been committing recently are in preparation 
> reversing the ownership between DICompileUnit and DISubprogram (which will 
> help ThinLTO to lazy-load debug info).
> DICompileUnit will no longer have a list of “subprograms:" and instead each 
> DISubprogram will have a “unit:" field that points to the owning CU.
> 
> While it would be possible to leave the unit field empty and have a 
> NamedMDNode hold on to these subprograms, having a mandatory “unit:" point to 
> a CU that is explicitly marked NoDebug is a more regular and readable 
> representation. It’s straightforward to verify and easier to debug especially 
> in the LTO case.
> 
> Not sure whether it adds much more regularity or irregularity compared to 
> having a null unit for the subprogram, really?

My thinking was that we could then have to easily enforceable rules:

1. The DISubprograms that are part of the type hierarchy (uniqued, and 
isDefinition: false) *never* have a unit field.
2. The DISubprogram definitions (distinct) *must* have a unit field. 

> Anyone looking at the subprogram for debug purposes is going to have to walk 
> up and check that it's not a nodebug CU, the CU isn't really a CU (when 
> looking at the code/IR/etc - it'll be a weird construct)... but I dunno.

After the pointer reversal we can add a DISubprogram::isNoDebug() convenience 
accessor. For the runtime performance the extra indirection doesn’t matter 
because in each of these places we already look up the parent CU.

From a practical point of view, implementing the null unit option is actually 
quite a bit more work, given how much CGDebugInfo and DIBuilder currently 
depend on having a CU. With enough effort this can be cleaned up as well and 
this patch doesn’t prevent us from doing this in the future.

-- adrian

>  
> 
> -- adrian
> 
>>  
>> 
>> 
>> Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1127-1128
>> @@ -1115,3 +1126,4 @@
>>if (!MMI->hasDebugInfo() || LScopes.empty() ||
>> -  !MF->getFunction()->getSubprogram()) {
>> +  !MF->getFunction()->getSubprogram() ||
>> +  !SPMap.lookup(MF->getFunction()->getSubprogram())) {
>>  // If we don't have a lexical scope for this function then there will
>> 
>> Comment.
>> 
>> 
>> Repository:
>>   rL LLVM
>> 
>> http://reviews.llvm.org/D18808 
>> 
>> 
>> 
>> ___
>> llvm-commits mailing list
>> llvm-comm...@lists.llvm.org 
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits 
>> 
> 

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


r265616 - Keep -fmodule-implementation-of as an alias of -fmodule-name.

2016-04-06 Thread Manman Ren via cfe-commits
Author: mren
Date: Wed Apr  6 18:28:26 2016
New Revision: 265616

URL: http://llvm.org/viewvc/llvm-project?rev=265616&view=rev
Log:
Keep -fmodule-implementation-of as an alias of -fmodule-name.

This helps us transitioning to -fmodule-name. Once the transitioning is done,
we can remove this alias.

rdar://24800983

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/test/Modules/implementation-of-module.m

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=265616&r1=265615&r2=265616&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Apr  6 18:28:26 2016
@@ -802,6 +802,8 @@ def fmodule_name_EQ : Joined<["-"], "fmo
   Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the name of the module to build">;
 def fmodule_name : Separate<["-"], "fmodule-name">, Alias;
+def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
+  Flags<[CC1Option]>, Alias;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group, Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
   HelpText<"Load this module map file">;

Modified: cfe/trunk/test/Modules/implementation-of-module.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/implementation-of-module.m?rev=265616&r1=265615&r2=265616&view=diff
==
--- cfe/trunk/test/Modules/implementation-of-module.m (original)
+++ cfe/trunk/test/Modules/implementation-of-module.m Wed Apr  6 18:28:26 2016
@@ -1,18 +1,18 @@
 // RUN: rm -rf %t
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w 
-Werror=auto-import %s -I %S/Inputs \
-// RUN: -fmodule-name=category_right -fsyntax-only
+// RUN: -fmodule-implementation-of category_right -fsyntax-only
 
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w 
-Werror=auto-import %s -I %S/Inputs \
-// RUN: -fmodule-name=category_right -dM -E -o - 2>&1 | FileCheck %s
+// RUN: -fmodule-implementation-of category_right -dM -E -o - 2>&1 | 
FileCheck %s
 // CHECK-NOT: __building_module
 
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -w 
-Werror=auto-import %s -I %S/Inputs \
-// RUN: -fmodule-name=category_left -verify
+// RUN: -fmodule-implementation-of category_left -verify
 
 // RUN: %clang_cc1 -x objective-c-header -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
-// RUN: -fmodule-name=category_right -emit-pch -o %t.pch
+// RUN: -fmodule-implementation-of category_right -emit-pch -o %t.pch
 // RUN: %clang_cc1 -x objective-c-header -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t -w -Werror=auto-import %s -I %S/Inputs \
-// RUN: -DWITH_PREFIX -fmodules-ignore-macro=WITH_PREFIX -include-pch 
%t.pch -fmodule-name=category_right
+// RUN: -DWITH_PREFIX -fmodules-ignore-macro=WITH_PREFIX -include-pch 
%t.pch -fmodule-implementation-of category_right
 
 #ifndef WITH_PREFIX
 


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


Re: [PATCH] D18843: Always have clang pass -pie-level and -pic-level values to the code generator

2016-04-06 Thread Reid Kleckner via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm

There are similar flags, like -O, which define preprocessor macros and get fed 
to the backend. In that case, we actually have duplicate LangOpts and 
CodeGenOpts. I don't think we need to do that in this case, though.



Comment at: lib/Frontend/CompilerInvocation.cpp:2139
@@ -2138,3 +2138,3 @@
   ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args);
   if (DashX == IK_AST || DashX == IK_LLVM_IR) {
 // ObjCAAutoRefCount and Sanitize LangOpts are used to setup the

This code would probably be cleaner with a local variable `LanguageOptions 
&LangOpts = *Res.getLangOpts()`


http://reviews.llvm.org/D18843



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


r265617 - NFC: use AtomicOrdering isStrongerThan

2016-04-06 Thread JF Bastien via cfe-commits
Author: jfb
Date: Wed Apr  6 18:37:36 2016
New Revision: 265617

URL: http://llvm.org/viewvc/llvm-project?rev=265617&view=rev
Log:
NFC: use AtomicOrdering isStrongerThan

Summary: As discussed in D18775.

Reviewers: jyknight

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

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

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=265617&r1=265616&r2=265617&view=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Wed Apr  6 18:37:36 2016
@@ -447,8 +447,9 @@ static void emitAtomicCmpXchgFailureSet(
   FailureOrder = llvm::AtomicOrdering::SequentiallyConsistent;
   break;
 }
-if (FailureOrder >= SuccessOrder) {
-  // Don't assert on undefined behaviour.
+if (isStrongerThan(FailureOrder, SuccessOrder)) {
+  // Don't assert on undefined behavior "failure argument shall be no
+  // stronger than the success argument".
   FailureOrder =
 llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(SuccessOrder);
 }
@@ -1496,8 +1497,9 @@ AtomicInfo::EmitAtomicCompareExchangeLib
 std::pair AtomicInfo::EmitAtomicCompareExchange(
 RValue Expected, RValue Desired, llvm::AtomicOrdering Success,
 llvm::AtomicOrdering Failure, bool IsWeak) {
-  if (Failure >= Success)
-// Don't assert on undefined behavior.
+  if (isStrongerThan(Failure, Success))
+// Don't assert on undefined behavior "failure argument shall be no 
stronger
+// than the success argument".
 Failure = llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(Success);
 
   // Check whether we should use a library call.


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


r265621 - [CrashReproducer] Move ModuleDependencyCollector method around. NFC

2016-04-06 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Wed Apr  6 19:00:42 2016
New Revision: 265621

URL: http://llvm.org/viewvc/llvm-project?rev=265621&view=rev
Log:
[CrashReproducer] Move ModuleDependencyCollector method around. NFC

Modified:
cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp

Modified: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp?rev=265621&r1=265620&r2=265621&view=diff
==
--- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp (original)
+++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp Wed Apr  6 19:00:42 
2016
@@ -52,6 +52,24 @@ struct ModuleDependencyMMCallbacks : pub
 
 }
 
+// TODO: move this to Support/Path.h and check for HAVE_REALPATH?
+static bool real_path(StringRef SrcPath, SmallVectorImpl &RealPath) {
+#ifdef LLVM_ON_UNIX
+  char CanonicalPath[PATH_MAX];
+
+  // TODO: emit a warning in case this fails...?
+  if (!realpath(SrcPath.str().c_str(), CanonicalPath))
+return false;
+
+  SmallString<256> RPath(CanonicalPath);
+  RealPath.swap(RPath);
+  return true;
+#else
+  // FIXME: Add support for systems without realpath.
+  return false;
+#endif
+}
+
 void ModuleDependencyCollector::attachToASTReader(ASTReader &R) {
   R.addListener(llvm::make_unique(*this));
 }
@@ -81,24 +99,6 @@ void ModuleDependencyCollector::writeFil
   VFSWriter.write(OS);
 }
 
-// TODO: move this to Support/Path.h and check for HAVE_REALPATH?
-static bool real_path(StringRef SrcPath, SmallVectorImpl &RealPath) {
-#ifdef LLVM_ON_UNIX
-  char CanonicalPath[PATH_MAX];
-
-  // TODO: emit a warning in case this fails...?
-  if (!realpath(SrcPath.str().c_str(), CanonicalPath))
-return false;
-
-  SmallString<256> RPath(CanonicalPath);
-  RealPath.swap(RPath);
-  return true;
-#else
-  // FIXME: Add support for systems without realpath.
-  return false;
-#endif
-}
-
 bool ModuleDependencyCollector::getRealPath(StringRef SrcPath,
 SmallVectorImpl &Result) {
   using namespace llvm::sys;


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


r265622 - [CrashReproducer] Setup 'case-sensitive' in YAML files.

2016-04-06 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Wed Apr  6 19:00:57 2016
New Revision: 265622

URL: http://llvm.org/viewvc/llvm-project?rev=265622&view=rev
Log:
[CrashReproducer] Setup 'case-sensitive' in YAML files.

The crash reproducer was not setting up case sensitivity in the
VFS yaml files, which defaults to true. Make the crash reproducer
explicitly set that flag based on the case sensitivity of the .cache
path where vfs and modules are dumped.

Modified:
cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
cfe/trunk/test/Modules/crash-vfs-relative-overlay.m

Modified: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp?rev=265622&r1=265621&r2=265622&view=diff
==
--- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp (original)
+++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp Wed Apr  6 19:00:57 
2016
@@ -79,19 +79,42 @@ void ModuleDependencyCollector::attachTo
   llvm::make_unique(*this));
 }
 
+static bool isCaseSensitivePath(StringRef Path) {
+  SmallString TmpDest = Path, UpperDest, RealDest;
+  // Remove component traversals, links, etc.
+  if (!real_path(Path, TmpDest))
+return true; // Current default value in vfs.yaml
+  Path = TmpDest;
+
+  // Change path to all upper case and ask for its real path, if the latter
+  // exists and is equal to Path, it's not case sensitive. Default to case
+  // sensitive in the absense of realpath, since this is what the VFSWriter
+  // already expects when sensitivity isn't setup.
+  for (auto &C : Path)
+UpperDest.push_back(std::toupper(C));
+  if (real_path(UpperDest, RealDest) && Path.equals(RealDest))
+return false;
+  return true;
+}
+
 void ModuleDependencyCollector::writeFileMap() {
   if (Seen.empty())
 return;
 
-  SmallString<256> Dest = getDest();
-  llvm::sys::path::append(Dest, "vfs.yaml");
+  StringRef VFSDir = getDest();
 
   // Default to use relative overlay directories in the VFS yaml file. This
   // allows crash reproducer scripts to work across machines.
-  VFSWriter.setOverlayDir(getDest());
+  VFSWriter.setOverlayDir(VFSDir);
+
+  // Explicitly set case sensitivity for the YAML writer. For that, find out
+  // the sensitivity at the path where the headers all collected to.
+  VFSWriter.setCaseSensitivity(isCaseSensitivePath(VFSDir));
 
   std::error_code EC;
-  llvm::raw_fd_ostream OS(Dest, EC, llvm::sys::fs::F_Text);
+  SmallString<256> YAMLPath = VFSDir;
+  llvm::sys::path::append(YAMLPath, "vfs.yaml");
+  llvm::raw_fd_ostream OS(YAMLPath, EC, llvm::sys::fs::F_Text);
   if (EC) {
 HasErrors = true;
 return;

Modified: cfe/trunk/test/Modules/crash-vfs-relative-overlay.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-relative-overlay.m?rev=265622&r1=265621&r2=265622&view=diff
==
--- cfe/trunk/test/Modules/crash-vfs-relative-overlay.m (original)
+++ cfe/trunk/test/Modules/crash-vfs-relative-overlay.m Wed Apr  6 19:00:57 2016
@@ -36,6 +36,8 @@
 // CHECKSH: "-ivfsoverlay" "crash-vfs-{{[^ ]*}}.cache/vfs/vfs.yaml"
 // CHECKSH: "-fmodules-cache-path=crash-vfs-{{[^ ]*}}.cache/modules"
 
+// CHECKYAML: 'case-sensitive':
+// CHECKYAML-NEXT: 'overlay-relative': 'true',
 // CHECKYAML: 'type': 'directory'
 // CHECKYAML: 'name': "/[[PATH:.*]]/Inputs/crash-recovery/usr/include",
 // CHECKYAML-NEXT: 'contents': [


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


[PATCH] D18849: [modules] Avoid module relocation error when building modules from VFS

2016-04-06 Thread Bruno Cardoso Lopes via cfe-commits
bruno created this revision.
bruno added reviewers: rsmith, benlangmuir, klimek.
bruno added subscribers: aprantl, dexonsmith, cfe-commits.

The reproducer script (generated by the crash reproducer) invokes clang
and tries to rebuild modules using the headers in the .cache/vfs
directory. Depending on the order that modules are constructed it is
possible that there's a mismatch between the directory that a module was
constructed and the path that it was found:

fatal error: module '_Builtin_stddef_max_align_t' was built in directory
'/Users/bruno/Dev/install/clang/bin/../lib/clang//include'
but now resides in directory
'/.cache/vfs/Users/bruno/Dev/install/clang/lib/clang//include'

This happens because getFile() can leak the original path depending on
the way it's accessed. This seems to be known issue and one that demands
a lot of work to get rid of, according to:

  [cfe-dev] Module maps, __FILE__ and lazy stat'ing of header
  http://lists.llvm.org/pipermail/cfe-dev/2014-July/038273.html

I tried a couple of fixes to the issue but this is the less invasive I
could come up with. This fixes the issue by first looking into modules
by using virtual dir paths instead of the real ones. Let me know if
there's a better solution or whether I'm missing something.

With this change on Darwin we are able to simulate a crash for a simple
application using "Foundation/Foundation.h" (which relies on a bunch of
different frameworks and headers) and successfully rebuild all the
modules by relying solely at the VFS overlay.

http://reviews.llvm.org/D18849

Files:
  lib/Lex/HeaderSearch.cpp
  test/Modules/Inputs/crash-recovery/Users/bar/a.h
  test/Modules/Inputs/crash-recovery/Users/bar/bar.h
  test/Modules/Inputs/crash-recovery/Users/bar/module.modulemap
  test/Modules/Inputs/crash-recovery/Users/foo/foo.h
  test/Modules/Inputs/crash-recovery/Users/foo/module.modulemap
  test/Modules/crash-vfs-module-redefinition.m

Index: test/Modules/crash-vfs-module-redefinition.m
===
--- /dev/null
+++ test/Modules/crash-vfs-module-redefinition.m
@@ -0,0 +1,38 @@
+// REQUIRES: crash-recovery, system-darwin, shell
+
+// FIXME: This XFAIL is cargo-culted from crash-report.c. Do we need it?
+// XFAIL: mingw32
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/i %t/m %t
+
+// RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t \
+// RUN: %clang -fsyntax-only -nostdinc %s \
+// RUN:	-I %S/Inputs/crash-recovery/Users/bar \
+// RUN:	-I %S/Inputs/crash-recovery/Users -isysroot %/t/i/ \
+// RUN: -fmodules -fmodules-cache-path=%t/m/ 2>&1 | FileCheck %s
+
+// RUN: FileCheck --check-prefix=CHECKSRC %s -input-file %t/crash-vfs-*.m
+// RUN: FileCheck --check-prefix=CHECKSH %s -input-file %t/crash-vfs-*.sh
+
+#include 
+
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK-NEXT: note: diagnostic msg: {{.*}}.m
+// CHECK-NEXT: note: diagnostic msg: {{.*}}.cache
+
+// CHECKSRC: @import foo;
+
+// CHECKSH: # Crash reproducer
+// CHECKSH-NEXT: # Driver args: "-fsyntax-only"
+// CHECKSH-NEXT: # Original command: {{.*$}}
+// CHECKSH-NEXT: "-cc1"
+// CHECKSH: "-resource-dir"
+// CHECKSH: "-isysroot" "{{[^"]*}}/i/"
+// CHECKSH: "crash-vfs-{{[^ ]*}}.m"
+// CHECKSH: "-ivfsoverlay" "crash-vfs-{{[^ ]*}}.cache/vfs/vfs.yaml"
+// CHECKSH: "-fmodules-cache-path=crash-vfs-{{[^ ]*}}.cache/modules"
+
+// RUN: cd %t
+// RUN: chmod 755 crash-vfs-*.sh
+// RUN: ./crash-vfs-*.sh
Index: test/Modules/Inputs/crash-recovery/Users/foo/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/crash-recovery/Users/foo/module.modulemap
@@ -0,0 +1,3 @@
+module foo [system] [extern_c] {
+  header "foo.h"
+}
Index: test/Modules/Inputs/crash-recovery/Users/foo/foo.h
===
--- /dev/null
+++ test/Modules/Inputs/crash-recovery/Users/foo/foo.h
@@ -0,0 +1 @@
+#include 
Index: test/Modules/Inputs/crash-recovery/Users/bar/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/crash-recovery/Users/bar/module.modulemap
@@ -0,0 +1,3 @@
+module bar [system] [extern_c] {
+  header "bar.h"
+}
Index: test/Modules/Inputs/crash-recovery/Users/bar/bar.h
===
--- /dev/null
+++ test/Modules/Inputs/crash-recovery/Users/bar/bar.h
@@ -0,0 +1,6 @@
+#ifndef __CLANG_MAX_ALIGN_T_DEFINED
+#define __CLANG_MAX_ALIGN_T_DEFINED
+
+typedef long double max_align_t;
+
+#endif
Index: test/Modules/Inputs/crash-recovery/Users/bar/a.h
===
--- /dev/null
+++ test/Modules/Inputs/crash-recovery/Users/bar/a.h
@@ -0,0 +1,6 @@
+#ifndef _BAR_H
+#define _BAR_H
+
+#include "bar.h"
+
+#endif
Index: lib/Lex/HeaderSearch.cpp
===
--- lib/Lex/

Re: r265622 - [CrashReproducer] Setup 'case-sensitive' in YAML files.

2016-04-06 Thread Hans Wennborg via cfe-commits
On Wed, Apr 6, 2016 at 5:00 PM, Bruno Cardoso Lopes via cfe-commits
 wrote:
> Author: bruno
> Date: Wed Apr  6 19:00:57 2016
> New Revision: 265622
>
> URL: http://llvm.org/viewvc/llvm-project?rev=265622&view=rev
> Log:
> [CrashReproducer] Setup 'case-sensitive' in YAML files.

This doesn't compile on Windows:

C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\tools\clang\lib\Frontend\ModuleDependencyCollector.cpp(83)
: error C2065: 'PATH_MAX' : undeclared identifier
C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\tools\clang\lib\Frontend\ModuleDependencyCollector.cpp(83)
: error C2975: 'InternalLen' : invalid template argument for
'llvm::SmallString', expected compile-time constant expression

C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\include\llvm/ADT/SmallString.h(24)
: see declaration of 'InternalLen'
C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\tools\clang\lib\Frontend\ModuleDependencyCollector.cpp(94)
: error C2039: 'toupper' : is not a member of 'std'
ninja: build stopped: subcommand failed.

From 
http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/7340/steps/build%20stage%201/logs/stdio
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r265622 - [CrashReproducer] Setup 'case-sensitive' in YAML files.

2016-04-06 Thread Bruno Cardoso Lopes via cfe-commits
Thanks Hans, taking a look!

On Wed, Apr 6, 2016 at 5:49 PM, Hans Wennborg  wrote:

> On Wed, Apr 6, 2016 at 5:00 PM, Bruno Cardoso Lopes via cfe-commits
>  wrote:
> > Author: bruno
> > Date: Wed Apr  6 19:00:57 2016
> > New Revision: 265622
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=265622&view=rev
> > Log:
> > [CrashReproducer] Setup 'case-sensitive' in YAML files.
>
> This doesn't compile on Windows:
>
>
> C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\tools\clang\lib\Frontend\ModuleDependencyCollector.cpp(83)
> : error C2065: 'PATH_MAX' : undeclared identifier
>
> C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\tools\clang\lib\Frontend\ModuleDependencyCollector.cpp(83)
> : error C2975: 'InternalLen' : invalid template argument for
> 'llvm::SmallString', expected compile-time constant expression
>
> C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\include\llvm/ADT/SmallString.h(24)
> : see declaration of 'InternalLen'
>
> C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\tools\clang\lib\Frontend\ModuleDependencyCollector.cpp(94)
> : error C2039: 'toupper' : is not a member of 'std'
> ninja: build stopped: subcommand failed.
>
> From
> http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/7340/steps/build%20stage%201/logs/stdio
>



-- 
Bruno Cardoso Lopes
http://www.brunocardoso.cc
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18073: Add memory allocating functions

2016-04-06 Thread Alexander Riccio via cfe-commits
ariccio updated this revision to Diff 52876.
ariccio added a comment.

Fewer added test functions.


http://reviews.llvm.org/D18073

Files:
  llvm/tools/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  llvm/tools/clang/test/Analysis/malloc.c

Index: llvm/tools/clang/test/Analysis/malloc.c
===
--- llvm/tools/clang/test/Analysis/malloc.c
+++ llvm/tools/clang/test/Analysis/malloc.c
@@ -31,12 +31,50 @@
 wchar_t *wcsdup(const wchar_t *s);
 char *strndup(const char *s, size_t n);
 int memcmp(const void *s1, const void *s2, size_t n);
+char *tempnam(const char *dir, const char *pfx);
 
+
 // Windows variants
 char *_strdup(const char *strSource);
 wchar_t *_wcsdup(const wchar_t *strSource);
+unsigned char *_mbsdup(const unsigned char *strSource);
+
 void *_alloca(size_t size);
 
+char *_tempnam(const char *dir, const char *prefix);
+wchar_t *_wtempnam(const wchar_t *dir, const wchar_t *prefix);
+
+
+void *_calloc_dbg(size_t num, size_t size, int blockType,
+  const char *filename, int linenumber);
+
+char *_strdup_dbg(const char *strSource, int blockType,
+  const char *filename, int linenumber);
+
+wchar_t *_wcsdup_dbg(const wchar_t *strSource, int blockType,
+ const char *filename, int linenumber);
+
+unsigned char *_mbsdup_dbg(const unsigned char *strSource, int blockType,
+   const char *filename, int linenumber);
+
+char *_tempnam_dbg(const char *dir, const char *prefix, int blockType,
+   const char *filename, int linenumber);
+
+wchar_t *_wtempnam_dbg(const wchar_t *dir, const wchar_t *prefix,
+   int blockType, const char *filename, int linenumber);
+
+
+
+// Very frequently used debug versions
+void _free_dbg(void *userData, int blockType);
+void _malloc_dbg(size_t size, int blockType, const char *filename,
+ int linenumber);
+
+void *_realloc_dbg(void *userData, size_t newSize,
+   int blockType, const char *filename, int linenumber);
+
+
+
 void myfoo(int *p);
 void myfooint(int p);
 char *fooRetPtr();
@@ -291,25 +329,37 @@
 }
 
 void CheckUseZeroAllocated6() {
+  int *p = _calloc_dbg(0, 2, 0, __FILE__, __LINE__);
+  *p = 1; // expected-warning {{Use of zero-allocated memory}}
+  free(p);
+}
+
+void CheckUseZeroAllocated7() {
   int *p = calloc(2, 0);
   *p = 1; // expected-warning {{Use of zero-allocated memory}}
   free(p);
 }
 
-void CheckUseZeroAllocated7() {
+void CheckUseZeroAllocated8() {
+  int *p = _calloc_dbg(2, 0, 0, __FILE__, __LINE__);
+  *p = 1; // expected-warning {{Use of zero-allocated memory}}
+  free(p);
+}
+
+void CheckUseZeroAllocated9() {
   int *p = realloc(0, 0);
   *p = 1; // expected-warning {{Use of zero-allocated memory}}
   free(p);
 }
 
-void CheckUseZeroAllocated8() {
+void CheckUseZeroAllocated10() {
   int *p = malloc(8);
   int *q = realloc(p, 0);
   *q = 1; // expected-warning {{Use of zero-allocated memory}}
   free(q);
 }
 
-void CheckUseZeroAllocated9() {
+void CheckUseZeroAllocated11() {
   int *p = realloc(0, 0);
   int *q = realloc(p, 0);
   *q = 1; // expected-warning {{Use of zero-allocated memory}}
@@ -1126,6 +1176,26 @@
   s2[validIndex + 1] = 'b';
 } // expected-warning {{Potential leak of memory pointed to by}}
 
+void testWinMbsdup(const unsigned char *s, unsigned validIndex) {
+  unsigned char *s2 = _mbsdup(s);
+  s2[validIndex + 1] = 'b';
+} // expected-warning {{Potential leak of memory pointed to by}}
+
+void testWinMbsdupDbg(const unsigned char *s, unsigned validIndex) {
+  unsigned char *s2 = _mbsdup_dbg(s, 0, __FILE__, __LINE__);
+  s2[validIndex + 1] = 'b';
+} // expected-warning {{Potential leak of memory pointed to by}}
+
+void testStrdupDbg(const char *s, unsigned validIndex) {
+  char *s2 = _strdup_dbg(s, 0, __FILE__, __LINE__);
+  s2[validIndex + 1] = 'b';
+} // expected-warning {{Potential leak of memory pointed to by}}
+
+void testWinWcsdupDbg(const wchar_t *s, unsigned validIndex) {
+  wchar_t *s2 = _wcsdup_dbg(s, 0, __FILE__, __LINE__);
+  s2[validIndex + 1] = 'b';
+} // expected-warning {{Potential leak of memory pointed to by}}
+
 int testStrndup(const char *s, unsigned validIndex, unsigned size) {
   char *s2 = strndup(s, size);
   s2 [validIndex + 1] = 'b';
@@ -1159,6 +1229,79 @@
   free(s2);
 }
 
+void testWinMbsdupContentIsDefined(const unsigned char *s, unsigned validIndex) {
+  unsigned char *s2 = _mbsdup(s);
+  unsigned char result = s2[1];// no warning
+  free(s2);
+}
+
+void testTempnamLeak(const char* dir, const char* prefix) {
+  char* fileName = tempnam(dir, prefix);
+}// expected-warning {{Potential leak of memory pointed to by}}
+
+void testWinTempnamLeak(const char* dir, const char* prefix) {
+  char* fileName = _tempnam(dir, prefix);
+}// expected-warning {{Potential leak of memory pointed to by}}
+
+void testWinTempnamDbgLeak(const char* dir, const char* prefix) {
+  char* fileName = _tempnam_dbg(dir, prefix, 0

r265630 - [CrashReproducer] Change std::toupper to ::toupper

2016-04-06 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Wed Apr  6 20:04:09 2016
New Revision: 265630

URL: http://llvm.org/viewvc/llvm-project?rev=265630&view=rev
Log:
[CrashReproducer] Change std::toupper to ::toupper

Attempt to fix windows bots

Modified:
cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp

Modified: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp?rev=265630&r1=265629&r2=265630&view=diff
==
--- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp (original)
+++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp Wed Apr  6 20:04:09 
2016
@@ -91,7 +91,7 @@ static bool isCaseSensitivePath(StringRe
   // sensitive in the absense of realpath, since this is what the VFSWriter
   // already expects when sensitivity isn't setup.
   for (auto &C : Path)
-UpperDest.push_back(std::toupper(C));
+UpperDest.push_back(::toupper(C));
   if (real_path(UpperDest, RealDest) && Path.equals(RealDest))
 return false;
   return true;


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


Re: r265622 - [CrashReproducer] Setup 'case-sensitive' in YAML files.

2016-04-06 Thread Bruno Cardoso Lopes via cfe-commits
Attempt to fix in r265630.

On Wed, Apr 6, 2016 at 5:51 PM, Bruno Cardoso Lopes  wrote:

> Thanks Hans, taking a look!
>
> On Wed, Apr 6, 2016 at 5:49 PM, Hans Wennborg  wrote:
>
>> On Wed, Apr 6, 2016 at 5:00 PM, Bruno Cardoso Lopes via cfe-commits
>>  wrote:
>> > Author: bruno
>> > Date: Wed Apr  6 19:00:57 2016
>> > New Revision: 265622
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=265622&view=rev
>> > Log:
>> > [CrashReproducer] Setup 'case-sensitive' in YAML files.
>>
>> This doesn't compile on Windows:
>>
>>
>> C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\tools\clang\lib\Frontend\ModuleDependencyCollector.cpp(83)
>> : error C2065: 'PATH_MAX' : undeclared identifier
>>
>> C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\tools\clang\lib\Frontend\ModuleDependencyCollector.cpp(83)
>> : error C2975: 'InternalLen' : invalid template argument for
>> 'llvm::SmallString', expected compile-time constant expression
>>
>> C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\include\llvm/ADT/SmallString.h(24)
>> : see declaration of 'InternalLen'
>>
>> C:\buildbot\slave-config\clang-x86-win2008-selfhost\llvm\tools\clang\lib\Frontend\ModuleDependencyCollector.cpp(94)
>> : error C2039: 'toupper' : is not a member of 'std'
>> ninja: build stopped: subcommand failed.
>>
>> From
>> http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/7340/steps/build%20stage%201/logs/stdio
>>
>
>
>
> --
> Bruno Cardoso Lopes
> http://www.brunocardoso.cc
>



-- 
Bruno Cardoso Lopes
http://www.brunocardoso.cc
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r265630 - [CrashReproducer] Change std::toupper to ::toupper

2016-04-06 Thread Sean Silva via cfe-commits
We also have toUppercase in include/clang/Basic/CharInfo.h

-- Sean Silva

On Wed, Apr 6, 2016 at 6:04 PM, Bruno Cardoso Lopes via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: bruno
> Date: Wed Apr  6 20:04:09 2016
> New Revision: 265630
>
> URL: http://llvm.org/viewvc/llvm-project?rev=265630&view=rev
> Log:
> [CrashReproducer] Change std::toupper to ::toupper
>
> Attempt to fix windows bots
>
> Modified:
> cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
>
> Modified: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp?rev=265630&r1=265629&r2=265630&view=diff
>
> ==
> --- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp (original)
> +++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp Wed Apr  6
> 20:04:09 2016
> @@ -91,7 +91,7 @@ static bool isCaseSensitivePath(StringRe
>// sensitive in the absense of realpath, since this is what the
> VFSWriter
>// already expects when sensitivity isn't setup.
>for (auto &C : Path)
> -UpperDest.push_back(std::toupper(C));
> +UpperDest.push_back(::toupper(C));
>if (real_path(UpperDest, RealDest) && Path.equals(RealDest))
>  return false;
>return true;
>
>
> ___
> 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


r265632 - [CrashReproducer] Use toUppercase from include/clang/Basic/CharInfo.h

2016-04-06 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Wed Apr  6 20:12:18 2016
New Revision: 265632

URL: http://llvm.org/viewvc/llvm-project?rev=265632&view=rev
Log:
[CrashReproducer] Use toUppercase from include/clang/Basic/CharInfo.h

Use toUppercase instead of ::toupper()

Modified:
cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp

Modified: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp?rev=265632&r1=265631&r2=265632&view=diff
==
--- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp (original)
+++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp Wed Apr  6 20:12:18 
2016
@@ -11,6 +11,7 @@
 //
 
//===--===//
 
+#include "clang/Basic/CharInfo.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
@@ -91,7 +92,7 @@ static bool isCaseSensitivePath(StringRe
   // sensitive in the absense of realpath, since this is what the VFSWriter
   // already expects when sensitivity isn't setup.
   for (auto &C : Path)
-UpperDest.push_back(::toupper(C));
+UpperDest.push_back(toUppercase(C));
   if (real_path(UpperDest, RealDest) && Path.equals(RealDest))
 return false;
   return true;


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


Re: r265630 - [CrashReproducer] Change std::toupper to ::toupper

2016-04-06 Thread Bruno Cardoso Lopes via cfe-commits
Better yet. Committed r265632

Thanks Sean,

On Wed, Apr 6, 2016 at 6:11 PM, Sean Silva  wrote:

> We also have toUppercase in include/clang/Basic/CharInfo.h
>
> -- Sean Silva
>
> On Wed, Apr 6, 2016 at 6:04 PM, Bruno Cardoso Lopes via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: bruno
>> Date: Wed Apr  6 20:04:09 2016
>> New Revision: 265630
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=265630&view=rev
>> Log:
>> [CrashReproducer] Change std::toupper to ::toupper
>>
>> Attempt to fix windows bots
>>
>> Modified:
>> cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
>>
>> Modified: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp?rev=265630&r1=265629&r2=265630&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp (original)
>> +++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp Wed Apr  6
>> 20:04:09 2016
>> @@ -91,7 +91,7 @@ static bool isCaseSensitivePath(StringRe
>>// sensitive in the absense of realpath, since this is what the
>> VFSWriter
>>// already expects when sensitivity isn't setup.
>>for (auto &C : Path)
>> -UpperDest.push_back(std::toupper(C));
>> +UpperDest.push_back(::toupper(C));
>>if (real_path(UpperDest, RealDest) && Path.equals(RealDest))
>>  return false;
>>return true;
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>


-- 
Bruno Cardoso Lopes
http://www.brunocardoso.cc
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18618: [ObjC] Pop all cleanups created in CodeGenFunction::EmitObjCForCollectionStmt

2016-04-06 Thread John McCall via cfe-commits
rjmccall added a comment.

LGTM, thanks!


http://reviews.llvm.org/D18618



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


[PATCH] D18852: [clang-tidy] fix a crash with -fdelayed-template-parsing in UnnecessaryValueParamCheck.

2016-04-06 Thread Etienne Bergeron via cfe-commits
etienneb created this revision.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.


This is the same kind of bug that [[ http://reviews.llvm.org/D18238 | D18238 ]].

Fix crashes caused by deferencing null pointer when declarations parsing may be 
delayed.
The body of the declarations may be null.

The crashes were observed with a Windows build of clang-tidy and the following 
command-line.
```
command-line switches: -fms-compatibility-version=19 -fms-compatibility
```

http://reviews.llvm.org/D18852

Files:
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp

Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -51,6 +51,10 @@
   bool IsConstQualified =
   Param->getType().getCanonicalType().isConstQualified();
 
+  // Skip declarations delayed by late template parsing without a body.
+  if (!Function->getBody())
+return;
+
   // Do not trigger on non-const value parameters when:
   // 1. they are in a constructor definition since they can likely trigger
   //misc-move-constructor-init which will suggest to move the argument.


Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -51,6 +51,10 @@
   bool IsConstQualified =
   Param->getType().getCanonicalType().isConstQualified();
 
+  // Skip declarations delayed by late template parsing without a body.
+  if (!Function->getBody())
+return;
+
   // Do not trigger on non-const value parameters when:
   // 1. they are in a constructor definition since they can likely trigger
   //misc-move-constructor-init which will suggest to move the argument.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18170: [CUDA][OpenMP] Create generic offload toolchains

2016-04-06 Thread Samuel Antao via cfe-commits
sfantao updated this revision to Diff 52878.
sfantao marked 6 inline comments as done.
sfantao added a comment.

Address Art and Eric comments.


http://reviews.llvm.org/D18170

Files:
  include/clang/Driver/Action.h
  include/clang/Driver/Compilation.h
  include/clang/Driver/Driver.h
  lib/Driver/Compilation.cpp
  lib/Driver/Driver.cpp
  lib/Driver/Tools.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3620,10 +3620,10 @@
 // particular compilation pass we're constructing here. For now we
 // can check which toolchain we're using and pick the other one to
 // extract the triple.
-if (&getToolChain() == C.getCudaDeviceToolChain())
-  AuxToolChain = C.getCudaHostToolChain();
-else if (&getToolChain() == C.getCudaHostToolChain())
-  AuxToolChain = C.getCudaDeviceToolChain();
+if (&getToolChain() == C.getSingleOffloadToolChain())
+  AuxToolChain = C.getOffloadingHostToolChain();
+else if (&getToolChain() == C.getOffloadingHostToolChain())
+  AuxToolChain = C.getSingleOffloadToolChain();
 else
   llvm_unreachable("Can't figure out CUDA compilation mode.");
 assert(AuxToolChain != nullptr && "No aux toolchain.");
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -396,6 +396,31 @@
   }
 }
 
+void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
+  InputList &Inputs) {
+
+  //
+  // CUDA
+  //
+  // We need to generate a CUDA toolchain if any of the inputs has a CUDA type.
+  if (llvm::any_of(Inputs, [](std::pair &I) {
+return types::isCuda(I.first);
+  })) {
+const ToolChain &TC = getToolChain(
+C.getInputArgs(),
+llvm::Triple(C.getOffloadingHostToolChain()->getTriple().isArch64Bit()
+ ? "nvptx64-nvidia-cuda"
+ : "nvptx-nvidia-cuda"));
+C.addOffloadDeviceToolChain(&TC, Action::OFK_Cuda);
+  }
+
+  //
+  // TODO: Add support for other offloading programming models here.
+  //
+
+  return;
+}
+
 Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   llvm::PrettyStackTraceString CrashInfo("Compilation construction");
 
@@ -514,18 +539,8 @@
   InputList Inputs;
   BuildInputs(C->getDefaultToolChain(), *TranslatedArgs, Inputs);
 
-  // Initialize the CUDA device TC only if we have any CUDA Inputs.  This is
-  // necessary so that we don't break compilations that pass flags that are
-  // incompatible with the NVPTX TC (e.g. -mthread-model single).
-  if (llvm::any_of(Inputs, [](const std::pair &I) {
-return I.first == types::TY_CUDA || I.first == types::TY_PP_CUDA ||
-   I.first == types::TY_CUDA_DEVICE;
-  })) {
-C->setCudaDeviceToolChain(
-&getToolChain(C->getArgs(), llvm::Triple(TC.getTriple().isArch64Bit()
- ? "nvptx64-nvidia-cuda"
- : "nvptx-nvidia-cuda")));
-  }
+  // Populate the tool chains for the offloading devices, if any.
+  CreateOffloadingDeviceToolChains(*C, Inputs);
 
   // Construct the list of abstract actions to perform for this compilation. On
   // MachO targets this uses the driver-driver and universal actions.
@@ -1340,7 +1355,7 @@
 CudaDeviceInputs.push_back(std::make_pair(types::TY_CUDA_DEVICE, InputArg));
 
   // Build actions for all device inputs.
-  assert(C.getCudaDeviceToolChain() &&
+  assert(C.getSingleOffloadToolChain() &&
  "Missing toolchain for device-side compilation.");
   ActionList CudaDeviceActions;
   C.getDriver().BuildActions(C, Args, CudaDeviceInputs, CudaDeviceActions);
@@ -1980,7 +1995,7 @@
 // Initial processing of CudaDeviceAction carries host params.
 // Call BuildJobsForAction() again, now with correct device parameters.
 InputInfo II = BuildJobsForAction(
-C, *CDA->input_begin(), C.getCudaDeviceToolChain(),
+C, *CDA->input_begin(), C.getSingleOffloadToolChain(),
 CDA->getGpuArchName(), CDA->isAtTopLevel(), /*MultipleArchs=*/true,
 LinkingOutput, CachedResults);
 // Currently II's Action is *CDA->input_begin().  Set it to CDA instead, so
Index: lib/Driver/Compilation.cpp
===
--- lib/Driver/Compilation.cpp
+++ lib/Driver/Compilation.cpp
@@ -24,10 +24,13 @@
 
 Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain,
  InputArgList *_Args, DerivedArgList *_TranslatedArgs)
-: TheDriver(D), DefaultToolChain(_DefaultToolChain),
-  CudaHostToolChain(&DefaultToolChain), CudaDeviceToolChain(nullptr),
+: TheDriver(D), DefaultToolChain(_DefaultToolChain), ActiveOffloadMask(0u),
   Args(_Args), TranslatedArgs(_TranslatedArgs), Redirects(nullptr),
-  ForDiag

  1   2   >