[PATCH] D35479: [CodeGen][mips] Support `long_call/far/near` attributes

2017-07-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Hmm.  Could you invert those conditions so that they early-return, just for 
consistency?  Sorry this is dragging out so long, and thanks for being so 
patient.




Comment at: lib/CodeGen/TargetInfo.cpp:2357
+return;
+  X86_32TargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition);
 

rjmccall wrote:
> That function has its own early exit, so do the early exit after calling it, 
> please.
Here.



Comment at: lib/CodeGen/TargetInfo.cpp:2401
+  if (!IsForDefinition)
+return;
+  TargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition);

And this one should go after the call; I just missed it in the earlier reviews.



Comment at: lib/CodeGen/TargetInfo.cpp:5535
+  ARMTargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition);
+  if (IsForDefinition)
+addStackProbeSizeTargetAttribute(D, GV, CGM);

Here.


Repository:
  rL LLVM

https://reviews.llvm.org/D35479



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


[PATCH] D35661: [clang] Implement P0704: "Fixing const-qualified pointers to members"

2017-07-20 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev created this revision.

https://reviews.llvm.org/D35661

Files:
  lib/Sema/SemaExprCXX.cpp
  test/CXX/expr/expr.mptr.oper/p7-1z.cpp


Index: test/CXX/expr/expr.mptr.oper/p7-1z.cpp
===
--- test/CXX/expr/expr.mptr.oper/p7-1z.cpp
+++ test/CXX/expr/expr.mptr.oper/p7-1z.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s
+
+struct X { };
+
+template T& lvalue();
+template T&& xvalue();
+template T prvalue();
+
+// In a .* expression whose object expression is an rvalue, the
+// program is ill-formed if the second operand is a pointer to member
+// function with (non-const, C++17) ref-qualifier &.
+// In a ->* expression or in a .* expression whose object
+// expression is an lvalue, the program is ill-formed if the second
+// operand is a pointer to member function with ref-qualifier &&.
+void test(X *xp, int (X::*pmf)(int), int (X::*l_pmf)(int) &, 
+  int (X::*r_pmf)(int) &&, int (X::*cl_pmf)(int) const &,
+  int (X::*cr_pmf)(int) const &&) {
+  // No ref-qualifier.
+  (lvalue().*pmf)(17);
+  (xvalue().*pmf)(17);
+  (prvalue().*pmf)(17);
+  (xp->*pmf)(17);
+
+  // Lvalue ref-qualifier.
+  (lvalue().*l_pmf)(17);
+  (xvalue().*l_pmf)(17); // expected-error-re{{pointer-to-member function 
type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &' can only be 
called on an lvalue}}
+  (prvalue().*l_pmf)(17); // expected-error-re{{pointer-to-member function 
type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &' can only be 
called on an lvalue}}
+  (xp->*l_pmf)(17);
+
+  // Rvalue ref-qualifier.
+  (lvalue().*r_pmf)(17); // expected-error-re{{pointer-to-member function 
type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &&' can only be 
called on an rvalue}}
+  (xvalue().*r_pmf)(17);
+  (prvalue().*r_pmf)(17);
+  (xp->*r_pmf)(17);  // expected-error-re{{pointer-to-member function type 
'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &&' can only be called on 
an rvalue}}
+
+  // Lvalue const ref-qualifier.
+  (lvalue().*cl_pmf)(17);
+  (xvalue().*cl_pmf)(17);
+  (prvalue().*cl_pmf)(17);
+  (xp->*cl_pmf)(17);
+
+  // Rvalue const ref-qualifier.
+  (lvalue().*cr_pmf)(17); // expected-error-re{{pointer-to-member function 
type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} const &&' can only 
be called on an rvalue}}
+  (xvalue().*cr_pmf)(17);
+  (prvalue().*cr_pmf)(17);
+  (xp->*cr_pmf)(17);  // expected-error-re{{pointer-to-member function type 
'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} const &&' can only be 
called on an rvalue}}
+}
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -5178,9 +5178,11 @@
   break;
 
 case RQ_LValue:
-  if (!isIndirect && !LHS.get()->Classify(Context).isLValue())
-Diag(Loc, diag::err_pointer_to_member_oper_value_classify)
-  << RHSType << 1 << LHS.get()->getSourceRange();
+  if (!isIndirect && !LHS.get()->Classify(Context).isLValue()) {
+if (!getLangOpts().CPlusPlus1z || !Proto->isConst())
+  Diag(Loc, diag::err_pointer_to_member_oper_value_classify)
+<< RHSType << 1 << LHS.get()->getSourceRange();
+  }
   break;
 
 case RQ_RValue:


Index: test/CXX/expr/expr.mptr.oper/p7-1z.cpp
===
--- test/CXX/expr/expr.mptr.oper/p7-1z.cpp
+++ test/CXX/expr/expr.mptr.oper/p7-1z.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s
+
+struct X { };
+
+template T& lvalue();
+template T&& xvalue();
+template T prvalue();
+
+// In a .* expression whose object expression is an rvalue, the
+// program is ill-formed if the second operand is a pointer to member
+// function with (non-const, C++17) ref-qualifier &.
+// In a ->* expression or in a .* expression whose object
+// expression is an lvalue, the program is ill-formed if the second
+// operand is a pointer to member function with ref-qualifier &&.
+void test(X *xp, int (X::*pmf)(int), int (X::*l_pmf)(int) &, 
+  int (X::*r_pmf)(int) &&, int (X::*cl_pmf)(int) const &,
+  int (X::*cr_pmf)(int) const &&) {
+  // No ref-qualifier.
+  (lvalue().*pmf)(17);
+  (xvalue().*pmf)(17);
+  (prvalue().*pmf)(17);
+  (xp->*pmf)(17);
+
+  // Lvalue ref-qualifier.
+  (lvalue().*l_pmf)(17);
+  (xvalue().*l_pmf)(17); // expected-error-re{{pointer-to-member function type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &' can only be called on an lvalue}}
+  (prvalue().*l_pmf)(17); // expected-error-re{{pointer-to-member function type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &' can only be called on an lvalue}}
+  (xp->*l_pmf)(17);
+
+  // Rvalue ref-qualifier.
+  (lvalue().*r_pmf)(17); // expected-error-re{{pointer-to-member function type 'int (X::*)(int){{( __attribute__\(\(thiscall\)\))?}} &&' can only be call

r308593 - clang/module.modulemap: Clang_Diagnostics: Activate "Sema/SemaDiagnostic.h".

2017-07-20 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Thu Jul 20 00:51:47 2017
New Revision: 308593

URL: http://llvm.org/viewvc/llvm-project?rev=308593&view=rev
Log:
clang/module.modulemap: Clang_Diagnostics: Activate "Sema/SemaDiagnostic.h".

It seems issues were resolved.

Modified:
cfe/trunk/include/clang/module.modulemap

Modified: cfe/trunk/include/clang/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/module.modulemap?rev=308593&r1=308592&r2=308593&view=diff
==
--- cfe/trunk/include/clang/module.modulemap (original)
+++ cfe/trunk/include/clang/module.modulemap Thu Jul 20 00:51:47 2017
@@ -69,8 +69,7 @@ module Clang_Diagnostics {
   module Frontend { header "Frontend/FrontendDiagnostic.h" export * }
   module Lex { header "Lex/LexDiagnostic.h" export * }
   module Parse { header "Parse/ParseDiagnostic.h" export * }
-  // FIXME: This breaks the build of Clang_Sema, for unknown reasons.
-  //module Sema { header "Sema/SemaDiagnostic.h" export * }
+  module Sema { header "Sema/SemaDiagnostic.h" export * }
   module Serialization { header "Serialization/SerializationDiagnostic.h" 
export * }
 }
 


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


[PATCH] D35479: [CodeGen][mips] Support `long_call/far/near` attributes

2017-07-20 Thread Simon Atanasyan via Phabricator via cfe-commits
atanasyan updated this revision to Diff 107461.
atanasyan added a comment.

Addressed review comments.


Repository:
  rL LLVM

https://reviews.llvm.org/D35479

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/long-call-attr.c
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/Sema/attr-long-call.c

Index: test/Sema/attr-long-call.c
===
--- /dev/null
+++ test/Sema/attr-long-call.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple mips-linux-gnu -fsyntax-only -verify %s
+
+__attribute__((long_call(0))) void foo1();  // expected-error {{'long_call' attribute takes no arguments}}
+__attribute__((far(0))) void foo2();  // expected-error {{'far' attribute takes no arguments}}
+__attribute__((near(0))) void foo3();  // expected-error {{'near' attribute takes no arguments}}
+
+__attribute((long_call)) int a; // expected-warning {{attribute only applies to functions}}
+__attribute((far)) int a; // expected-warning {{attribute only applies to functions}}
+__attribute((near)) int a; // expected-warning {{attribute only applies to functions}}
+
+__attribute((long_call)) void foo4();
+__attribute((far)) void foo5();
+__attribute((near)) void foo6();
+
+__attribute((long_call, far)) void foo7();
+
+__attribute((far, near)) void foo8(); // expected-error {{'far' and 'near' attributes are not compatible}} \
+  // expected-note {{conflicting attribute is here}}
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 62 attributes:
+// CHECK: #pragma clang attribute supports 64 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -31,6 +31,8 @@
 // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record)
 // CHECK-NEXT: MicroMips (SubjectMatchRule_function)
+// CHECK-NEXT: MipsLongCall (SubjectMatchRule_function)
+// CHECK-NEXT: MipsShortCall (SubjectMatchRule_function)
 // CHECK-NEXT: NoDebug (SubjectMatchRule_hasType_functionType, SubjectMatchRule_objc_method, SubjectMatchRule_variable_not_is_parameter)
 // CHECK-NEXT: NoDuplicate (SubjectMatchRule_function)
 // CHECK-NEXT: NoMicroMips (SubjectMatchRule_function)
Index: test/CodeGen/long-call-attr.c
===
--- /dev/null
+++ test/CodeGen/long-call-attr.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple mips-linux-gnu -emit-llvm  -o  - %s | FileCheck %s
+
+void __attribute__((long_call)) foo1 (void);
+
+void __attribute__((far)) foo2 (void) {}
+
+// CHECK: define void @foo2() [[FAR:#[0-9]+]]
+
+void __attribute__((near)) foo3 (void) { foo1(); }
+
+// CHECK: define void @foo3() [[NEAR:#[0-9]+]]
+
+// CHECK: declare void @foo1() [[LONGDECL:#[0-9]+]]
+
+// CHECK: attributes [[FAR]] = { {{.*}} "long-call" {{.*}} }
+// CHECK: attributes [[NEAR]] = { {{.*}} "short-call" {{.*}} }
+// CHECK: attributes [[LONGDECL]] = { {{.*}} "long-call" {{.*}} }
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5965,6 +5965,14 @@
   case AttributeList::AT_NoMicroMips:
 handleSimpleAttribute(S, D, Attr);
 break;
+  case AttributeList::AT_MipsLongCall:
+handleSimpleAttributeWithExclusions(
+S, D, Attr);
+break;
+  case AttributeList::AT_MipsShortCall:
+handleSimpleAttributeWithExclusions(
+S, D, Attr);
+break;
   case AttributeList::AT_AMDGPUFlatWorkGroupSize:
 handleAMDGPUFlatWorkGroupSizeAttr(S, D, Attr);
 break;
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H
 #define LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H
 
+#include "CodeGenModule.h"
 #include "CGValue.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/LLVM.h"
@@ -34,7 +35,6 @@
 namespace CodeGen {
 class ABIInfo;
 class CallArgList;
-class CodeGenModule;
 class CodeGenFunction;
 class CGFunctionInfo;
 
@@ -55,7 +55,8 @@
   /// setTargetAttributes - Provides a convenient hook to handle extra
   /// target-specific attributes for the given global.
   virtual void setTargetAttributes(const Decl *D

[PATCH] D35613: Add Support for Generic Reference Counting Annotations in RetainCountChecker

2017-07-20 Thread Malhar Thakkar via Phabricator via cfe-commits
malhar1995 added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp:2012
+  } else if (CurrV.getObjKind() == RetEffect::GenericC) {
+if (Sym->getType().isNull()) {
+  os << " returns an object with a ";

NoQ wrote:
> I don't think this can happen. Symbols always have a type, see 
> `isValidTypeForSymbol()`. These branches can be removed from the surrounding 
> code as well.
So, you're saying `Sym->getType()` can never be NULL?
If so, do you want me to insert `assert(isValidTypeForSymbol(Sym->getType()))` 
instead? 


Repository:
  rL LLVM

https://reviews.llvm.org/D35613



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


[PATCH] D35613: Add Support for Generic Reference Counting Annotations in RetainCountChecker

2017-07-20 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp:2012
+  } else if (CurrV.getObjKind() == RetEffect::GenericC) {
+if (Sym->getType().isNull()) {
+  os << " returns an object with a ";

malhar1995 wrote:
> NoQ wrote:
> > I don't think this can happen. Symbols always have a type, see 
> > `isValidTypeForSymbol()`. These branches can be removed from the 
> > surrounding code as well.
> So, you're saying `Sym->getType()` can never be NULL?
> If so, do you want me to insert 
> `assert(isValidTypeForSymbol(Sym->getType()))` instead? 
This assertion is already there in Sym's constructor (of the whole `SymExpr` 
class), and symbols are also immutable, so it's already verified and you can 
just rely on it and remove the branch in your `if` (and probably nearby `if`s 
as well).


Repository:
  rL LLVM

https://reviews.llvm.org/D35613



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


[PATCH] D35483: clang-format: fix block OpeningLineIndex around preprocessor

2017-07-20 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/UnwrappedLineParser.cpp:464
+  for (const auto &i : PPStack) {
+hash_combine(h, i.Kind);
+hash_combine(h, i.Line);

When I patch this, I get an `UnwrappedLineParser.cpp:457:16 error: implicit 
instantiation of undefined template 
'std::hash'`. 



Comment at: lib/Format/UnwrappedLineParser.h:158
   bool isOnNewLine(const FormatToken &FormatTok);
+  size_t computePPHash() const;
 

Please add a short comment of why is the preprocessor hash needed.



Comment at: lib/Format/UnwrappedLineParser.h:213
+PPBranch(PPBranchKind Kind, size_t Line) : Kind(Kind), Line(Line) {}
+bool operator==(PPBranchKind Kind) const { return Kind == this->Kind; }
+PPBranchKind Kind;

This `operator==` is confusing. Please remove it.


https://reviews.llvm.org/D35483



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


[PATCH] D34654: Allow passing a regex for headers to exclude from clang-tidy

2017-07-20 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

I wonder whether anyone uses file patterns that need anything from regular 
expressions beyond `|` and `.*`. If not, globs (as used in -checks=) would be a 
better solution.

One problem with a header-filter + exclude-header-filter is that it doesn't 
make it easier to express restrictions similar to "everything under a/ (except 
for everything under a/b/ (except for everything under a/b/c/))".


Repository:
  rL LLVM

https://reviews.llvm.org/D34654



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


[PATCH] D35613: Add Support for Generic Reference Counting Annotations in RetainCountChecker

2017-07-20 Thread Malhar Thakkar via Phabricator via cfe-commits
malhar1995 updated this revision to Diff 107471.
malhar1995 added a comment.

Removed the checks to see if the symbol type is NULL while printing diagnostics 
as they are unnecessary.


Repository:
  rL LLVM

https://reviews.llvm.org/D35613

Files:
  include/clang/StaticAnalyzer/Checkers/ObjCRetainCount.h
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  test/Analysis/retain-release-inline.m
  test/Analysis/retain-release.m

Index: test/Analysis/retain-release.m
===
--- test/Analysis/retain-release.m
+++ test/Analysis/retain-release.m
@@ -325,6 +325,9 @@
 
 extern
 void *CFPlugInInstanceCreate(CFAllocatorRef allocator, CFUUIDRef factoryUUID, CFUUIDRef typeUUID);
+typedef struct {
+  int ref;
+} isl_basic_map;
 
 //===--===//
 // Test cases.
@@ -574,6 +577,14 @@
   }
 }
 
+__attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *isl_basic_map_cow(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap);
+
+// Test custom diagnostics for generalized objects.
+void f18(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) {
+  // After this call, 'bmap' has a +1 reference count.
+  bmap = isl_basic_map_cow(bmap); // expected-warning {{Potential leak of an object}}
+}
+
 // Test basic tracking of ivars associated with 'self'.  For the retain/release
 // checker we currently do not want to flag leaks associated with stores
 // of tracked objects to ivars.
Index: test/Analysis/retain-release-inline.m
===
--- test/Analysis/retain-release-inline.m
+++ test/Analysis/retain-release-inline.m
@@ -299,15 +299,15 @@
   bar(s);
 }
 
-__attribute__((cf_returns_retained)) isl_basic_map *isl_basic_map_cow(__attribute__((cf_consumed)) isl_basic_map *bmap);
+__attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *isl_basic_map_cow(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap);
 void free(void *);
 
 // As 'isl_basic_map_free' is annotated with 'rc_ownership_trusted_implementation', RetainCountChecker trusts its
 // implementation and doesn't analyze its body. If the annotation 'rc_ownership_trusted_implementation' is removed,
 // a leak warning is raised by RetainCountChecker as the analyzer is unable to detect a decrement in the reference
 // count of 'bmap' along the path in 'isl_basic_map_free' assuming the predicate of the second 'if' branch to be
 // true or assuming both the predicates in the function to be false.
-__attribute__((annotate("rc_ownership_trusted_implementation"))) isl_basic_map *isl_basic_map_free(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+__attribute__((annotate("rc_ownership_trusted_implementation"))) isl_basic_map *isl_basic_map_free(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) {
   if (!bmap)
 return NULL;
 
@@ -322,15 +322,15 @@
 // implementation and doesn't analyze its body. If that annotation is removed, a 'use-after-release' warning might
 // be raised by RetainCountChecker as the pointer which is passed as an argument to this function and the pointer
 // which is returned from the function point to the same memory location.
-__attribute__((annotate("rc_ownership_trusted_implementation"))) __attribute__((cf_returns_retained)) isl_basic_map *isl_basic_map_copy(isl_basic_map *bmap) {
+__attribute__((annotate("rc_ownership_trusted_implementation"))) __attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *isl_basic_map_copy(isl_basic_map *bmap) {
   if (!bmap)
 return NULL;
 
   bmap->ref++;
   return bmap;
 }
 
-void test_use_after_release_with_trusted_implementation_annotate_attribute(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+void test_use_after_release_with_trusted_implementation_annotate_attribute(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) {
   // After this call, 'bmap' has a +1 reference count.
   bmap = isl_basic_map_cow(bmap);
   // After the call to 'isl_basic_map_copy', 'bmap' has a +1 reference count.
@@ -341,7 +341,7 @@
   isl_basic_map_free(temp);
 }
 
-void test_leak_with_trusted_implementation_annotate_attribute(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+void test_leak_with_trusted_implementation_annotate_attribute(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) {
   // After this call, 'bmap' has a +1 reference count.
   bmap = isl_basic_map_cow(bmap); // no-warning
   // After this call, 'bmap' has a +0 reference count.
Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1340,6 +1340,8 @@
 
   if (D->hasAttr())
 return RetEffect::MakeOwned(RetEffect::CF);
+  else if (hasR

[PATCH] D35406: [clangd] Replace ASTUnit with manual AST management.

2017-07-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdUnit.cpp:167
+std::move(VFS));
+  CI->getFrontendOpts().DisableFree = false;
+  return CI;

krasimir wrote:
> Why `DisableFree`?
We rely on CompilerInstance to free the resources. It won't do that if 
`DisableFree` is set to true. Added a comment about that.



Comment at: clangd/ClangdUnit.cpp:251
+CompilerInstance::createDiagnostics(new DiagnosticOptions,
+&CommandLineDiagsConsumer, false);
+CI = createCompilerInvocation(ArgStrs, CommandLineDiagsEngine, VFS);

krasimir wrote:
> What's the purpose of this local scope here?
> Wouldn't &CommandLineDiagsConsumer point to garbage after the end of this 
> local scope?
This `DiagnosticsEngine` is not stored in `CompilerInvocation` created here, it 
is used for reporting errors during command-line parsing.
Since we don't show those errors to the user, we discard them.

Local scope is there to avoid referencing `CommandLineDiagsEngine` later (as it 
will discard diagnostics, and we actually want to have them).



Comment at: clangd/ClangdUnit.cpp:262
+  ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
+  if (!Preamble || !Preamble->Preamble.CanReuse(*CI, ContentsBuffer.get(),
+Bounds, VFS.get())) {

krasimir wrote:
> We can not compute `Bounds`, `if (Preamble)`.
When `Preamble` is set, we need `Bounds` for `Preamble.CanReuse`.
When `Preamble` is not set, we need `Bounds` for `PrecompiledPreamble::Build`.

So we need them in both cases.



Comment at: clangd/ClangdUnit.cpp:268
+CompilerInstance::createDiagnostics(
+&CI->getDiagnosticOpts(), &PreambleDiagnosticsConsumer, false);
+ClangdUnitPreambleCallbacks SerializedDeclsCollector;

krasimir wrote:
> Here `PreambleDiagsEngine` holds a pointer to the local variable 
> `PreambleDiagnosticsConsumer`.
> Next, `BuiltPreamble` holds a reference to `PreambleDiagsEngine`.
> Next, `Preamble` is created by moving `BuiltPreamble`.
> Doesn't then `Preamble` hold a transitive reference to junk after this local 
> scope?
I don't think `BuiltPreamble` holds a reference to `PreambleDiagsEngine`.  Here 
is a list of fields of `PrecompiledPreamble` class:


```
  //...
  TempPCHFile PCHFile;
  llvm::StringMap FilesInPreamble;
  std::vector PreambleBytes;
  bool PreambleEndsAtStartOfLine;
```




Comment at: clangd/ClangdUnit.cpp:404
+CI = createCompilerInvocation(ArgStrs, CommandLineDiagsEngine, VFS);
+  }
+  assert(CI && "Couldn't create CompilerInvocation");

krasimir wrote:
> what's the purpose of this local scope?
The `DiagnosticsEngine` used here uses default `DiagnosticOptions`.
A one that's properly configured after reading command-line arguments is 
created below, inside a `prepareCompilerInstance` call.
To avoid using `DiagnosticsEngine` configured by default, it is put into a 
local scope.



Comment at: clangd/ClangdUnit.cpp:691
+
+void ClangdUnit::ParsedAST::ensurePreambleDeclsDeserialized() {
+  if (PendingTopLevelDecls.empty())

krasimir wrote:
> Why do we need to ensure that Decls are deserialized?
These Decls are used in `findDefinitions` (specifically, they are passed to 
`indexTopLevelDecls`). I've opted for mimicing the `ASTUnit` behaviour here.

It is possible that visiting only local decls (i.e. not from `Preamble`) will 
not break anything. But that requires thorough testing and digging into how 
PCHs works (one question is, if it is possible to have decls from the same file 
as part of the PCH). I actually want to investigate if we actually need all 
that deserializing logic here, but would prefer to do that with a separate 
change to keep semantic changes related to this commit as small as possible.

PS. Alternatively, we could just visit all decls in `ASTContext` whenever we 
need them for `findDefinitions`, but [[ 
https://reviews.llvm.org/diffusion/L/browse/cfe/trunk/include/clang/Frontend/ASTUnit.h;308597$149
 | a comment in ASTUnit]] says it's slower.



Comment at: clangd/ClangdUnit.h:77
+  /// Stores and provides access to parsed AST.
+  class ParsedAST {
+  public:

krasimir wrote:
> Why is this a separate class and not just part of `ClangdUnit`?
For managing the lifetime of an AST. Specifically:
 - there is a destructor here that calls `EndSourceFile` to free AST-related 
resources,
 - all getters return references to objects that either have pointers to 
resources, managed by `ParsedAST` (`getASTContext`, `getPreprocessor`, etc) or 
semantically tied to this specific parsing result(`getDiagnostics`, 
`PendingTopLevelDecls`).

`ClangdUnit` is managing two things at the moment: a preamble and an AST. Since 
the lifetime o

[PATCH] D35406: [clangd] Replace ASTUnit with manual AST management.

2017-07-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 107475.
ilya-biryukov added a comment.

Added a few comments.


https://reviews.llvm.org/D35406

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h

Index: clangd/ClangdUnit.h
===
--- clangd/ClangdUnit.h
+++ clangd/ClangdUnit.h
@@ -13,6 +13,9 @@
 #include "Path.h"
 #include "Protocol.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/PrecompiledPreamble.h"
+#include "clang/Serialization/ASTBitCodes.h"
+#include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include 
 
@@ -70,11 +73,82 @@
   void dumpAST(llvm::raw_ostream &OS) const;
 
 private:
+  /// Stores and provides access to parsed AST.
+  class ParsedAST {
+  public:
+/// Attempts to run Clang and store parsed AST. If \p Preamble is non-null
+/// it is reused during parsing.
+static llvm::Optional
+Build(std::unique_ptr CI,
+  const PrecompiledPreamble *Preamble,
+  ArrayRef PreambleDeclIDs,
+  std::unique_ptr Buffer,
+  std::shared_ptr PCHs,
+  IntrusiveRefCntPtr VFS);
+
+ParsedAST(ParsedAST &&Other);
+ParsedAST &operator=(ParsedAST &&Other);
+
+~ParsedAST();
+
+ASTContext &getASTContext();
+const ASTContext &getASTContext() const;
+
+Preprocessor &getPreprocessor();
+const Preprocessor &getPreprocessor() const;
+
+/// This function returns all top-level decls, including those that come
+/// from Preamble. Decls, coming from Preamble, have to be deserialized, so
+/// this call might be expensive.
+ArrayRef getTopLevelDecls();
+
+const std::vector &getDiagnostics() const;
+
+  private:
+ParsedAST(std::unique_ptr Clang,
+  std::unique_ptr Action,
+  std::vector TopLevelDecls,
+  std::vector PendingTopLevelDecls,
+  std::vector Diags);
+
+  private:
+void ensurePreambleDeclsDeserialized();
+
+// We store an "incomplete" FrontendAction (i.e. no EndSourceFile was called
+// on it) and CompilerInstance used to run it. That way we don't have to do
+// complex memory management of all Clang structures on our own. (They are
+// stored in CompilerInstance and cleaned up by
+// FrontendAction.EndSourceFile).
+std::unique_ptr Clang;
+std::unique_ptr Action;
+
+// Data, stored after parsing.
+std::vector Diags;
+std::vector TopLevelDecls;
+std::vector PendingTopLevelDecls;
+  };
+
+  // Store Preamble and all associated data
+  struct PreambleData {
+PreambleData(PrecompiledPreamble Preamble,
+ std::vector TopLevelDeclIDs,
+ std::vector Diags);
+
+PrecompiledPreamble Preamble;
+std::vector TopLevelDeclIDs;
+std::vector Diags;
+  };
+
+  SourceLocation getBeginningOfIdentifier(const Position &Pos,
+  const FileEntry *FE) const;
+
   Path FileName;
-  std::unique_ptr Unit;
-  std::shared_ptr PCHs;
+  tooling::CompileCommand Command;
 
-  SourceLocation getBeginningOfIdentifier(const Position& Pos, const FileEntry* FE) const;
+  llvm::Optional Preamble;
+  llvm::Optional Unit;
+
+  std::shared_ptr PCHs;
 };
 
 } // namespace clangd
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -9,23 +9,219 @@
 
 #include "ClangdUnit.h"
 
-#include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/Utils.h"
-#include "clang/Index/IndexingAction.h"
 #include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexingAction.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Serialization/ASTWriter.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Format.h"
 
 #include 
 
 using namespace clang::clangd;
 using namespace clang;
 
+namespace {
+
+class DeclTrackingASTConsumer : public ASTConsumer {
+public:
+  DeclTrackingASTConsumer(std::vector &TopLevelDecls)
+  : TopLevelDecls(TopLevelDecls) {}
+
+  bool HandleTopLevelDecl(DeclGroupRef DG) override {
+for (const Decl *D : DG) {
+  // ObjCMethodDecl are not actually top-level decls.
+  if (isa(D))
+continue;
+
+  TopLevelDecls.push_back(D);
+}
+return true;
+  }
+
+private:
+  std::vector &TopLevelDecls;
+};
+
+class ClangdFrontendAction : public SyntaxOnlyAction {
+public:
+  std::vector takeTopLevelDecls() {
+return std::move(TopLevelDecls);
+  }
+
+protected:
+  std::unique_ptr CreateASTConsume

[PATCH] D35673: [analyzer] A better CFG-based suppress-on-sink.

2017-07-20 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.

Because https://reviews.llvm.org/D28023 wasn't enough, as i've just seen an 
assertion-like macro with as many as 12 CFG blocks (including 
`do..while(false)` loops), i mocked up a quick CFG depth-first search to easily 
detect blocks dominated by noreturn blocks.


https://reviews.llvm.org/D35673

Files:
  lib/StaticAnalyzer/Core/BugReporter.cpp
  test/Analysis/max-nodes-suppress-on-sink.c

Index: test/Analysis/max-nodes-suppress-on-sink.c
===
--- test/Analysis/max-nodes-suppress-on-sink.c
+++ test/Analysis/max-nodes-suppress-on-sink.c
@@ -15,6 +15,8 @@
 
 void clang_analyzer_warnIfReached(void);
 
+int coin();
+
 void test_single_cfg_block_sink() {
   void *p = malloc(1); // no-warning (wherever the leak warning may occur here)
 
@@ -29,3 +31,53 @@
   // the leak report.
   exit(0);
 }
+
+// A similar test with more complicated control flow before the no-return thing,
+// so that the no-return thing wasn't in the same CFG block.
+void test_more_complex_control_flow_before_sink() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  if (coin())
+exit(0);
+  else
+exit(1);
+}
+
+// A loop before the no-return function, to make sure that
+// the dominated-by-sink analysis doesn't hang.
+void test_loop_before_sink(int n) {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  for (int i = 0; i < n; ++i) {
+  }
+  exit(1);
+}
+
+// We're not sure if this is no-return.
+void test_loop_with_sink(int n) {
+  void *p = malloc(1); // expected-warning@+2{{Potential leak of memory}}
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  for (int i = 0; i < n; ++i)
+if (i == 0)
+  exit(1);
+}
+
+// Handle unreachable blocks correctly.
+void test_unreachable_successor_blocks() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  if (1) // no-crash
+exit(1);
+}
Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3304,6 +3304,48 @@
   return nullptr;
 }
 
+static bool isDominatedByNoReturnBlocks(const ExplodedNode *N) {
+  const CFG &Cfg = N->getCFG();
+
+  const CFGBlock *StartBlk = findBlockForNode(N);
+  if (!StartBlk)
+return false;
+
+  llvm::SmallVector DFSWorkList;
+  llvm::SmallPtrSet Visited;
+
+  DFSWorkList.push_back(StartBlk);
+  while (!DFSWorkList.empty()) {
+const CFGBlock *Blk = DFSWorkList.back();
+DFSWorkList.pop_back();
+
+if (Blk->hasNoReturnElement()) {
+  // Nice, this block is noreturn. What about other blocks?
+  continue;
+}
+
+if (Blk == &Cfg.getExit()) {
+  // We're leaving the current CFG. We're no longer sure what happens next.
+  return false;
+}
+
+if (Visited.count(Blk)) {
+  // We've encountered a loop. We won't see anything new here anymore.
+  continue;
+}
+Visited.insert(Blk);
+
+for (const auto &Succ : Blk->succs()) {
+  // See what's going on in reachable child blocks.
+  if (const CFGBlock *SuccBlk = Succ.getReachableBlock())
+DFSWorkList.push_back(SuccBlk);
+}
+  }
+
+  // Nothing reached the exit. It can only mean one thing: there's no return.
+  return true;
+}
+
 static BugReport *
 FindReportInEquivalenceClass(BugReportEquivClass& EQ,
  SmallVectorImpl &bugReports) {
@@ -3360,9 +3402,8 @@
 // We may be post-dominated in subsequent blocks, or even
 // inter-procedurally. However, it is not clear if more complicated
 // cases are generally worth suppressing.
-if (const CFGBlock *B = findBlockForNode(errorNode))
-  if (B->hasNoReturnElement())
-continue;
+if (isDominatedByNoReturnBlocks(errorNode))
+  continue;
 
 // At this point we know that 'N' is not a sink and it has at least one
 // successor.  Use a DFS worklist to find a non-sink end-of-path node.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34654: Allow passing a regex for headers to exclude from clang-tidy

2017-07-20 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

> In our project we want to do something like include src/.*.h but exclude 
> src/some-thirdparty/.*.h.

There are at least two other possibilities to handle this use case.

The first one is to extend the way clang-tidy handles per-directory configs. 
Currently, for each translation unit clang-tidy takes the configuration for the 
main file of the translation unit and uses the Checks option found in this 
configuration to filter diagnostics coming from the main file as well as from 
the headers included by the translation unit. In a better world, it would take 
the configuration for the header where the diagnostic originates and thus allow 
a more source-centric way of controlling the set of diagnostics it displays. 
For example, consider this setup:

  a/.clang-tidy: Checks=-*,check1,check2
  a/a.cpp: #include a/a.h, #include b/b.h, #include third-party/c.h
  a/a.h
  b/.clang-tidy: Checks=-*,check2,check3
  b/b.h
  third-party/.clang-tidy: Checks=-*
  third-party/c.h

Let's assume that each of a/a.h, b/b.h, third-party/c.h and a/a.cpp contain 
code that triggers check1, check2 and check3. Currently, when run on a.cpp 
without `-header-filter`, clang-tidy would only output check1 and check2 from 
a.cpp. `-header-filter=.*` will result in check1 and check2 diagnostics from 
all the files.

If we change clang-tidy to apply the most relevant local configuration to the 
generated diagnostics (and get rid of `-header-filter` altogether, or set it to 
`.*` by default), in the case above it would output check1 and check2 from 
a/a.cpp and a/a.h, check2 from b/b.h (since we don't even run check3 on the 
code, and check1 gets filtered out), and no diagnostics from third-party/c.h, 
since we filter out check1 and check2 according to the local configuration. 
This seems like a more logical and useful behavior, however, when implementing 
this we'll have to make sure configuration retrieval doesn't become a 
bottleneck (FileOptionsProvider already implements some sort of caching, but 
we'd have to carefully benchmark it on large translation units with tons of 
diagnostics).

The second way to handle this use case is possible on a different level: one 
can run clang-tidy over the whole project with `-header-filter=.*` and then 
filter the results and use a specialized tool to display them, e.g. 
https://github.com/Ericsson/codechecker. I'm not sure though whether this suits 
your needs or is an overkill.


Repository:
  rL LLVM

https://reviews.llvm.org/D34654



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


[PATCH] D35674: [analyzer] Treat C++ throw as sink during CFG-based suppress-on-sink.

2017-07-20 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.

Because throws produce sinks during symbolic execution, we need to treat them 
as noreturn during our suppress-on-sink analysis as well. This would get a lot 
less conservative when CFG actually supports exceptions.


https://reviews.llvm.org/D35674

Files:
  lib/StaticAnalyzer/Core/BugReporter.cpp
  test/Analysis/max-nodes-suppress-on-sink.cpp


Index: test/Analysis/max-nodes-suppress-on-sink.cpp
===
--- /dev/null
+++ test/Analysis/max-nodes-suppress-on-sink.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_analyze_cc1 -x c++ -fcxx-exceptions 
-analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config 
max-nodes=12 -verify %s
+
+// Here we test how "suppress on sink" feature of certain bugtypes interacts
+// with reaching analysis limits. See comments in max-nodes-suppress-on-sink.c
+// for more discussion.
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+void clang_analyzer_warnIfReached(void);
+
+// Because we don't have a better approach, we currently treat throw as
+// noreturn.
+void test_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  throw 0;
+}
+
+// FIXME: Handled throws shouldn't be suppressing us!
+void test_handled_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  try {
+throw 0;
+  } catch (int i) {
+  }
+}
+
Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3324,6 +3324,19 @@
   continue;
 }
 
+if (std::any_of(Blk->begin(), Blk->end(), [](const CFGElement &Elm) {
+  if (Optional StmtElm = Elm.getAs())
+if (isa(StmtElm->getStmt()))
+  return true;
+  return false;
+})) {
+  // Throw-expressions are currently generating sinks during symbolic
+  // execution: they're not supported yet, and also often used for
+  // actually terminating the program. So we should treat them as sinks
+  // in this analysis as well, at least for now.
+  continue;
+}
+
 if (Blk == &Cfg.getExit()) {
   // We're leaving the current CFG. We're no longer sure what happens next.
   return false;


Index: test/Analysis/max-nodes-suppress-on-sink.cpp
===
--- /dev/null
+++ test/Analysis/max-nodes-suppress-on-sink.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_analyze_cc1 -x c++ -fcxx-exceptions -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config max-nodes=12 -verify %s
+
+// Here we test how "suppress on sink" feature of certain bugtypes interacts
+// with reaching analysis limits. See comments in max-nodes-suppress-on-sink.c
+// for more discussion.
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+void clang_analyzer_warnIfReached(void);
+
+// Because we don't have a better approach, we currently treat throw as
+// noreturn.
+void test_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  throw 0;
+}
+
+// FIXME: Handled throws shouldn't be suppressing us!
+void test_handled_throw_treated_as_noreturn() {
+  void *p = malloc(1); // no-warning
+
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  clang_analyzer_warnIfReached(); // no-warning
+
+  try {
+throw 0;
+  } catch (int i) {
+  }
+}
+
Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3324,6 +3324,19 @@
   continue;
 }
 
+if (std::any_of(Blk->begin(), Blk->end(), [](const CFGElement &Elm) {
+  if (Optional StmtElm = Elm.getAs())
+if (isa(StmtElm->getStmt()))
+  return true;
+  return false;
+})) {
+  // Throw-expressions are currently generating sinks during symbolic
+  // execution: they're not supported yet, and also often used for
+  // actually terminating the program. So we should treat them as sinks
+  // in this analysis as well, at least for now.
+  continue;
+}
+
 if (Blk == &Cfg.getExit()) {
   // We're leaving the current CFG. We're no longer sure what happens next.
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34748: [clang-diff] improve mapping accuracy, HTML side-by-side diff.

2017-07-20 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 107479.
johannes retitled this revision from "[clang-diff] Fix multiple mappings." to 
"[clang-diff] improve mapping accuracy, HTML side-by-side diff.".
Herald added a subscriber: mgorny.

https://reviews.llvm.org/D34748

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  include/clang/Tooling/ASTDiff/ASTDiffInternal.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-basic.cpp
  tools/clang-diff/CMakeLists.txt
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "clang/Tooling/ASTDiff/ASTDiff.h"
+#include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
@@ -24,15 +25,20 @@
 static cl::OptionCategory ClangDiffCategory("clang-diff options");
 
 static cl::opt
-DumpAST("ast-dump",
+ASTDump("ast-dump",
 cl::desc("Print the internal representation of the AST as JSON."),
 cl::init(false), cl::cat(ClangDiffCategory));
 
-static cl::opt NoCompilationDatabase(
-"no-compilation-database",
-cl::desc(
-"Do not attempt to load build settings from a compilation database"),
-cl::init(false), cl::cat(ClangDiffCategory));
+static cl::opt
+PrintMatches("m", cl::desc("Print the matched nodes (verbose)."),
+ cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt JsonDiff("json", cl::desc("Print the diff as JSON."),
+  cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt HtmlDiff("html",
+  cl::desc("Output a side-by-side diff in HTML."),
+  cl::init(false), cl::cat(ClangDiffCategory));
 
 static cl::opt SourcePath(cl::Positional, cl::desc(""),
cl::Required,
@@ -43,12 +49,69 @@
 cl::Optional,
 cl::cat(ClangDiffCategory));
 
+static cl::opt NoCompilationDatabase(
+"no-compilation-database",
+cl::desc(
+"Do not attempt to load build settings from a compilation database"),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt BuildPath("p", cl::desc("Build path"), cl::Optional,
+  cl::cat(ClangDiffCategory));
+
+static cl::list ArgsAfter(
+"extra-arg",
+cl::desc("Additional argument to append to the compiler command line"),
+cl::cat(ClangDiffCategory));
+
+static cl::list ArgsBefore(
+"extra-arg-before",
+cl::desc("Additional argument to prepend to the compiler command line"),
+cl::cat(ClangDiffCategory));
+
+namespace {
+class ArgumentsAdjustingCompilations : public CompilationDatabase {
+public:
+  ArgumentsAdjustingCompilations(
+  std::unique_ptr Compilations)
+  : Compilations(std::move(Compilations)) {}
+
+  void appendArgumentsAdjuster(ArgumentsAdjuster Adjuster) {
+Adjusters.push_back(std::move(Adjuster));
+  }
+
+  std::vector
+  getCompileCommands(StringRef FilePath) const override {
+return adjustCommands(Compilations->getCompileCommands(FilePath));
+  }
+
+  std::vector getAllFiles() const override {
+return Compilations->getAllFiles();
+  }
+
+  std::vector getAllCompileCommands() const override {
+return adjustCommands(Compilations->getAllCompileCommands());
+  }
+
+private:
+  std::unique_ptr Compilations;
+  std::vector Adjusters;
+
+  std::vector
+  adjustCommands(std::vector Commands) const {
+for (CompileCommand &Command : Commands)
+  for (const auto &Adjuster : Adjusters)
+Command.CommandLine = Adjuster(Command.CommandLine, Command.Filename);
+return Commands;
+  }
+};
+} // namespace
+
 static std::unique_ptr getAST(const StringRef Filename) {
   std::string ErrorMessage;
   std::unique_ptr Compilations;
   if (!NoCompilationDatabase)
-Compilations =
-CompilationDatabase::autoDetectFromSource(Filename, ErrorMessage);
+Compilations = CompilationDatabase::autoDetectFromSource(
+BuildPath.empty() ? Filename : BuildPath, ErrorMessage);
   if (!Compilations) {
 if (!NoCompilationDatabase)
   llvm::errs()
@@ -58,6 +121,14 @@
 Compilations = llvm::make_unique(
 ".", std::vector());
   }
+  auto AdjustingCompilations =
+  llvm::make_unique(
+  std::move(Compilations));
+  AdjustingCompilations->appendArgumentsAdjuster(
+  getInsertArgumentAdjuster(ArgsBefore, ArgumentInsertPosition::BEGIN));
+  AdjustingCompilations->appendArgumentsAdjuster(
+  getInsertArgumentAdjuster(ArgsAfter, ArgumentInsertPosition::END));
+  Compilations = std::move(AdjustingCompilations);
   std::array Files = {{Filename}};
   

[PATCH] D35051: [clang-tidy] Add bugprone-undefined-memory-manipulation check.

2017-07-20 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

FYI, bugprone-undefined-memory-manipulation crashes on some of our code. I 
guess, this happens with dependent types, but I don't have an isolated repro 
yet.


Repository:
  rL LLVM

https://reviews.llvm.org/D35051



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


[PATCH] D35051: [clang-tidy] Add bugprone-undefined-memory-manipulation check.

2017-07-20 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

The top of stack trace is:

  clang::CXXRecordDecl::isTriviallyCopyable()
  (unknown)
  clang::tidy::bugprone::(anonymous 
namespace)::internal::matcher_isNotTriviallyCopyableMatcher::matches()


Repository:
  rL LLVM

https://reviews.llvm.org/D35051



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


r308604 - [vfs] Assert that the status is known in equivalent().

2017-07-20 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Thu Jul 20 04:57:02 2017
New Revision: 308604

URL: http://llvm.org/viewvc/llvm-project?rev=308604&view=rev
Log:
[vfs] Assert that the status is known in equivalent().

Otherwise we'd silently compare uninitialized data.

Modified:
cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=308604&r1=308603&r2=308604&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Thu Jul 20 04:57:02 2017
@@ -59,6 +59,7 @@ Status Status::copyWithNewName(const fil
 }
 
 bool Status::equivalent(const Status &Other) const {
+  assert(isStatusKnown() && Other.isStatusKnown());
   return getUniqueID() == Other.getUniqueID();
 }
 bool Status::isDirectory() const {


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


[clang-tools-extra] r308605 - [clang-tidy] Unify the way IncludeStyle and HeaderFileExtesions options are used

2017-07-20 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Jul 20 05:02:03 2017
New Revision: 308605

URL: http://llvm.org/viewvc/llvm-project?rev=308605&view=rev
Log:
[clang-tidy] Unify the way IncludeStyle and HeaderFileExtesions options are used

Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp
clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.h
clang-tools-extra/trunk/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MoveConstructorInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp

clang-tools-extra/trunk/clang-tidy/performance/TypePromotionInMathFnCheck.cpp

clang-tools-extra/trunk/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/HeaderFileExtensionsUtils.h
clang-tools-extra/trunk/clang-tidy/utils/HeaderGuard.h

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp?rev=308605&r1=308604&r2=308605&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
 Thu Jul 20 05:02:03 2017
@@ -23,7 +23,7 @@ ProBoundsConstantArrayIndexCheck::ProBou
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context), GslHeader(Options.get("GslHeader", "")),
   IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
-  Options.get("IncludeStyle", "llvm"))) {}
+  Options.getLocalOrGlobal("IncludeStyle", "llvm"))) {}
 
 void ProBoundsConstantArrayIndexCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {

Modified: 
clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp?rev=308605&r1=308604&r2=308605&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/google/GlobalNamesInHeadersCheck.cpp Thu 
Jul 20 05:02:03 2017
@@ -23,8 +23,8 @@ namespace readability {
 GlobalNamesInHeadersCheck::GlobalNamesInHeadersCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  RawStringHeaderFileExtensions(
-  Options.getLocalOrGlobal("HeaderFileExtensions", "h")) {
+  RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
+  "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
   if (!utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
 HeaderFileExtensions, ',')) {
 llvm::errs() << "Invalid header file extension: "

Modified: 
clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp?rev=308605&r1=308604&r2=308605&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp 
Thu Jul 20 05:02:03 2017
@@ -22,8 +22,8 @@ namespace build {
 UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  RawStringHeaderFileExtensions(
-  Options.getLocalOrGlobal("HeaderFileExtensions", "h,hh,hpp,hxx")) {
+  RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
+  "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
   if (!utils::parseHeaderFileExtensions(RawStringHeaderFileExtensions,
 HeaderFileExtensions, ',')) {
 llvm::errs() << "Invalid header file extension: "

Modified: clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/HeaderGuardCheck.cpp?rev=308605&r1=308604&r2=308605&view=diff
===

r308592 - Revert "[StaticAnalyzer] Completely unrolling specific loops with known bound option"

2017-07-20 Thread Peter Szecsi via cfe-commits
Author: szepet
Date: Thu Jul 20 00:35:11 2017
New Revision: 308592

URL: http://llvm.org/viewvc/llvm-project?rev=308592&view=rev
Log:
Revert "[StaticAnalyzer] Completely unrolling specific loops with known bound 
option"

Revert r308561 and r308558.

Clang-ppc64be-linux seems to crash while running the test cases.


Removed:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/LoopUnrolling.h
cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
cfe/trunk/test/Analysis/loop-unrolling.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CMakeLists.txt
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/analyzer-config.c
cfe/trunk/test/Analysis/analyzer-config.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=308592&r1=308591&r2=308592&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Thu Jul 20 
00:35:11 2017
@@ -275,9 +275,6 @@ private:
   /// \sa shouldWidenLoops
   Optional WidenLoops;
 
-  /// \sa shouldUnrollLoops
-  Optional UnrollLoops;
-
   /// \sa shouldDisplayNotesAsEvents
   Optional DisplayNotesAsEvents;
 
@@ -563,11 +560,7 @@ public:
   /// This is controlled by the 'widen-loops' config option.
   bool shouldWidenLoops();
 
-  /// Returns true if the analysis should try to unroll loops with known 
bounds.
-  /// This is controlled by the 'unroll-loops' config option.
-  bool shouldUnrollLoops();
-
-/// Returns true if the bug reporter should transparently treat extra note
+  /// Returns true if the bug reporter should transparently treat extra note
   /// diagnostic pieces as event diagnostic pieces. Useful when the diagnostic
   /// consumer doesn't support the extra note pieces.
   ///

Removed: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/LoopUnrolling.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/LoopUnrolling.h?rev=308591&view=auto
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/LoopUnrolling.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/LoopUnrolling.h 
(removed)
@@ -1,33 +0,0 @@
-//===--- LoopUnrolling.h - Unroll loops -*- C++ 
-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-///
-/// This header contains the declarations of functions which are used to decide
-/// which loops should be completely unrolled and mark their corresponding
-/// CFGBlocks.
-///
-//===--===//
-
-#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_LOOPUNROLLING_H
-#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_LOOPUNROLLING_H
-
-#include "clang/Analysis/CFG.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
-
-namespace clang {
-namespace ento {
-ProgramStateRef markLoopAsUnrolled(const Stmt *Term, ProgramStateRef State,
-   CFGStmtMap *StmtToBlockMap);
-bool isUnrolledLoopBlock(const CFGBlock *Block, ExplodedNode *Prev);
-bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx);
-
-} // end namespace ento
-} // end namespace clang
-
-#endif

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp?rev=308592&r1=308591&r2=308592&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp Thu Jul 20 
00:35:11 2017
@@ -272,7 +272,6 @@ void ExprInspectionChecker::checkEndAnal
 
 reportBug(llvm::to_string(NumTimesReached), BR, N);
   }
-  ReachedStats.clear();
 }
 
 void ExprInspectionChecker::analyzerCrash(const CallExpr *CE,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=308592&r1=308591&r2=308592&view=diff
==
--- cfe/trunk/lib/StaticAnaly

[PATCH] D24892: [clang-tidy] Add option "LiteralInitializers" to cppcoreguidelines-pro-type-member-init

2017-07-20 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

In https://reviews.llvm.org/D24892#733016, @alexfh wrote:

> In https://reviews.llvm.org/D24892#732243, @malcolm.parsons wrote:
>
> > In https://reviews.llvm.org/D24892#732217, @alexfh wrote:
> >
> > > In https://reviews.llvm.org/D24892#723536, @malcolm.parsons wrote:
> > >
> > > > Is there any way for multiple checks to share an option?
> > >
> > >
> > > There's OptionsView::getLocalOrGlobal. See how StrictMode option is read 
> > > in ArgumentCommentCheck, for example.
> >
> >
> > ArgumentCommentCheck uses getLocalOrGlobal, but 
> > InefficientStringConcatenationCheck and SuspiciousEnumUsageCheck don't.
> >  6 checks have an IncludeStyle option that isn't shared.
> >  4 checks share a HeaderFileExtensions option, but with different defaults.
>
>
> The right thing would be to fix these. I might get around to this, if nobody 
> does this before me.


Better late than never: r308605 ;)

Any specific plans re: this patch?


https://reviews.llvm.org/D24892



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


[PATCH] D35678: Omit sumbodule semantics for TS modules

2017-07-20 Thread Boris Kolpackov via Phabricator via cfe-commits
boris created this revision.

If a TS module name has more than one component (e.g., foo.bar) then we 
erroneously activate the submodule semantics when encountering a module 
declaration in the module implementation unit (e.g., module foo.bar;).


https://reviews.llvm.org/D35678

Files:
  lib/Frontend/CompilerInstance.cpp


Index: lib/Frontend/CompilerInstance.cpp
===
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -1595,7 +1595,22 @@
  Module::NameVisibilityKind Visibility,
  bool IsInclusionDirective) {
   // Determine what file we're searching from.
-  StringRef ModuleName = Path[0].first->getName();
+  // FIXME: Should we be deciding whether this is a submodule (here and
+  // below) based on -fmodules-ts or should we pass a flag and make the
+  // caller decide?
+  std::string ModuleName;
+  if (getLangOpts().ModulesTS) {
+// FIXME: Same code as Sema::ActOnModuleDecl() so there is probably a
+// better place/way to do this.
+for (auto &Piece : Path) {
+  if (!ModuleName.empty())
+ModuleName += ".";
+  ModuleName += Piece.first->getName();
+}
+  }
+  else
+ModuleName = Path[0].first->getName();
+
   SourceLocation ModuleNameLoc = Path[0].second;
 
   // If we've already handled this import, just return the cached result.
@@ -1810,7 +1825,7 @@
 
   // Verify that the rest of the module path actually corresponds to
   // a submodule.
-  if (Path.size() > 1) {
+  if (!getLangOpts().ModulesTS && Path.size() > 1) {
 for (unsigned I = 1, N = Path.size(); I != N; ++I) {
   StringRef Name = Path[I].first->getName();
   clang::Module *Sub = Module->findSubmodule(Name);


Index: lib/Frontend/CompilerInstance.cpp
===
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -1595,7 +1595,22 @@
  Module::NameVisibilityKind Visibility,
  bool IsInclusionDirective) {
   // Determine what file we're searching from.
-  StringRef ModuleName = Path[0].first->getName();
+  // FIXME: Should we be deciding whether this is a submodule (here and
+  // below) based on -fmodules-ts or should we pass a flag and make the
+  // caller decide?
+  std::string ModuleName;
+  if (getLangOpts().ModulesTS) {
+// FIXME: Same code as Sema::ActOnModuleDecl() so there is probably a
+// better place/way to do this.
+for (auto &Piece : Path) {
+  if (!ModuleName.empty())
+ModuleName += ".";
+  ModuleName += Piece.first->getName();
+}
+  }
+  else
+ModuleName = Path[0].first->getName();
+
   SourceLocation ModuleNameLoc = Path[0].second;
 
   // If we've already handled this import, just return the cached result.
@@ -1810,7 +1825,7 @@
 
   // Verify that the rest of the module path actually corresponds to
   // a submodule.
-  if (Path.size() > 1) {
+  if (!getLangOpts().ModulesTS && Path.size() > 1) {
 for (unsigned I = 1, N = Path.size(); I != N; ++I) {
   StringRef Name = Path[I].first->getName();
   clang::Module *Sub = Module->findSubmodule(Name);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31326: Add option to export fixes to run-clang-tidy.py

2017-07-20 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.



Comment at: clang-tidy/tool/run-clang-tidy.py:96-98
+  # Clang-tidy < 4.0.0 uses "Replacements" as a key to the list
+  # of replacements. Clang-tidy >= 4.0.0 uses "Diagnostics" as the
+  # top-level key.

I don't think there's much sense in supporting the old format, since the script 
is distributed together with the binary, so it's unlikely that it will 
encounter clang-tidy of an earlier version.


https://reviews.llvm.org/D31326



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


[PATCH] D35578: Add -fswitch-tables and -fno-switch-tables flags

2017-07-20 Thread Chad Rosier via Phabricator via cfe-commits
mcrosier added reviewers: echristo, ddunbar.
mcrosier added subscribers: echristo, ddunbar.
mcrosier added a comment.

Adding @echristo and @ddunbar who have been the primary owners of the driver 
for the past decade or so.


https://reviews.llvm.org/D35578



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


[PATCH] D35577: Add -flookup-tables and -fno-lookup-tables flags

2017-07-20 Thread Chad Rosier via Phabricator via cfe-commits
mcrosier added subscribers: echristo, ddunbar, mcrosier.
mcrosier added reviewers: echristo, ddunbar.
mcrosier added a comment.

Adding @echristo and @ddunbar who have been the primary owners of the driver 
for the past decade or so.


https://reviews.llvm.org/D35577



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


[PATCH] D35682: Fixed failing assert in code completion.

2017-07-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

The code was accessing uninstantiated default argument.
This resulted in failing assertion at ParamVarDecl::getDefaultArg().


https://reviews.llvm.org/D35682

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/CodeCompletion/uninstantiated_params.cpp


Index: test/CodeCompletion/uninstantiated_params.cpp
===
--- /dev/null
+++ test/CodeCompletion/uninstantiated_params.cpp
@@ -0,0 +1,13 @@
+template 
+struct unique_ptr {
+  typedef T* pointer;
+
+  void reset(pointer ptr = pointer());
+};
+
+void test() {
+  unique_ptr x;
+  x.
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:5 %s -o - | 
FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: [#void#]reset({#<#unique_ptr::pointer ptr = pointer()#>#})
+}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -2401,10 +2401,7 @@
 static std::string GetDefaultValueString(const ParmVarDecl *Param,
  const SourceManager &SM,
  const LangOptions &LangOpts) {
-  const Expr *defaultArg = Param->getDefaultArg();
-  if (!defaultArg)
-return "";
-  const SourceRange SrcRange = defaultArg->getSourceRange();
+  const SourceRange SrcRange = Param->getDefaultArgRange();
   CharSourceRange CharSrcRange = CharSourceRange::getTokenRange(SrcRange);
   bool Invalid = CharSrcRange.isInvalid();
   if (Invalid)


Index: test/CodeCompletion/uninstantiated_params.cpp
===
--- /dev/null
+++ test/CodeCompletion/uninstantiated_params.cpp
@@ -0,0 +1,13 @@
+template 
+struct unique_ptr {
+  typedef T* pointer;
+
+  void reset(pointer ptr = pointer());
+};
+
+void test() {
+  unique_ptr x;
+  x.
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:5 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: [#void#]reset({#<#unique_ptr::pointer ptr = pointer()#>#})
+}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -2401,10 +2401,7 @@
 static std::string GetDefaultValueString(const ParmVarDecl *Param,
  const SourceManager &SM,
  const LangOptions &LangOpts) {
-  const Expr *defaultArg = Param->getDefaultArg();
-  if (!defaultArg)
-return "";
-  const SourceRange SrcRange = defaultArg->getSourceRange();
+  const SourceRange SrcRange = Param->getDefaultArgRange();
   CharSourceRange CharSrcRange = CharSourceRange::getTokenRange(SrcRange);
   bool Invalid = CharSrcRange.isInvalid();
   if (Invalid)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35329: [clang-reorder-fields] Enable reordering for plain C structs

2017-07-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D35329



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


r308619 - Reland "[mips] Teach the driver to accept -m(no-)gpopt."

2017-07-20 Thread Simon Dardis via cfe-commits
Author: sdardis
Date: Thu Jul 20 07:04:12 2017
New Revision: 308619

URL: http://llvm.org/viewvc/llvm-project?rev=308619&view=rev
Log:
Reland "[mips] Teach the driver to accept -m(no-)gpopt."

This patch teaches the driver to pass -mgpopt by default to the backend when it
is supported, i.e. we are using -mno-abicalls.

Reviewers: atanasyan, slthakur

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

This version fixes a logic error that generated warnings incorrectly and
gets rid of spurious arguments to the backend when -mgpopt is not used.

Added:
cfe/trunk/test/Driver/mips-gpopt-warning.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/mips-features.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=308619&r1=308618&r2=308619&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Jul 20 07:04:12 
2017
@@ -279,6 +279,10 @@ def warn_target_unsupported_nanlegacy :
 def warn_target_unsupported_compact_branches : Warning<
   "ignoring '-mcompact-branches=' option because the '%0' architecture does 
not"
   " support it">, InGroup;
+def warn_drv_unsupported_gpopt : Warning<
+  "ignoring '-mgpopt' option as it cannot be used with %select{|the implicit"
+  " usage of}0-mabicalls">,
+  InGroup;
 
 def warn_drv_unable_to_find_directory_expected : Warning<
   "unable to find %0 directory, expected to be in '%1'">,

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=308619&r1=308618&r2=308619&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Jul 20 07:04:12 2017
@@ -61,6 +61,7 @@ def DoublePromotion : DiagGroup<"double-
 def EnumTooLarge : DiagGroup<"enum-too-large">;
 def UnsupportedNan : DiagGroup<"unsupported-nan">;
 def UnsupportedCB : DiagGroup<"unsupported-cb">;
+def UnsupportedGPOpt : DiagGroup<"unsupported-gpopt">;
 def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">;
 def NullConversion : DiagGroup<"null-conversion">;
 def ImplicitConversionFloatingPointToBool :

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=308619&r1=308618&r2=308619&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Jul 20 07:04:12 2017
@@ -2035,6 +2035,12 @@ def mfp64 : Flag<["-"], "mfp64">, Group<
   HelpText<"Use 64-bit floating point registers (MIPS only)">;
 def mfp32 : Flag<["-"], "mfp32">, Group,
   HelpText<"Use 32-bit floating point registers (MIPS only)">;
+def mgpopt : Flag<["-"], "mgpopt">, Group,
+  HelpText<"Use GP relative accesses for symbols known to be in a small"
+   " data section (MIPS)">;
+def mno_gpopt : Flag<["-"], "mno-gpopt">, Group,
+  HelpText<"Do not use GP relative accesses for symbols known to be in a small"
+   " data section (MIPS)">;
 def mnan_EQ : Joined<["-"], "mnan=">, Group;
 def mabicalls : Flag<["-"], "mabicalls">, Group,
   HelpText<"Enable SVR4-style position-independent code (Mips only)">;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=308619&r1=308618&r2=308619&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Jul 20 07:04:12 2017
@@ -1462,6 +1462,30 @@ void Clang::AddMIPSTargetArgs(const ArgL
 A->claim();
   }
 
+  Arg *GPOpt = Args.getLastArg(options::OPT_mgpopt, options::OPT_mno_gpopt);
+  Arg *ABICalls =
+  Args.getLastArg(options::OPT_mabicalls, options::OPT_mno_abicalls);
+
+  // -mabicalls is the default for many MIPS environments, even with -fno-pic.
+  // -mgpopt is the default for static, -fno-pic environments but these two
+  // options conflict. We want to be certain that -mno-abicalls -mgpopt is
+  // the only case where -mllvm -mgpopt is passed.
+  // NOTE: We need a warning here or in the backend to warn when -mgpopt is
+  //   passed explicitly when compiling something with -mabicalls
+  //   (implictly) in affect. Currently the warning is in the backend.
+  bool NoABICalls =
+  ABICalls && ABICalls->getOption().m

[PATCH] D35652: [clang] Fix handling of "%zd" format specifier in scanf

2017-07-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM with a small testing nit.




Comment at: test/Sema/format-strings-scanf.c:1
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -Wformat-nonliteral %s
 

alexshap wrote:
> c11 is necessary for _Generic below.
> I have not found a more reliable way to define ssize_t
> which doesn't require a large number of #ifdef ...
Ugh, that is pretty nasty, but I cannot think of a better way to define it in a 
generic manner.



Comment at: test/Sema/format-strings-scanf.c:198
+  scanf("%zn", &d3); // expected-warning-re{{format specifies type 'ssize_t *' 
(aka '{{.+}}') but the argument has type 'double *'}}
+}
+

Can you add a passing test for `%zn`?


Repository:
  rL LLVM

https://reviews.llvm.org/D35652



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


[clang-tools-extra] r308621 - [clang-tidy] s/1/true/, NFC

2017-07-20 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Jul 20 07:56:52 2017
New Revision: 308621

URL: http://llvm.org/viewvc/llvm-project?rev=308621&view=rev
Log:
[clang-tidy] s/1/true/, NFC

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=308621&r1=308620&r2=308621&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Thu Jul 20 07:56:52 2017
@@ -140,7 +140,7 @@ UseDefaultMemberInitCheck::UseDefaultMem
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   UseAssignment(Options.get("UseAssignment", 0) != 0),
-  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", 1) != 0) {}
+  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true) != 0) {}
 
 void UseDefaultMemberInitCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {


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


[PATCH] D35082: [OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-07-20 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:11846
   // an address space.
   if (T.getAddressSpace() != 0) {
 // OpenCL allows function arguments declared to be an array of a type

yaxunl wrote:
> Anastasia wrote:
> > yaxunl wrote:
> > > Anastasia wrote:
> > > > Could we use `LangAS::Default` here too?
> > > done
> > Sorry, I wasn't clear. I think we could have:
> > 
> >   if (T.getAddressSpace() != LangAS::Default && T.getAddressSpace() != 
> > LangAS::opencl_private)
> > 
> > and then original condition. It is a bit clearer I think.
> No. For OpenCL, the condition is on line 11847 and 11848. An array type in 
> other address spaces is allowed.
I think the initial condition was `T.getAddressSpace() != 0` i.e. if not 
private address space.

So now since we added private this should be `T.getAddressSpace() 
!=LangAS::opencl_private` but we can have the default case as well hence 
'T.getAddressSpace() !=LangAS::opencl_private || T.getAddressSpace() 
!=LangAS::Default'.

This entire case seems to be for OpenCL anyways. So you could also move out the 
OpenCL check if you prefer. I am just trying to see if we can make this easier 
to understand.



Comment at: lib/Sema/SemaType.cpp:6969
 
+  if (state.getSema().getLangOpts().OpenCL &&
+  !hasOpenCLAddressSpace && type.getAddressSpace() == 0 &&

yaxunl wrote:
> Anastasia wrote:
> > yaxunl wrote:
> > > Anastasia wrote:
> > > > Would it be nicer to not append any address space at all neither here 
> > > > nor down at the end of this function and keep it default instead until 
> > > > the Codegen? If it's doable I would very much prefer that. It seems 
> > > > like it would make the implementation potentially a bit cleaner to 
> > > > understand and easier to improve semantical analysis. See one example 
> > > > of improving original type printing in my comment to the test below.
> > > > 
> > > > Also there are at least these 3 related bugs open currently:
> > > > https://bugs.llvm.org//show_bug.cgi?id=33418
> > > > https://bugs.llvm.org//show_bug.cgi?id=33419
> > > > https://bugs.llvm.org//show_bug.cgi?id=33420
> > > > 
> > > > Does your change address any of those?
> > > On the contrary, I think using default address space for automatic 
> > > variable and function parameter will cause ambiguity and inconsistency in 
> > > AST, making it more difficult to understand and process, and making some 
> > > bug (e.g. https://bugs.llvm.org//show_bug.cgi?id=33419) unfixable. For 
> > > example, `private int f(void)` and `int f(void)` will be identical in 
> > > AST, therefore we cannot diagnose `private int f(void)`.
> > > 
> > > With current representation I am able to fix the 3 bugs. I will update 
> > > the diff.
> > I don't see why?
> > 
> > `private int f(void)` -> will have an address space attribute in AST as it 
> > is provided explicitly.
> > 
> > `int f(void) ` -> will have no address space attribute because it's not 
> > provided explicitly and not attached implicitly either.
> > 
> > All I was asking is  not to deduce the address space here if it's not 
> > specified explicitly until later step when we need to put it in the IR.
> Clang already deduce global and generic address spaces and use them in the 
> diagnostic messages. I don't see why we can use deduced global and generic 
> address space in diagnostics whereas cannot use deduced private address space 
> in diagnostics. Why users can accept deduced global and generic address 
> spaces but cannot accept deduced private address space?
> 
> Automatic variables and function parameters have private address space. This 
> is the reality and as true as a global variable has global or constant 
> address spaces. Not using private address space in diagnostics gives user 
> illusion that automatic variables and function parameters do not have address 
> space, which is not true.
> 
> Besides, allowing default address space to represent private address space in 
> AST causes ambiguity in AST. Instead of just check if a type has private 
> address space, now we need to check if a type has private or default address 
> spaces. Also if an expression has default address space, it is not clear if 
> it is an l-value or r-value. This will complicate semantic checking 
> unnecessarily. Also I am not sure if it is acceptable to modify AST between 
> Sema and CodeGen since it seems to change the paradigm of how clang does 
> Sema/CodeGen now.
> Clang already deduce global and generic address spaces and use them in the 
> diagnostic messages. I don't see why we can use deduced global and generic 
> address space in diagnostics whereas cannot use deduced private address space 
> in diagnostics. Why users can accept deduced global and generic address 
> spaces but cannot accept deduced private address space?

Yes, we did this initially as a workaround because there was no way to 
distinguish the private and default address spa

[PATCH] D35683: [clang-format] Put '/**' and '*/' on own lines in multiline jsdocs

2017-07-20 Thread Martin Probst via Phabricator via cfe-commits
mprobst added inline comments.



Comment at: lib/Format/BreakableToken.cpp:435
+  // Detect a multiline jsdoc comment and set DelimitersOnNewline in that case.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+if ((Lines[0] == "*" || Lines[0].startswith("* ")) && Lines.size() > 1) {

I think I'd also enable this for at least Java. But tentatively I wonder - 
wouldn't just about every language do it like this for `/**` comments?



Comment at: lib/Format/BreakableToken.cpp:436
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+if ((Lines[0] == "*" || Lines[0].startswith("* ")) && Lines.size() > 1) {
+  // This is a multiline jsdoc comment.

Wouldn't we also want to do this for `/**blah`, i.e. no whitespace after `*`?



Comment at: lib/Format/BreakableToken.cpp:436
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+if ((Lines[0] == "*" || Lines[0].startswith("* ")) && Lines.size() > 1) {
+  // This is a multiline jsdoc comment.

mprobst wrote:
> Wouldn't we also want to do this for `/**blah`, i.e. no whitespace after `*`?
Would we also want to do this for simple block comments, e.g. `/*blah*/`?  
That's a bit more tricky as they can be used inline, not sure about the corner 
cases there.



Comment at: lib/Format/BreakableToken.cpp:606
+if (DelimitersOnNewline) {
+size_t BreakLength = Lines[0].substr(1).find_first_not_of(Blanks);
+if (BreakLength != StringRef::npos) {

isn't this BreakPosition rather than length?



Comment at: unittests/Format/FormatTestJS.cpp:136
+   " * line long long long */",
+   getGoogleJSStyleWithColumns(20)));
+}

do you need a test where the entire comment block is indented?


https://reviews.llvm.org/D35683



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


[PATCH] D35479: [CodeGen][mips] Support `long_call/far/near` attributes

2017-07-20 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, that looks great!


Repository:
  rL LLVM

https://reviews.llvm.org/D35479



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


[PATCH] D33852: Enable __declspec(selectany) on linux

2017-07-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: include/clang/Basic/Attr.td:2421
 
-def SelectAny : InheritableAttr, TargetSpecificAttr {
+def SelectAny : InheritableAttr, TargetSpecificAttr {
   let Spellings = [Declspec<"selectany">, GCC<"selectany">];

Prazek wrote:
> davide wrote:
> > rnk wrote:
> > > Prazek wrote:
> > > > rnk wrote:
> > > > > davide wrote:
> > > > > > Prazek wrote:
> > > > > > > majnemer wrote:
> > > > > > > > selectany should work on targets other than "x86", "x86_64", 
> > > > > > > > "arm", "thumb", etc. I think it is only necessary to require 
> > > > > > > > that it be a COFF or ELF target.
> > > > > > > Should we allow other OSes than Win32 and Linux?
> > > > > > I guess everything ELF should be allowed.
> > > > > Why not use weak_odr / linkonce_odr on MachO? Microsoft builds Office 
> > > > > for Mac and I suspect they use `__declspec(selectany)`.
> > > > I think this is what would happen right now. The question is - should 
> > > > we warn about using declspec on macho? Beause not using comdat looks 
> > > > like "not supporting" it, but I am not sure about it.
> > > I'm pretty sure weak_odr / linkonce_odr with ld64 on macho are the same 
> > > as having a comdat. LLVM didn't always have comdats, but it's supported 
> > > inline functions for a very long time. We should support selectany there.
> > I agree with @rnk here.
> So does it actually mean that we don't have any requirements for 
> declscpec(any)? It can run on every OS and target
I guess so. I think `__declspec` spellings are controlled by 
-fdeclspec-extensions, which is off by default except on Windows & PS4. If we 
remove this constraint, `__attribute__((selectany))` will become available 
everywhere. I guess that's OK.


https://reviews.llvm.org/D33852



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


[PATCH] D35683: [clang-format] Put '/**' and '*/' on own lines in multiline jsdocs

2017-07-20 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 107539.
krasimir marked 3 inline comments as done.
krasimir added a comment.

- Address review comments


https://reviews.llvm.org/D35683

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestJS.cpp
  unittests/Format/FormatTestJava.cpp

Index: unittests/Format/FormatTestJava.cpp
===
--- unittests/Format/FormatTestJava.cpp
+++ unittests/Format/FormatTestJava.cpp
@@ -525,6 +525,15 @@
"  void f() {}"));
 }
 
+TEST_F(FormatTestJava, KeepsDelimitersOnOwnLineInJavaDocComments) {
+  EXPECT_EQ("/**\n"
+" * javadoc line 1\n"
+" * javadoc line 2\n"
+" */",
+format("/** javadoc line 1\n"
+   " * javadoc line 2 */"));
+}
+
 TEST_F(FormatTestJava, RetainsLogicalShifts) {
 verifyFormat("void f() {\n"
  "  int a = 1;\n"
Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -67,6 +67,89 @@
"aaa);");
 }
 
+TEST_F(FormatTestJS, JSDocComments) {
+  // Break the first line of a multiline jsdoc comment.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 1\n"
+" * jsdoc line 2\n"
+" */",
+format("/** jsdoc line 1\n"
+   " * jsdoc line 2\n"
+   " */",
+   getGoogleJSStyleWithColumns(20)));
+  // Both break after '/**' and break the line itself.
+  EXPECT_EQ("/**\n"
+" * jsdoc line long\n"
+" * long jsdoc line 2\n"
+" */",
+format("/** jsdoc line long long\n"
+   " * jsdoc line 2\n"
+   " */",
+   getGoogleJSStyleWithColumns(20)));
+  // Break a short first line if the ending '*/' is on a newline.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 1\n"
+" */",
+format("/** jsdoc line 1\n"
+   " */", getGoogleJSStyleWithColumns(20)));
+  // Don't break the first line of a short single line jsdoc comment.
+  EXPECT_EQ("/** jsdoc line 1 */",
+format("/** jsdoc line 1 */", getGoogleJSStyleWithColumns(20)));
+  // Don't break the first line of a single line jsdoc comment if it just fits
+  // the column limit.
+  EXPECT_EQ("/** jsdoc line 12 */",
+format("/** jsdoc line 12 */", getGoogleJSStyleWithColumns(20)));
+  // Break the first line of a single line jsdoc comment if it just exceeds the
+  // column limit.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 123\n"
+" */",
+format("/** jsdoc line 123 */", getGoogleJSStyleWithColumns(20)));
+  // Break also if the leading indent of the first line is more than 1 column.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 123\n"
+" */",
+format("/**  jsdoc line 123 */", getGoogleJSStyleWithColumns(20)));
+  // Break also if the leading indent of the first line is more than 1 column.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 123\n"
+" */",
+format("/**   jsdoc line 123 */", getGoogleJSStyleWithColumns(20)));
+  // Break after the content of the last line.
+  EXPECT_EQ("/**\n"
+" * line 1\n"
+" * line 2\n"
+" */",
+format("/**\n"
+   " * line 1\n"
+   " * line 2 */",
+   getGoogleJSStyleWithColumns(20)));
+  // Break both the content and after the content of the last line.
+  EXPECT_EQ("/**\n"
+" * line 1\n"
+" * line long long\n"
+" * long\n"
+" */",
+format("/**\n"
+   " * line 1\n"
+   " * line long long long */",
+   getGoogleJSStyleWithColumns(20)));
+
+  // The comment block gets indented.
+  EXPECT_EQ("function f() {\n"
+"  /**\n"
+"   * comment about\n"
+"   * x\n"
+"   */\n"
+"  var x = 1;\n"
+"}",
+format("function f() {\n"
+   "  /** comment about x */\n"
+   "  var x = 1;\n"
+   "}",
+   getGoogleJSStyleWithColumns(20)));
+}
+
 TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
   verifyFormat("a == = b;");
   verifyFormat("a != = b;");
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1314,15 +1314,16 @@
   bool ReflowInProgress = false;
   unsigned Penalty = 0;
   unsigned RemainingTokenColumns = 0;
+  unsigned TailOffset = 0;
   for (unsigned LineIndex = 0, EndIndex = Token->getLineCount();
LineIndex 

[PATCH] D35683: [clang-format] Put '/**' and '*/' on own lines in multiline jsdocs

2017-07-20 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir marked 2 inline comments as done.
krasimir added inline comments.



Comment at: lib/Format/BreakableToken.cpp:435
+  // Detect a multiline jsdoc comment and set DelimitersOnNewline in that case.
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+if ((Lines[0] == "*" || Lines[0].startswith("* ")) && Lines.size() > 1) {

mprobst wrote:
> I think I'd also enable this for at least Java. But tentatively I wonder - 
> wouldn't just about every language do it like this for `/**` comments?
I agree for Java, but otherwise not. C++ is crazy with strange styles.



Comment at: lib/Format/BreakableToken.cpp:436
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+if ((Lines[0] == "*" || Lines[0].startswith("* ")) && Lines.size() > 1) {
+  // This is a multiline jsdoc comment.

mprobst wrote:
> mprobst wrote:
> > Wouldn't we also want to do this for `/**blah`, i.e. no whitespace after 
> > `*`?
> Would we also want to do this for simple block comments, e.g. `/*blah*/`?  
> That's a bit more tricky as they can be used inline, not sure about the 
> corner cases there.
I explicitly check for a whitespace after the `*` to take care of strange stuff 
that is not javadoc, like ASCII art or lines like:
```
/
 * #yolo
 */
```
I think we can decide for simple block comments later and leave them as-is for 
now.



Comment at: lib/Format/BreakableToken.cpp:606
+if (DelimitersOnNewline) {
+size_t BreakLength = Lines[0].substr(1).find_first_not_of(Blanks);
+if (BreakLength != StringRef::npos) {

mprobst wrote:
> isn't this BreakPosition rather than length?
It's both the BreakPosition and the BreakLength, because we're breaking 
starting from index 1.
Added a comment line (pun intended).


https://reviews.llvm.org/D35683



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


r308629 - [OPENMP] Fix DSA processing for member declaration.

2017-07-20 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Jul 20 09:47:47 2017
New Revision: 308629

URL: http://llvm.org/viewvc/llvm-project?rev=308629&view=rev
Log:
[OPENMP] Fix DSA processing for member declaration.

If the member declaration is captured in the OMPCapturedExprDecl, we may
loose data-sharing attribute info for this declaration. Patch fixes this
bug.

Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_reduction_messages.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/distribute_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/distribute_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/dump.cpp
cfe/trunk/test/OpenMP/for_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/for_reduction_messages.cpp
cfe/trunk/test/OpenMP/for_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/for_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_reduction_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/parallel_reduction_messages.cpp
cfe/trunk/test/OpenMP/parallel_sections_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/parallel_sections_reduction_messages.cpp
cfe/trunk/test/OpenMP/sections_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/sections_reduction_messages.cpp
cfe/trunk/test/OpenMP/simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/target_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_lastprivate_messages.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_messages.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_reduction_messages.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_lastprivate_messages.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/target_teams_reduction_messages.cpp
cfe/trunk/test/OpenMP/taskgroup_task_reduction_messages.cpp
cfe/trunk/test/OpenMP/taskloop_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/taskloop_reduction_messages.cpp
cfe/trunk/test/OpenMP/taskloop_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/taskloop_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_reduction_messages.cpp

cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_lastprivate_messages.cpp

cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_reduction_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_lastprivate_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_reduction_messages.cpp
cfe/trunk/test/OpenMP/teams_reduction_messages.cpp

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=308629&r1=308628&r2=308629&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Thu Jul 20 09:47:47 2017
@@ -1848,8 +1848,10 @@ Sema::BuildFieldReferenceExpr(Expr *Base
   if (getLangOpts().OpenMP && IsArrow &&
   !CurContext->isDependentContext() &&
   isa(Base.get()->IgnoreParenImpCasts())) {
-if (auto *PrivateCopy = IsOpenMPCapturedDecl(Field))
-  return getOpenMPCapturedExpr(PrivateCopy, VK, OK, OpLoc);
+if (auto *PrivateCopy = IsOpenMPCapturedDecl(Field)) {
+  return getOpenMPCapturedExpr(PrivateCopy, VK, OK,
+   MemberNameInfo.getLoc());
+}
   }
 
   return BuildMemberExpr(*this, Context, Base.get(), IsArrow, OpLoc, SS,

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

[PATCH] D33277: [Clang][x86][Inline Asm] - Enum support for MS syntax

2017-07-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rL LLVM

https://reviews.llvm.org/D33277



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


[PATCH] D32047: [Driver] Add support for default UBSan blacklists

2017-07-20 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

I'd like to address the current problems with sanitizer blacklists before 
moving on to this patch:
https://reviews.llvm.org/D32842

The summary is that the entries in a blacklist file apply to all sanitizers, 
resulting in potential false negatives when multiple default blacklists are 
loaded.


https://reviews.llvm.org/D32047



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


[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-20 Thread Anton Korobeynikov via Phabricator via cfe-commits
asl added a comment.

In https://reviews.llvm.org/D34440#809525, @alexfh wrote:

> In https://reviews.llvm.org/D34440#808156, @vladimir.plyashkun wrote:
>
> > **To discuss:**
> >  ...
> >  By this moment, we unable to use //CompilationDatabase.json// from //CLion 
> > //side which is widely used in //Clang-Tidy// and in other common tools.
>
>
> It would be interesting to learn more about the reasons why you can't use 
> JSON compilation database. In case you don't want to clutter the project's 
> directory, you can place the compile_commands.json file elsewhere (in a 
> temporary directory, for example) and point clang tools to this directory 
> using the `-p` command line flag.


Many build systems normally generate response files on-fly in some 
circumstances (e.g. if command line is longer than some platform-imposed 
limit). So IMO response files should be a perfect citizen here.


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



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


[PATCH] D35683: [clang-format] Put '/**' and '*/' on own lines in multiline jsdocs

2017-07-20 Thread Martin Probst via Phabricator via cfe-commits
mprobst accepted this revision.
mprobst added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Format/BreakableToken.cpp:436
+  if (Style.Language == FormatStyle::LK_JavaScript) {
+if ((Lines[0] == "*" || Lines[0].startswith("* ")) && Lines.size() > 1) {
+  // This is a multiline jsdoc comment.

krasimir wrote:
> mprobst wrote:
> > mprobst wrote:
> > > Wouldn't we also want to do this for `/**blah`, i.e. no whitespace after 
> > > `*`?
> > Would we also want to do this for simple block comments, e.g. `/*blah*/`?  
> > That's a bit more tricky as they can be used inline, not sure about the 
> > corner cases there.
> I explicitly check for a whitespace after the `*` to take care of strange 
> stuff that is not javadoc, like ASCII art or lines like:
> ```
> /
>  * #yolo
>  */
> ```
> I think we can decide for simple block comments later and leave them as-is 
> for now.
Makes sense. Maybe add some negative tests for such situations, to make sure we 
don't screw up the source?


https://reviews.llvm.org/D35683



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


[PATCH] D35426: [clang] Add abi-breaking-checks support to clang

2017-07-20 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

Ping for reviews please.


https://reviews.llvm.org/D35426



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


r308641 - [Docs] Regenerate the command line option reference.

2017-07-20 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Jul 20 10:52:48 2017
New Revision: 308641

URL: http://llvm.org/viewvc/llvm-project?rev=308641&view=rev
Log:
[Docs] Regenerate the command line option reference.

Modified:
cfe/trunk/docs/ClangCommandLineReference.rst

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=308641&r1=308640&r2=308641&view=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Thu Jul 20 10:52:48 2017
@@ -96,6 +96,8 @@ Emit ARC errors even if the migrator can
 
 Output path for the plist report
 
+.. option:: --autocomplete=
+
 .. option:: -bind\_at\_load
 
 .. option:: -bundle
@@ -292,7 +294,7 @@ Disable builtin #include directories
 
 .. option:: -nomultidefs
 
-.. option:: -nopie
+.. option:: -nopie, -no-pie
 
 .. option:: -noprebind
 
@@ -704,6 +706,10 @@ Don't use blacklist file for sanitizers
 
 Level of field padding for AddressSanitizer
 
+.. option:: -fsanitize-address-globals-dead-stripping
+
+Enable linker dead stripping of globals in AddressSanitizer
+
 .. option:: -fsanitize-address-use-after-scope, 
-fno-sanitize-address-use-after-scope
 
 Enable use-after-scope detection in AddressSanitizer
@@ -1071,6 +1077,10 @@ Target-independent compilation options
 
 Enable C++17 aligned allocation functions
 
+.. option:: -fallow-editor-placeholders, -fno-allow-editor-placeholders
+
+Treat editor placeholders as valid source code
+
 .. option:: -fallow-unsupported
 
 .. option:: -faltivec, -fno-altivec
@@ -1205,6 +1215,10 @@ Print absolute paths in diagnostics
 .. option:: -fdiagnostics-color=
 .. program:: clang
 
+.. option:: -fdiagnostics-hotness-threshold=
+
+Prevent optimization remarks from being output if they do not have at least 
this profile count
+
 .. option:: -fdiagnostics-show-hotness, -fno-diagnostics-show-hotness
 
 Enable profile hotness information in diagnostic line
@@ -1585,6 +1599,8 @@ Turn on loop reroller
 
 .. option:: -fretain-comments-from-system-headers
 
+.. option:: -frewrite-imports, -fno-rewrite-imports
+
 .. option:: -frewrite-includes, -fno-rewrite-includes
 
 .. option:: -frewrite-map-file 
@@ -1639,10 +1655,6 @@ Use SjLj style exceptions
 
 Enable the superword-level parallelism vectorization passes
 
-.. option:: -fslp-vectorize-aggressive, -fno-slp-vectorize-aggressive
-
-Enable the BB vectorization passes
-
 .. option:: -fspell-checking, -fno-spell-checking
 
 .. option:: -fspell-checking-limit=
@@ -1911,6 +1923,8 @@ Link stack frames through backchain on S
 
 .. option:: -mcpu=, -mv4 (equivalent to -mcpu=hexagonv4), -mv5 
(equivalent to -mcpu=hexagonv5), -mv55 (equivalent to -mcpu=hexagonv55), -mv60 
(equivalent to -mcpu=hexagonv60), -mv62 (equivalent to -mcpu=hexagonv62)
 
+.. option:: -mdefault-build-attributes, -mno-default-build-attributes
+
 .. option:: -mdll
 
 .. option:: -mdouble-float
@@ -1947,6 +1961,10 @@ Use 64-bit floating point registers (MIP
 
 Enable merging of globals
 
+.. option:: -mgpopt, -mno-gpopt
+
+Use GP relative accesses for symbols known to be in a small data section (MIPS)
+
 .. option:: -mhard-float
 
 .. option:: -mhwdiv=, --mhwdiv , --mhwdiv=
@@ -1975,10 +1993,16 @@ Use Intel MCU ABI
 
 Generate branches with extended addressability, usually via indirect jumps.
 
-.. option:: -mmacosx-version-min=
+.. option:: -mmacosx-version-min=, -mmacos-version-min=
 
 Set Mac OS X deployment target
 
+.. option:: -mmadd4, -mno-madd4
+
+Enable the generation of 4-operand madd.s, madd.d and related instructions.
+
+.. option:: -mmcu=
+
 .. option:: -mmicromips, -mno-micromips
 
 .. option:: -mms-bitfields, -mno-ms-bitfields
@@ -1989,6 +2013,10 @@ Set the default structure layout to be c
 
 Enable MSA ASE (MIPS only)
 
+.. option:: -mmt, -mno-mt
+
+Enable MT ASE (MIPS only)
+
 .. option:: -mnan=
 
 .. option:: -mno-mips16
@@ -2203,6 +2231,8 @@ X86
 
 .. option:: -mavx512vl, -mno-avx512vl
 
+.. option:: -mavx512vpopcntdq, -mno-avx512vpopcntdq
+
 .. option:: -mbmi, -mno-bmi
 
 .. option:: -mbmi2, -mno-bmi2
@@ -2225,6 +2255,8 @@ X86
 
 .. option:: -mfxsr, -mno-fxsr
 
+.. option:: -mlwp, -mno-lwp
+
 .. option:: -mlzcnt, -mno-lzcnt
 
 .. option:: -mmmx, -mno-mmx
@@ -2372,6 +2404,16 @@ Debug information flags
 
 .. option:: -gstrict-dwarf, -gno-strict-dwarf
 
+.. option:: -gz
+
+DWARF debug sections compression type
+
+.. program:: clang1
+.. option:: -gz=
+.. program:: clang
+
+DWARF debug sections compression type
+
 Static analyzer flags
 =
 


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


[PATCH] D35372: [clang-tidy] Add a close-on-exec check on memfd_create() in Android module.

2017-07-20 Thread Yan Wang via Phabricator via cfe-commits
yawanng updated this revision to Diff 107557.
yawanng added a comment.

Refactor the check, add a base class for it, which can facilitate all other 
similar checks. Basically, all checks in the same category will have only one 
or two lines code by inheriting the base class. If this looks good, I will 
modify all other similar ones. Thank you :-)


https://reviews.llvm.org/D35372

Files:
  clang-tidy/android/AndroidTidyModule.cpp
  clang-tidy/android/CMakeLists.txt
  clang-tidy/android/CloexecCheck.cpp
  clang-tidy/android/CloexecCheck.h
  clang-tidy/android/CloexecMemfdCreateCheck.cpp
  clang-tidy/android/CloexecMemfdCreateCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/android-cloexec-memfd-create.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/android-cloexec-memfd-create.cpp

Index: test/clang-tidy/android-cloexec-memfd-create.cpp
===
--- /dev/null
+++ test/clang-tidy/android-cloexec-memfd-create.cpp
@@ -0,0 +1,63 @@
+// RUN: %check_clang_tidy %s android-cloexec-memfd-create %t
+
+#define MFD_ALLOW_SEALING 1
+#define __O_CLOEXEC 3
+#define MFD_CLOEXEC __O_CLOEXEC
+#define TEMP_FAILURE_RETRY(exp) \
+  ({\
+int _rc;\
+do {\
+  _rc = (exp);  \
+} while (_rc == -1);\
+  })
+#define NULL 0
+
+extern "C" int memfd_create(const char *name, unsigned int flags);
+
+void a() {
+  memfd_create(NULL, MFD_ALLOW_SEALING);
+  // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: 'memfd_create' should use MFD_CLOEXEC where possible [android-cloexec-memfd-create]
+  // CHECK-FIXES: memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC)
+  TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING));
+  // CHECK-MESSAGES: :[[@LINE-1]]:58: warning: 'memfd_create'
+  // CHECK-FIXES: TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC))
+}
+
+void f() {
+  memfd_create(NULL, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'memfd_create'
+  // CHECK-FIXES: memfd_create(NULL, 3 | MFD_CLOEXEC)
+  TEMP_FAILURE_RETRY(memfd_create(NULL, 3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: 'memfd_create'
+  // CHECK-FIXES: TEMP_FAILURE_RETRY(memfd_create(NULL, 3 | MFD_CLOEXEC))
+
+  int flag = 3;
+  memfd_create(NULL, flag);
+  TEMP_FAILURE_RETRY(memfd_create(NULL, flag));
+}
+
+namespace i {
+int memfd_create(const char *name, unsigned int flags);
+
+void d() {
+  memfd_create(NULL, MFD_ALLOW_SEALING);
+  TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING));
+}
+
+} // namespace i
+
+void e() {
+  memfd_create(NULL, MFD_CLOEXEC);
+  TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_CLOEXEC));
+  memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC);
+  TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING | MFD_CLOEXEC));
+}
+
+class G {
+public:
+  int memfd_create(const char *name, unsigned int flags);
+  void d() {
+memfd_create(NULL, MFD_ALLOW_SEALING);
+TEMP_FAILURE_RETRY(memfd_create(NULL, MFD_ALLOW_SEALING));
+  }
+};
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -6,6 +6,7 @@
 .. toctree::
android-cloexec-creat
android-cloexec-fopen
+   android-cloexec-memfd-create
android-cloexec-open
android-cloexec-socket
boost-use-to-string
Index: docs/clang-tidy/checks/android-cloexec-memfd-create.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/android-cloexec-memfd-create.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - android-cloexec-memfd-create
+
+android-cloexec-memfd-create
+
+
+``memfd_create()`` should include ``MFD_CLOEXEC`` in its type argument to avoid
+the file descriptor leakage. Without this flag, an opened sensitive file would
+remain open across a fork+exec to a lower-privileged SELinux domain.
+
+Examples:
+
+.. code-block:: c++
+
+  memfd_create(name, MFD_ALLOW_SEALING);
+
+  // becomes
+
+  memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC);
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -73,6 +73,12 @@
 
   Checks if the required mode ``e`` exists in the mode argument of ``fopen()``.
 
+- New `android-cloexec-memfd_create
+  `_ check
+
+  Checks if the required file flag ``MFD_CLOEXEC`` is present in the argument of
+  ``memfd_create()``.
+
 - New `android-cloexec-socket
   `_ check
 
Index: clang-tidy/android/CloexecMemfdCreateCheck.h
===
--- /dev/null
+++ clang-tidy/android/CloexecMemfdCreateCheck.h
@@ -0,0 +1,35 @@
+//===--- CloexecMemfdCreateCheck.h -

Re: r308641 - [Docs] Regenerate the command line option reference.

2017-07-20 Thread Craig Topper via cfe-commits
Hans,

This needs to be ported to the 5.0 branch. Not sure if any new options have
been added to 6.0 since the branch that would make this patch not correct.
Probably safest to just regenerate it in the 5.0 branch.

~Craig

On Thu, Jul 20, 2017 at 10:52 AM, Craig Topper via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ctopper
> Date: Thu Jul 20 10:52:48 2017
> New Revision: 308641
>
> URL: http://llvm.org/viewvc/llvm-project?rev=308641&view=rev
> Log:
> [Docs] Regenerate the command line option reference.
>
> Modified:
> cfe/trunk/docs/ClangCommandLineReference.rst
>
> Modified: cfe/trunk/docs/ClangCommandLineReference.rst
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/
> ClangCommandLineReference.rst?rev=308641&r1=308640&r2=308641&view=diff
> 
> ==
> --- cfe/trunk/docs/ClangCommandLineReference.rst (original)
> +++ cfe/trunk/docs/ClangCommandLineReference.rst Thu Jul 20 10:52:48 2017
> @@ -96,6 +96,8 @@ Emit ARC errors even if the migrator can
>
>  Output path for the plist report
>
> +.. option:: --autocomplete=
> +
>  .. option:: -bind\_at\_load
>
>  .. option:: -bundle
> @@ -292,7 +294,7 @@ Disable builtin #include directories
>
>  .. option:: -nomultidefs
>
> -.. option:: -nopie
> +.. option:: -nopie, -no-pie
>
>  .. option:: -noprebind
>
> @@ -704,6 +706,10 @@ Don't use blacklist file for sanitizers
>
>  Level of field padding for AddressSanitizer
>
> +.. option:: -fsanitize-address-globals-dead-stripping
> +
> +Enable linker dead stripping of globals in AddressSanitizer
> +
>  .. option:: -fsanitize-address-use-after-scope,
> -fno-sanitize-address-use-after-scope
>
>  Enable use-after-scope detection in AddressSanitizer
> @@ -1071,6 +1077,10 @@ Target-independent compilation options
>
>  Enable C++17 aligned allocation functions
>
> +.. option:: -fallow-editor-placeholders, -fno-allow-editor-placeholders
> +
> +Treat editor placeholders as valid source code
> +
>  .. option:: -fallow-unsupported
>
>  .. option:: -faltivec, -fno-altivec
> @@ -1205,6 +1215,10 @@ Print absolute paths in diagnostics
>  .. option:: -fdiagnostics-color=
>  .. program:: clang
>
> +.. option:: -fdiagnostics-hotness-threshold=
> +
> +Prevent optimization remarks from being output if they do not have at
> least this profile count
> +
>  .. option:: -fdiagnostics-show-hotness, -fno-diagnostics-show-hotness
>
>  Enable profile hotness information in diagnostic line
> @@ -1585,6 +1599,8 @@ Turn on loop reroller
>
>  .. option:: -fretain-comments-from-system-headers
>
> +.. option:: -frewrite-imports, -fno-rewrite-imports
> +
>  .. option:: -frewrite-includes, -fno-rewrite-includes
>
>  .. option:: -frewrite-map-file 
> @@ -1639,10 +1655,6 @@ Use SjLj style exceptions
>
>  Enable the superword-level parallelism vectorization passes
>
> -.. option:: -fslp-vectorize-aggressive, -fno-slp-vectorize-aggressive
> -
> -Enable the BB vectorization passes
> -
>  .. option:: -fspell-checking, -fno-spell-checking
>
>  .. option:: -fspell-checking-limit=
> @@ -1911,6 +1923,8 @@ Link stack frames through backchain on S
>
>  .. option:: -mcpu=, -mv4 (equivalent to -mcpu=hexagonv4), -mv5
> (equivalent to -mcpu=hexagonv5), -mv55 (equivalent to -mcpu=hexagonv55),
> -mv60 (equivalent to -mcpu=hexagonv60), -mv62 (equivalent to
> -mcpu=hexagonv62)
>
> +.. option:: -mdefault-build-attributes,
> -mno-default-build-attributes
> +
>  .. option:: -mdll
>
>  .. option:: -mdouble-float
> @@ -1947,6 +1961,10 @@ Use 64-bit floating point registers (MIP
>
>  Enable merging of globals
>
> +.. option:: -mgpopt, -mno-gpopt
> +
> +Use GP relative accesses for symbols known to be in a small data section
> (MIPS)
> +
>  .. option:: -mhard-float
>
>  .. option:: -mhwdiv=, --mhwdiv , --mhwdiv=
> @@ -1975,10 +1993,16 @@ Use Intel MCU ABI
>
>  Generate branches with extended addressability, usually via indirect
> jumps.
>
> -.. option:: -mmacosx-version-min=
> +.. option:: -mmacosx-version-min=, -mmacos-version-min=
>
>  Set Mac OS X deployment target
>
> +.. option:: -mmadd4, -mno-madd4
> +
> +Enable the generation of 4-operand madd.s, madd.d and related
> instructions.
> +
> +.. option:: -mmcu=
> +
>  .. option:: -mmicromips, -mno-micromips
>
>  .. option:: -mms-bitfields, -mno-ms-bitfields
> @@ -1989,6 +2013,10 @@ Set the default structure layout to be c
>
>  Enable MSA ASE (MIPS only)
>
> +.. option:: -mmt, -mno-mt
> +
> +Enable MT ASE (MIPS only)
> +
>  .. option:: -mnan=
>
>  .. option:: -mno-mips16
> @@ -2203,6 +2231,8 @@ X86
>
>  .. option:: -mavx512vl, -mno-avx512vl
>
> +.. option:: -mavx512vpopcntdq, -mno-avx512vpopcntdq
> +
>  .. option:: -mbmi, -mno-bmi
>
>  .. option:: -mbmi2, -mno-bmi2
> @@ -2225,6 +2255,8 @@ X86
>
>  .. option:: -mfxsr, -mno-fxsr
>
> +.. option:: -mlwp, -mno-lwp
> +
>  .. option:: -mlzcnt, -mno-lzcnt
>
>  .. option:: -mmmx, -mno-mmx
> @@ -2372,6 +2404,16 @@ Debug information flags
>
>  .. option:: -gstrict-dwarf, -gno-strict-dwarf
>

[PATCH] D35693: [Driver][Darwin] Pass -munwind-table when !UseSjLjExceptions

2017-07-20 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
Herald added subscribers: kristof.beyls, aemerson.

When I compile the following code targeting arm64 and execute it, it terminates 
with an uncaught exception:  "libc++abi.dylib: terminating with uncaught 
exception of type int":

int foo1() noexcept {

  try {
throw 0;
  } catch (int i) {
return 0;
  }
  return 1;

}

int main() {

  return foo1();

}

This happens because function foo1 has attribute nounwind but doesn't have 
attribute uwtable on it, in which case Funcion::needsUnwindTableEntry, which is 
the function that determines whether an unwind table is needed, returns false.

  bool needsUnwindTableEntry() const {
return hasUWTable() || !doesNotThrow();
  }

This patch changes MachO::IsUnwindTablesDefault to return true when 
!UseSjLjExceptions. When the function returns true, -munwind-table is passed to 
the frontend, which causes IRGen to annotate functions with attribute uwtable.

One question: instead of adding uwtable in 
SetLLVMFunctionAttributesForDefinition whenever CodeGenOpts.UnwindTables is 
true, is it possible to limit it to functions that actually need unwind tables 
(for example, in TryMarkNoThrow in CodeGenFunction.cpp)?

rdar://problem/32411865


https://reviews.llvm.org/D35693

Files:
  include/clang/Driver/ToolChain.h
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/CrossWindows.cpp
  lib/Driver/ToolChains/CrossWindows.h
  lib/Driver/ToolChains/Darwin.cpp
  lib/Driver/ToolChains/Darwin.h
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Gnu.h
  lib/Driver/ToolChains/MSVC.cpp
  lib/Driver/ToolChains/MSVC.h
  lib/Driver/ToolChains/MinGW.cpp
  lib/Driver/ToolChains/MinGW.h
  lib/Driver/ToolChains/NetBSD.h
  test/Driver/clang-translation.c

Index: test/Driver/clang-translation.c
===
--- test/Driver/clang-translation.c
+++ test/Driver/clang-translation.c
@@ -69,6 +69,14 @@
 // ARMV7_HARDFLOAT-NOT: "-msoft-float"
 // ARMV7_HARDFLOAT: "-x" "c"
 
+// RUN: %clang -target arm64-apple-ios10 -### -S %s -arch arm64 2>&1 | \
+// RUN: FileCheck -check-prefix=ARM64-APPLE %s
+// ARM64-APPLE: -munwind-table
+
+// RUN: %clang -target armv7k-apple-watchos4.0 -### -S %s -arch armv7k 2>&1 | \
+// RUN: FileCheck -check-prefix=ARMV7K-APPLE %s
+// ARMV7K-APPLE: -munwind-table
+
 // RUN: %clang -target arm-linux -### -S %s -march=armv5e 2>&1 | \
 // RUN: FileCheck -check-prefix=ARMV5E %s
 // ARMV5E: clang
Index: lib/Driver/ToolChains/NetBSD.h
===
--- lib/Driver/ToolChains/NetBSD.h
+++ lib/Driver/ToolChains/NetBSD.h
@@ -65,7 +65,10 @@
   const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const override;
 
-  bool IsUnwindTablesDefault() const override { return true; }
+  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override {
+return true;
+  }
+
   SanitizerMask getSupportedSanitizers() const override;
 
 protected:
Index: lib/Driver/ToolChains/MinGW.h
===
--- lib/Driver/ToolChains/MinGW.h
+++ lib/Driver/ToolChains/MinGW.h
@@ -60,7 +60,7 @@
 const llvm::opt::ArgList &Args);
 
   bool IsIntegratedAssemblerDefault() const override;
-  bool IsUnwindTablesDefault() const override;
+  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
   bool isPICDefault() const override;
   bool isPIEDefault() const override;
   bool isPICDefaultForced() const override;
Index: lib/Driver/ToolChains/MinGW.cpp
===
--- lib/Driver/ToolChains/MinGW.cpp
+++ lib/Driver/ToolChains/MinGW.cpp
@@ -347,7 +347,7 @@
   return new tools::MinGW::Linker(*this);
 }
 
-bool toolchains::MinGW::IsUnwindTablesDefault() const {
+bool toolchains::MinGW::IsUnwindTablesDefault(const ArgList &Args) const {
   return getArch() == llvm::Triple::x86_64;
 }
 
Index: lib/Driver/ToolChains/MSVC.h
===
--- lib/Driver/ToolChains/MSVC.h
+++ lib/Driver/ToolChains/MSVC.h
@@ -73,7 +73,7 @@
 Action::OffloadKind DeviceOffloadKind) const override;
 
   bool IsIntegratedAssemblerDefault() const override;
-  bool IsUnwindTablesDefault() const override;
+  bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
   bool isPICDefault() const override;
   bool isPIEDefault() const override;
   bool isPICDefaultForced() const override;
Index: lib/Driver/ToolChains/MSVC.cpp
===
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -699,7 +699,7 @@
   return true;
 }
 
-bool MSVCToolChain::IsUnwindTablesDefault() const {
+bool MSVCToolChain::IsUnwindTablesDefault(const ArgList &Args) const {
   // Emit unwind tables by default on Win64. All non-x86_32 Windows platforms
  

[PATCH] D35652: [clang] Fix handling of "%zd" format specifier in scanf

2017-07-20 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap updated this revision to Diff 107569.
alexshap added a comment.

Address comments


Repository:
  rL LLVM

https://reviews.llvm.org/D35652

Files:
  lib/Analysis/ScanfFormatString.cpp
  test/Sema/format-strings-fixit-ssize_t.c
  test/Sema/format-strings-scanf.c

Index: test/Sema/format-strings-scanf.c
===
--- test/Sema/format-strings-scanf.c
+++ test/Sema/format-strings-scanf.c
@@ -1,10 +1,18 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -Wformat-nonliteral %s
 
 // Test that -Wformat=0 works:
-// RUN: %clang_cc1 -fsyntax-only -Werror -Wformat=0 %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -Werror -Wformat=0 %s
 
 #include 
-typedef __typeof(sizeof(int)) size_t;
+typedef __SIZE_TYPE__ size_t;
+#define __SSIZE_TYPE__ \
+  __typeof__(_Generic((__SIZE_TYPE__)0,\
+  unsigned long long int : (long long int)0,   \
+  unsigned long int : (long int)0, \
+  unsigned int : (int)0,   \
+  unsigned short : (short)0,   \
+  unsigned char : (signed char)0))
+typedef __SSIZE_TYPE__ ssize_t; 
 typedef struct _FILE FILE;
 typedef __WCHAR_TYPE__ wchar_t;
 
@@ -172,6 +180,26 @@
   scanf("%d", (cip_t)0); // expected-warning{{format specifies type 'int *' but the argument has type 'cip_t' (aka 'const int *')}}
 }
 
+void test_size_types() {
+  size_t s = 0;
+  scanf("%zu", &s); // No warning.
+
+  double d1 = 0.;
+  scanf("%zu", &d1); // expected-warning-re{{format specifies type 'size_t *' (aka '{{.+}}') but the argument has type 'double *'}}
+
+  ssize_t ss = 0;
+  scanf("%zd", &s); // No warning.
+
+  double d2 = 0.;
+  scanf("%zd", &d2); // expected-warning-re{{format specifies type 'ssize_t *' (aka '{{.+}}') but the argument has type 'double *'}}
+
+  ssize_t sn = 0;
+  scanf("%zn", &sn); // No warning.
+
+  double d3 = 0.;
+  scanf("%zn", &d3); // expected-warning-re{{format specifies type 'ssize_t *' (aka '{{.+}}') but the argument has type 'double *'}}
+}
+
 void check_conditional_literal(char *s, int *i) {
   scanf(0 ? "%s" : "%d", i); // no warning
   scanf(1 ? "%s" : "%d", i); // expected-warning{{format specifies type 'char *'}}
Index: test/Sema/format-strings-fixit-ssize_t.c
===
--- test/Sema/format-strings-fixit-ssize_t.c
+++ test/Sema/format-strings-fixit-ssize_t.c
@@ -1,18 +1,22 @@
 // RUN: cp %s %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -pedantic -Wall -fixit %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -pedantic -Wall -Werror %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -E -o - %t | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c99 -pedantic -Wall -fixit %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c99 -fsyntax-only -pedantic -Wall -Werror %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c99 -E -o - %t | FileCheck %s
 
 /* This is a test of the various code modification hints that are
provided as part of warning or extension diagnostics. All of the
warnings will be fixed by -fixit, and the resulting file should
compile cleanly with -Werror -pedantic. */
 
 int printf(char const *, ...);
+int scanf(const char *, ...);
 
 void test() {
   typedef signed long int ssize_t;
   printf("%f", (ssize_t) 42);
+  ssize_t s;
+  scanf("%f",  &s);
 }
 
 // CHECK: printf("%zd", (ssize_t) 42);
+// CHECK: scanf("%zd", &s)
Index: lib/Analysis/ScanfFormatString.cpp
===
--- lib/Analysis/ScanfFormatString.cpp
+++ lib/Analysis/ScanfFormatString.cpp
@@ -251,8 +251,7 @@
 case LengthModifier::AsIntMax:
   return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
 case LengthModifier::AsSizeT:
-  // FIXME: ssize_t.
-  return ArgType();
+  return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
 case LengthModifier::AsPtrDiff:
   return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
 case LengthModifier::AsLongDouble:
@@ -386,7 +385,7 @@
 case LengthModifier::AsIntMax:
   return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
 case LengthModifier::AsSizeT:
-  return ArgType(); // FIXME: ssize_t
+  return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
 case LengthModifier::AsPtrDiff:
   return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
 case LengthModifier::AsLongDouble:
___
cfe-commits mailing list
cfe-co

r308662 - [clang] Fix handling of "%zd" in scanf

2017-07-20 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Thu Jul 20 13:11:47 2017
New Revision: 308662

URL: http://llvm.org/viewvc/llvm-project?rev=308662&view=rev
Log:
[clang] Fix handling of "%zd" in scanf

This diff addresses FIXMEs in lib/Analysis/ScanfFormatString.cpp 
for the case of ssize_t format specifier and adds tests.
In particular, this change enables Clang to emit a warning 
on incorrect using of "%zd"/"%zn".

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D35652

Modified:
cfe/trunk/lib/Analysis/ScanfFormatString.cpp
cfe/trunk/test/Sema/format-strings-fixit-ssize_t.c
cfe/trunk/test/Sema/format-strings-scanf.c

Modified: cfe/trunk/lib/Analysis/ScanfFormatString.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ScanfFormatString.cpp?rev=308662&r1=308661&r2=308662&view=diff
==
--- cfe/trunk/lib/Analysis/ScanfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/ScanfFormatString.cpp Thu Jul 20 13:11:47 2017
@@ -251,8 +251,7 @@ ArgType ScanfSpecifier::getArgType(ASTCo
 case LengthModifier::AsIntMax:
   return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
 case LengthModifier::AsSizeT:
-  // FIXME: ssize_t.
-  return ArgType();
+  return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
 case LengthModifier::AsPtrDiff:
   return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), 
"ptrdiff_t"));
 case LengthModifier::AsLongDouble:
@@ -386,7 +385,7 @@ ArgType ScanfSpecifier::getArgType(ASTCo
 case LengthModifier::AsIntMax:
   return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
 case LengthModifier::AsSizeT:
-  return ArgType(); // FIXME: ssize_t
+  return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
 case LengthModifier::AsPtrDiff:
   return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), 
"ptrdiff_t"));
 case LengthModifier::AsLongDouble:

Modified: cfe/trunk/test/Sema/format-strings-fixit-ssize_t.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-fixit-ssize_t.c?rev=308662&r1=308661&r2=308662&view=diff
==
--- cfe/trunk/test/Sema/format-strings-fixit-ssize_t.c (original)
+++ cfe/trunk/test/Sema/format-strings-fixit-ssize_t.c Thu Jul 20 13:11:47 2017
@@ -1,7 +1,7 @@
 // RUN: cp %s %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -pedantic -Wall -fixit %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -pedantic -Wall 
-Werror %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -E -o - %t | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c99 -pedantic -Wall 
-fixit %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c99 -fsyntax-only 
-pedantic -Wall -Werror %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c99 -E -o - %t | 
FileCheck %s
 
 /* This is a test of the various code modification hints that are
provided as part of warning or extension diagnostics. All of the
@@ -9,10 +9,14 @@
compile cleanly with -Werror -pedantic. */
 
 int printf(char const *, ...);
+int scanf(const char *, ...);
 
 void test() {
   typedef signed long int ssize_t;
   printf("%f", (ssize_t) 42);
+  ssize_t s;
+  scanf("%f",  &s);
 }
 
 // CHECK: printf("%zd", (ssize_t) 42);
+// CHECK: scanf("%zd", &s)

Modified: cfe/trunk/test/Sema/format-strings-scanf.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-scanf.c?rev=308662&r1=308661&r2=308662&view=diff
==
--- cfe/trunk/test/Sema/format-strings-scanf.c (original)
+++ cfe/trunk/test/Sema/format-strings-scanf.c Thu Jul 20 13:11:47 2017
@@ -1,10 +1,18 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -Wformat-nonliteral %s
 
 // Test that -Wformat=0 works:
-// RUN: %clang_cc1 -fsyntax-only -Werror -Wformat=0 %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -Werror -Wformat=0 %s
 
 #include 
-typedef __typeof(sizeof(int)) size_t;
+typedef __SIZE_TYPE__ size_t;
+#define __SSIZE_TYPE__ 
\
+  __typeof__(_Generic((__SIZE_TYPE__)0,
\
+  unsigned long long int : (long long int)0,   
\
+  unsigned long int : (long int)0, 
\
+  unsigned int : (int)0,   
\
+  unsigned short : (short)0,   
\
+  unsigned char : (signed char)0))
+typedef __SSIZE_TYPE__ ssize_t; 
 typedef struct _FILE FILE;
 typedef __WCHAR_TYPE__ wchar_t;
 
@@ -172,6 +180,26 @@ void test_qualifier

[PATCH] D35652: [clang] Fix handling of "%zd" format specifier in scanf

2017-07-20 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308662: [clang] Fix handling of "%zd" in scanf (authored by 
alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D35652?vs=107569&id=107574#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35652

Files:
  cfe/trunk/lib/Analysis/ScanfFormatString.cpp
  cfe/trunk/test/Sema/format-strings-fixit-ssize_t.c
  cfe/trunk/test/Sema/format-strings-scanf.c

Index: cfe/trunk/lib/Analysis/ScanfFormatString.cpp
===
--- cfe/trunk/lib/Analysis/ScanfFormatString.cpp
+++ cfe/trunk/lib/Analysis/ScanfFormatString.cpp
@@ -251,8 +251,7 @@
 case LengthModifier::AsIntMax:
   return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
 case LengthModifier::AsSizeT:
-  // FIXME: ssize_t.
-  return ArgType();
+  return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
 case LengthModifier::AsPtrDiff:
   return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
 case LengthModifier::AsLongDouble:
@@ -386,7 +385,7 @@
 case LengthModifier::AsIntMax:
   return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t"));
 case LengthModifier::AsSizeT:
-  return ArgType(); // FIXME: ssize_t
+  return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t"));
 case LengthModifier::AsPtrDiff:
   return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
 case LengthModifier::AsLongDouble:
Index: cfe/trunk/test/Sema/format-strings-fixit-ssize_t.c
===
--- cfe/trunk/test/Sema/format-strings-fixit-ssize_t.c
+++ cfe/trunk/test/Sema/format-strings-fixit-ssize_t.c
@@ -1,18 +1,22 @@
 // RUN: cp %s %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -pedantic -Wall -fixit %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -pedantic -Wall -Werror %t
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -E -o - %t | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c99 -pedantic -Wall -fixit %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c99 -fsyntax-only -pedantic -Wall -Werror %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c99 -E -o - %t | FileCheck %s
 
 /* This is a test of the various code modification hints that are
provided as part of warning or extension diagnostics. All of the
warnings will be fixed by -fixit, and the resulting file should
compile cleanly with -Werror -pedantic. */
 
 int printf(char const *, ...);
+int scanf(const char *, ...);
 
 void test() {
   typedef signed long int ssize_t;
   printf("%f", (ssize_t) 42);
+  ssize_t s;
+  scanf("%f",  &s);
 }
 
 // CHECK: printf("%zd", (ssize_t) 42);
+// CHECK: scanf("%zd", &s)
Index: cfe/trunk/test/Sema/format-strings-scanf.c
===
--- cfe/trunk/test/Sema/format-strings-scanf.c
+++ cfe/trunk/test/Sema/format-strings-scanf.c
@@ -1,10 +1,18 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify -Wformat-nonliteral %s
 
 // Test that -Wformat=0 works:
-// RUN: %clang_cc1 -fsyntax-only -Werror -Wformat=0 %s
+// RUN: %clang_cc1 -std=c11 -fsyntax-only -Werror -Wformat=0 %s
 
 #include 
-typedef __typeof(sizeof(int)) size_t;
+typedef __SIZE_TYPE__ size_t;
+#define __SSIZE_TYPE__ \
+  __typeof__(_Generic((__SIZE_TYPE__)0,\
+  unsigned long long int : (long long int)0,   \
+  unsigned long int : (long int)0, \
+  unsigned int : (int)0,   \
+  unsigned short : (short)0,   \
+  unsigned char : (signed char)0))
+typedef __SSIZE_TYPE__ ssize_t; 
 typedef struct _FILE FILE;
 typedef __WCHAR_TYPE__ wchar_t;
 
@@ -172,6 +180,26 @@
   scanf("%d", (cip_t)0); // expected-warning{{format specifies type 'int *' but the argument has type 'cip_t' (aka 'const int *')}}
 }
 
+void test_size_types() {
+  size_t s = 0;
+  scanf("%zu", &s); // No warning.
+
+  double d1 = 0.;
+  scanf("%zu", &d1); // expected-warning-re{{format specifies type 'size_t *' (aka '{{.+}}') but the argument has type 'double *'}}
+
+  ssize_t ss = 0;
+  scanf("%zd", &s); // No warning.
+
+  double d2 = 0.;
+  scanf("%zd", &d2); // expected-warning-re{{format specifies type 'ssize_t *' (aka '{{.+}}') but the argument has type 'double *'}}
+
+  ssize_t sn = 0;
+  scanf("%zn", &sn); // No warning.
+
+  double d3 = 0.;
+  scanf("%zn", &d3); // expected-warning-re{{format specifies type 'ssize_t *' (aka '{{.+}}') but the argument has type

r308667 - [CodeGen][mips] Support `long_call/far/near` attributes

2017-07-20 Thread Simon Atanasyan via cfe-commits
Author: atanasyan
Date: Thu Jul 20 13:34:18 2017
New Revision: 308667

URL: http://llvm.org/viewvc/llvm-project?rev=308667&view=rev
Log:
[CodeGen][mips] Support `long_call/far/near` attributes

This patch adds support for the `long_call`, `far`, and `near` attributes
for MIPS targets. The `long_call` and `far` attributes are synonyms. All
these attributes override `-mlong-calls` / `-mno-long-calls` command
line options for particular function.

Differential revision: https://reviews.llvm.org/D35479

Added:
cfe/trunk/test/CodeGen/long-call-attr.c
cfe/trunk/test/Sema/attr-long-call.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/CodeGen/TargetInfo.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=308667&r1=308666&r2=308667&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Jul 20 13:34:18 2017
@@ -1188,6 +1188,18 @@ def MicroMips : InheritableAttr, TargetS
   let Documentation = [MicroMipsDocs];
 }
 
+def MipsLongCall : InheritableAttr, TargetSpecificAttr {
+  let Spellings = [GCC<"long_call">, GCC<"far">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [MipsCallStyleDocs];
+}
+
+def MipsShortCall : InheritableAttr, TargetSpecificAttr {
+  let Spellings = [GCC<"near">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [MipsCallStyleDocs];
+}
+
 def Mode : Attr {
   let Spellings = [GCC<"mode">];
   let Subjects = SubjectList<[Var, Enum, TypedefName, Field], ErrorDiag,

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=308667&r1=308666&r2=308667&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu Jul 20 13:34:18 2017
@@ -1323,6 +1323,26 @@ on the command line.
   }];
 }
 
+def MipsCallStyleDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the ``__attribute__((long_call))``, ``__attribute__((far))``,
+and ``__attribute__((near))`` attributes on MIPS targets. These attributes may
+only be added to function declarations and change the code generated
+by the compiler when directly calling the function. The ``near`` attribute
+allows calls to the function to be made using the ``jal`` instruction, which
+requires the function to be located in the same naturally aligned 256MB
+segment as the caller.  The ``long_call`` and ``far`` attributes are synonyms
+and require the use of a different call sequence that works regardless
+of the distance between the functions.
+
+These attributes have no effect for position-independent code.
+
+These attributes take priority over command line switches such
+as ``-mlong-calls`` and ``-mno-long-calls``.
+  }];
+}
+
 def AVRInterruptDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=308667&r1=308666&r2=308667&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Jul 20 13:34:18 2017
@@ -1080,7 +1080,7 @@ void CodeGenModule::setNonAliasAttribute
   GO->setSection(SA->getName());
   }
 
-  getTargetCodeGenInfo().setTargetAttributes(D, GO, *this);
+  getTargetCodeGenInfo().setTargetAttributes(D, GO, *this, ForDefinition);
 }
 
 void CodeGenModule::SetInternalFunctionAttributes(const Decl *D,
@@ -1147,7 +1147,9 @@ void CodeGenModule::CreateFunctionTypeMe
 
 void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
   bool IsIncompleteFunction,
-  bool IsThunk) {
+  bool IsThunk,
+  ForDefinition_t IsForDefinition) {
+
   if (llvm::Intrinsic::ID IID = F->getIntrinsicID()) {
 // If this is an intrinsic function, set the function's attributes
 // to the intrinsic's attributes.
@@ -1157,8 +1159,13 @@ void CodeGenModule::SetFunctionAttribute
 
   const auto *FD = cast(GD.getDecl());
 
-  if (!IsIncompleteFunction)
+  if (!IsIncompleteFunction) {
 SetLLVMFunctionAttributes(FD, getTypes().arrangeGlobalDeclaration(GD), F);
+// Setup target-specific attributes.
+if (

[PATCH] D35479: [CodeGen][mips] Support `long_call/far/near` attributes

2017-07-20 Thread Simon Atanasyan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308667: [CodeGen][mips] Support `long_call/far/near` 
attributes (authored by atanasyan).

Changed prior to commit:
  https://reviews.llvm.org/D35479?vs=107461&id=107578#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35479

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/lib/CodeGen/TargetInfo.h
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/CodeGen/long-call-attr.c
  cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test
  cfe/trunk/test/Sema/attr-long-call.c

Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -1080,7 +1080,7 @@
   GO->setSection(SA->getName());
   }
 
-  getTargetCodeGenInfo().setTargetAttributes(D, GO, *this);
+  getTargetCodeGenInfo().setTargetAttributes(D, GO, *this, ForDefinition);
 }
 
 void CodeGenModule::SetInternalFunctionAttributes(const Decl *D,
@@ -1147,7 +1147,9 @@
 
 void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
   bool IsIncompleteFunction,
-  bool IsThunk) {
+  bool IsThunk,
+  ForDefinition_t IsForDefinition) {
+
   if (llvm::Intrinsic::ID IID = F->getIntrinsicID()) {
 // If this is an intrinsic function, set the function's attributes
 // to the intrinsic's attributes.
@@ -1157,8 +1159,13 @@
 
   const auto *FD = cast(GD.getDecl());
 
-  if (!IsIncompleteFunction)
+  if (!IsIncompleteFunction) {
 SetLLVMFunctionAttributes(FD, getTypes().arrangeGlobalDeclaration(GD), F);
+// Setup target-specific attributes.
+if (!IsForDefinition)
+  getTargetCodeGenInfo().setTargetAttributes(FD, F, *this,
+ NotForDefinition);
+  }
 
   // Add the Returned attribute for "this", except for iOS 5 and earlier
   // where substantial code, including the libstdc++ dylib, was compiled with
@@ -2123,7 +2130,8 @@
 
   assert(F->getName() == MangledName && "name was uniqued!");
   if (D)
-SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk);
+SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk,
+  IsForDefinition);
   if (ExtraAttrs.hasAttributes(llvm::AttributeList::FunctionIndex)) {
 llvm::AttrBuilder B(ExtraAttrs, llvm::AttributeList::FunctionIndex);
 F->addAttributes(llvm::AttributeList::FunctionIndex, B);
Index: cfe/trunk/lib/CodeGen/TargetInfo.h
===
--- cfe/trunk/lib/CodeGen/TargetInfo.h
+++ cfe/trunk/lib/CodeGen/TargetInfo.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H
 #define LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H
 
+#include "CodeGenModule.h"
 #include "CGValue.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/LLVM.h"
@@ -34,7 +35,6 @@
 namespace CodeGen {
 class ABIInfo;
 class CallArgList;
-class CodeGenModule;
 class CodeGenFunction;
 class CGFunctionInfo;
 
@@ -55,7 +55,8 @@
   /// setTargetAttributes - Provides a convenient hook to handle extra
   /// target-specific attributes for the given global.
   virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
-   CodeGen::CodeGenModule &M) const {}
+   CodeGen::CodeGenModule &M,
+   ForDefinition_t IsForDefinition) const {}
 
   /// emitTargetMD - Provides a convenient hook to handle extra
   /// target-specific metadata for the given global.
Index: cfe/trunk/lib/CodeGen/TargetInfo.cpp
===
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp
@@ -1037,7 +1037,8 @@
   const llvm::Triple &Triple, const CodeGenOptions &Opts);
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
-   CodeGen::CodeGenModule &CGM) const override;
+   CodeGen::CodeGenModule &CGM,
+   ForDefinition_t IsForDefinition) const override;
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const override {
 // Darwin uses different dwarf register numbers for EH.
@@ -1904,9 +1905,11 @@
   }
 }
 
-void X86_32TargetCodeGenInfo::setTargetAttributes(const Decl *D,
-  llvm::GlobalValue *GV,
-CodeGen::CodeGenModule &CGM) const {
+void X86_32TargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModul

r308675 - [NVPTX] Add lowering of i128 params.

2017-07-20 Thread Artem Belevich via cfe-commits
Author: tra
Date: Thu Jul 20 14:16:03 2017
New Revision: 308675

URL: http://llvm.org/viewvc/llvm-project?rev=308675&view=rev
Log:
[NVPTX] Add lowering of i128 params.

The patch adds support of i128 params lowering. The changes are quite trivial to
support i128 as a "special case" of integer type. With this patch, we lower i128
params the same way as aggregates of size 16 bytes: .param .b8 _ [16].

Currently, NVPTX can't deal with the 128 bit integers:
* in some cases because of failed assertions like
  ValVTs.size() == OutVals.size() && "Bad return value decomposition"
* in other cases emitting PTX with .i128 or .u128 types (which are not valid 
[1])
  [1] 
http://docs.nvidia.com/cuda/parallel-thread-execution/index.html#fundamental-types

Differential Revision: https://reviews.llvm.org/D34555
Patch by: Denys Zariaiev (denys.zaria...@gmail.com)

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/CodeGen/target-data.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=308675&r1=308674&r2=308675&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Jul 20 14:16:03 2017
@@ -1833,9 +1833,9 @@ public:
 GPU = CudaArch::SM_20;
 
 if (TargetPointerWidth == 32)
-  resetDataLayout("e-p:32:32-i64:64-v16:16-v32:32-n16:32:64");
+  resetDataLayout("e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
 else
-  resetDataLayout("e-i64:64-v16:16-v32:32-n16:32:64");
+  resetDataLayout("e-i64:64-i128:128-v16:16-v32:32-n16:32:64");
 
 // If possible, get a TargetInfo for our host triple, so we can match its
 // types.

Modified: cfe/trunk/test/CodeGen/target-data.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/target-data.c?rev=308675&r1=308674&r2=308675&view=diff
==
--- cfe/trunk/test/CodeGen/target-data.c (original)
+++ cfe/trunk/test/CodeGen/target-data.c Thu Jul 20 14:16:03 2017
@@ -116,11 +116,11 @@
 
 // RUN: %clang_cc1 -triple nvptx-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=NVPTX
-// NVPTX: target datalayout = "e-p:32:32-i64:64-v16:16-v32:32-n16:32:64"
+// NVPTX: target datalayout = 
"e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64"
 
 // RUN: %clang_cc1 -triple nvptx64-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=NVPTX64
-// NVPTX64: target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
+// NVPTX64: target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
 
 // RUN: %clang_cc1 -triple r600-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=R600


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


[PATCH] D35701: Break up Targets.cpp into a header/impl pair per target type[NFCI]

2017-07-20 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Bitrig has to be eliminated - it's dead upstream and will be removed from LLVM. 
(confirmed from ex developers, nobody needs it any more)


https://reviews.llvm.org/D35701



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


[PATCH] D35701: Break up Targets.cpp into a header/impl pair per target type[NFCI]

2017-07-20 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover added a comment.

> I tended to keep function definitions in the class declaration unless it 
> caused additional includes to be necessary.

Was that for implementation simplicity, or part of some cunning design goal? A 
lot of these pairs look pretty header-heavy to me (especially given that we're 
overriding virtual functions so inlining is mostly impossible).


https://reviews.llvm.org/D35701



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


[PATCH] D35701: Break up Targets.cpp into a header/impl pair per target type[NFCI]

2017-07-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In https://reviews.llvm.org/D35701#816678, @t.p.northover wrote:

> > I tended to keep function definitions in the class declaration unless it 
> > caused additional includes to be necessary.
>
> Was that for implementation simplicity, or part of some cunning design goal? 
> A lot of these pairs look pretty header-heavy to me (especially given that 
> we're overriding virtual functions so inlining is mostly impossible).


No cunning design goal.  Mostly just trying to keep the implementation time as 
low as possible, so that I don't get hit by a need to manually rebase next time 
someone makes a change here.

In https://reviews.llvm.org/D35701#816680, @krytarowski wrote:

> Bitrig has to be eliminated - it's dead upstream and will be removed from 
> LLVM. (confirmed from ex developers, nobody needs it any more)


If no one has an objection, I can definitely remove that OS target and all 
references to it.  Is that your encouragement here?


https://reviews.llvm.org/D35701



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


[clang-tools-extra] r308678 - [clang-tools-extra] Add support for plain C structs in clang-reorder-fields

2017-07-20 Thread Alexander Shaposhnikov via cfe-commits
Author: alexshap
Date: Thu Jul 20 14:41:20 2017
New Revision: 308678

URL: http://llvm.org/viewvc/llvm-project?rev=308678&view=rev
Log:
[clang-tools-extra] Add support for plain C structs in clang-reorder-fields

This diff updates the tool clang-reorder-fields
to enable reordering of fields of plain C structs.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D35329

Added:
clang-tools-extra/trunk/test/clang-reorder-fields/PlainCStructFieldsOrder.c
Modified:
clang-tools-extra/trunk/clang-reorder-fields/ReorderFieldsAction.cpp

Modified: clang-tools-extra/trunk/clang-reorder-fields/ReorderFieldsAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-reorder-fields/ReorderFieldsAction.cpp?rev=308678&r1=308677&r2=308678&view=diff
==
--- clang-tools-extra/trunk/clang-reorder-fields/ReorderFieldsAction.cpp 
(original)
+++ clang-tools-extra/trunk/clang-reorder-fields/ReorderFieldsAction.cpp Thu 
Jul 20 14:41:20 2017
@@ -32,10 +32,10 @@ using namespace clang::ast_matchers;
 /// \brief Finds the definition of a record by name.
 ///
 /// \returns nullptr if the name is ambiguous or not found.
-static const CXXRecordDecl *findDefinition(StringRef RecordName,
-   ASTContext &Context) {
+static const RecordDecl *findDefinition(StringRef RecordName,
+ASTContext &Context) {
   auto Results = match(
-  recordDecl(hasName(RecordName), isDefinition()).bind("cxxRecordDecl"),
+  recordDecl(hasName(RecordName), isDefinition()).bind("recordDecl"),
   Context);
   if (Results.empty()) {
 llvm::errs() << "Definition of " << RecordName << "  not found\n";
@@ -46,14 +46,14 @@ static const CXXRecordDecl *findDefiniti
  << " is ambiguous, several definitions found\n";
 return nullptr;
   }
-  return selectFirst("cxxRecordDecl", Results);
+  return selectFirst("recordDecl", Results);
 }
 
 /// \brief Calculates the new order of fields.
 ///
 /// \returns empty vector if the list of fields doesn't match the definition.
 static SmallVector
-getNewFieldsOrder(const CXXRecordDecl *Definition,
+getNewFieldsOrder(const RecordDecl *Definition,
   ArrayRef DesiredFieldsOrder) {
   assert(Definition && "Definition is null");
 
@@ -97,7 +97,7 @@ addReplacement(SourceRange Old, SourceRa
 /// different accesses (public/protected/private) is not supported.
 /// \returns true on success.
 static bool reorderFieldsInDefinition(
-const CXXRecordDecl *Definition, ArrayRef NewFieldsOrder,
+const RecordDecl *Definition, ArrayRef NewFieldsOrder,
 const ASTContext &Context,
 std::map &Replacements) {
   assert(Definition && "Definition is null");
@@ -223,7 +223,7 @@ public:
   ReorderingConsumer &operator=(const ReorderingConsumer &) = delete;
 
   void HandleTranslationUnit(ASTContext &Context) override {
-const CXXRecordDecl *RD = findDefinition(RecordName, Context);
+const RecordDecl *RD = findDefinition(RecordName, Context);
 if (!RD)
   return;
 SmallVector NewFieldsOrder =
@@ -232,16 +232,21 @@ public:
   return;
 if (!reorderFieldsInDefinition(RD, NewFieldsOrder, Context, Replacements))
   return;
-for (const auto *C : RD->ctors())
-  if (const auto *D = dyn_cast(C->getDefinition()))
-reorderFieldsInConstructor(cast(D),
-   NewFieldsOrder, Context, Replacements);
 
-// We only need to reorder init list expressions for aggregate types.
+// CXXRD will be nullptr if C code (not C++) is being processed.
+const CXXRecordDecl *CXXRD = dyn_cast(RD);
+if (CXXRD)
+  for (const auto *C : CXXRD->ctors())
+if (const auto *D = dyn_cast(C->getDefinition()))
+  reorderFieldsInConstructor(cast(D),
+  NewFieldsOrder, Context, Replacements);
+
+// We only need to reorder init list expressions for 
+// plain C structs or C++ aggregate types.
 // For other types the order of constructor parameters is used,
 // which we don't change at the moment.
 // Now (v0) partial initialization is not supported.
-if (RD->isAggregate())
+if (!CXXRD || CXXRD->isAggregate())
   for (auto Result :
match(initListExpr(hasType(equalsNode(RD))).bind("initListExpr"),
  Context))

Added: 
clang-tools-extra/trunk/test/clang-reorder-fields/PlainCStructFieldsOrder.c
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-reorder-fields/PlainCStructFieldsOrder.c?rev=308678&view=auto
==
--- clang-tools-extra/trunk/test/clang-reorder-fields/PlainCStructFieldsOrder.c 
(added)
+++ clang-tools-extra/trunk/test/clang-reorder-fields/PlainCStructFieldsOrder.c 
Thu Jul 20 14:41:20 2017
@@ -0,0 +1,14 @@
+// RUN: clang-re

[PATCH] D35329: [clang-reorder-fields] Enable reordering for plain C structs

2017-07-20 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308678: [clang-tools-extra] Add support for plain C structs 
in clang-reorder-fields (authored by alexshap).

Changed prior to commit:
  https://reviews.llvm.org/D35329?vs=107143&id=107588#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35329

Files:
  clang-tools-extra/trunk/clang-reorder-fields/ReorderFieldsAction.cpp
  clang-tools-extra/trunk/test/clang-reorder-fields/PlainCStructFieldsOrder.c

Index: clang-tools-extra/trunk/clang-reorder-fields/ReorderFieldsAction.cpp
===
--- clang-tools-extra/trunk/clang-reorder-fields/ReorderFieldsAction.cpp
+++ clang-tools-extra/trunk/clang-reorder-fields/ReorderFieldsAction.cpp
@@ -32,10 +32,10 @@
 /// \brief Finds the definition of a record by name.
 ///
 /// \returns nullptr if the name is ambiguous or not found.
-static const CXXRecordDecl *findDefinition(StringRef RecordName,
-   ASTContext &Context) {
+static const RecordDecl *findDefinition(StringRef RecordName,
+ASTContext &Context) {
   auto Results = match(
-  recordDecl(hasName(RecordName), isDefinition()).bind("cxxRecordDecl"),
+  recordDecl(hasName(RecordName), isDefinition()).bind("recordDecl"),
   Context);
   if (Results.empty()) {
 llvm::errs() << "Definition of " << RecordName << "  not found\n";
@@ -46,14 +46,14 @@
  << " is ambiguous, several definitions found\n";
 return nullptr;
   }
-  return selectFirst("cxxRecordDecl", Results);
+  return selectFirst("recordDecl", Results);
 }
 
 /// \brief Calculates the new order of fields.
 ///
 /// \returns empty vector if the list of fields doesn't match the definition.
 static SmallVector
-getNewFieldsOrder(const CXXRecordDecl *Definition,
+getNewFieldsOrder(const RecordDecl *Definition,
   ArrayRef DesiredFieldsOrder) {
   assert(Definition && "Definition is null");
 
@@ -97,7 +97,7 @@
 /// different accesses (public/protected/private) is not supported.
 /// \returns true on success.
 static bool reorderFieldsInDefinition(
-const CXXRecordDecl *Definition, ArrayRef NewFieldsOrder,
+const RecordDecl *Definition, ArrayRef NewFieldsOrder,
 const ASTContext &Context,
 std::map &Replacements) {
   assert(Definition && "Definition is null");
@@ -223,25 +223,30 @@
   ReorderingConsumer &operator=(const ReorderingConsumer &) = delete;
 
   void HandleTranslationUnit(ASTContext &Context) override {
-const CXXRecordDecl *RD = findDefinition(RecordName, Context);
+const RecordDecl *RD = findDefinition(RecordName, Context);
 if (!RD)
   return;
 SmallVector NewFieldsOrder =
 getNewFieldsOrder(RD, DesiredFieldsOrder);
 if (NewFieldsOrder.empty())
   return;
 if (!reorderFieldsInDefinition(RD, NewFieldsOrder, Context, Replacements))
   return;
-for (const auto *C : RD->ctors())
-  if (const auto *D = dyn_cast(C->getDefinition()))
-reorderFieldsInConstructor(cast(D),
-   NewFieldsOrder, Context, Replacements);
 
-// We only need to reorder init list expressions for aggregate types.
+// CXXRD will be nullptr if C code (not C++) is being processed.
+const CXXRecordDecl *CXXRD = dyn_cast(RD);
+if (CXXRD)
+  for (const auto *C : CXXRD->ctors())
+if (const auto *D = dyn_cast(C->getDefinition()))
+  reorderFieldsInConstructor(cast(D),
+  NewFieldsOrder, Context, Replacements);
+
+// We only need to reorder init list expressions for 
+// plain C structs or C++ aggregate types.
 // For other types the order of constructor parameters is used,
 // which we don't change at the moment.
 // Now (v0) partial initialization is not supported.
-if (RD->isAggregate())
+if (!CXXRD || CXXRD->isAggregate())
   for (auto Result :
match(initListExpr(hasType(equalsNode(RD))).bind("initListExpr"),
  Context))
Index: clang-tools-extra/trunk/test/clang-reorder-fields/PlainCStructFieldsOrder.c
===
--- clang-tools-extra/trunk/test/clang-reorder-fields/PlainCStructFieldsOrder.c
+++ clang-tools-extra/trunk/test/clang-reorder-fields/PlainCStructFieldsOrder.c
@@ -0,0 +1,14 @@
+// RUN: clang-reorder-fields -record-name Foo -fields-order z,w,y,x %s -- | FileCheck %s
+
+struct Foo {
+  const int* x; // CHECK:  {{^  double z;}}
+  int y;// CHECK-NEXT: {{^  int w;}}
+  double z; // CHECK-NEXT: {{^  int y;}}
+  int w;// CHECK-NEXT: {{^  const int\* x}}
+};
+
+int main() {
+  const int x = 13;
+  struct Foo foo = { &x, 0, 1.29, 17 }; // CHECK: {{^  struct Foo foo = { 1.29, 17, 0, &x };}} 
+  return 0;
+}
___
cfe-commits mailing list
cfe-commits@lists.

[PATCH] D35701: Break up Targets.cpp into a header/impl pair per target type[NFCI]

2017-07-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In https://reviews.llvm.org/D35701#816680, @krytarowski wrote:

> Bitrig has to be eliminated - it's dead upstream and will be removed from 
> LLVM. (confirmed from ex developers, nobody needs it any more)


I just did a bit of looking about, and noticed that the "Bitrig" token is in a 
bunch of places.  I suspect what we need is for a single pair of patches (llvm 
& clang) dedicated to removing it.  I'd prefer to do those in a dedicated 
patchset if thats OK.


https://reviews.llvm.org/D35701



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


r308683 - [mips] Add support for -m(no-)local-sdata

2017-07-20 Thread Simon Dardis via cfe-commits
Author: sdardis
Date: Thu Jul 20 15:23:21 2017
New Revision: 308683

URL: http://llvm.org/viewvc/llvm-project?rev=308683&view=rev
Log:
[mips] Add support for -m(no-)local-sdata

Teach the driver to support -mlocal-sdata. The backend already matches GCC's
default behaviour.

Reviewers: atanasyan, slthakur

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/mips-features.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=308683&r1=308682&r2=308683&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Jul 20 15:23:21 2017
@@ -2041,6 +2041,10 @@ def mgpopt : Flag<["-"], "mgpopt">, Grou
 def mno_gpopt : Flag<["-"], "mno-gpopt">, Group,
   HelpText<"Do not use GP relative accesses for symbols known to be in a small"
" data section (MIPS)">;
+def mlocal_sdata : Flag<["-"], "mlocal-sdata">, Group,
+  HelpText<"Extend the -G behaviour to object local data (MIPS)">;
+def mno_local_sdata : Flag<["-"], "mno-local-sdata">, Group,
+  HelpText<"Do not extend the -G behaviour to object local data (MIPS)">;
 def mnan_EQ : Joined<["-"], "mnan=">, Group;
 def mabicalls : Flag<["-"], "mabicalls">, Group,
   HelpText<"Enable SVR4-style position-independent code (Mips only)">;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=308683&r1=308682&r2=308683&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Jul 20 15:23:21 2017
@@ -1480,6 +1480,19 @@ void Clang::AddMIPSTargetArgs(const ArgL
   if (NoABICalls && (!GPOpt || WantGPOpt)) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-mgpopt");
+
+Arg *LocalSData = Args.getLastArg(options::OPT_mlocal_sdata,
+  options::OPT_mno_local_sdata);
+if (LocalSData) {
+  CmdArgs.push_back("-mllvm");
+  if (LocalSData->getOption().matches(options::OPT_mlocal_sdata)) {
+CmdArgs.push_back("-mlocal-sdata=1");
+  } else {
+CmdArgs.push_back("-mlocal-sdata=0");
+  }
+  LocalSData->claim();
+}
+
   } else if ((!ABICalls || (!NoABICalls && ABICalls)) && WantGPOpt)
 D.Diag(diag::warn_drv_unsupported_gpopt) << (ABICalls ? 0 : 1);
 

Modified: cfe/trunk/test/Driver/mips-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mips-features.c?rev=308683&r1=308682&r2=308683&view=diff
==
--- cfe/trunk/test/Driver/mips-features.c (original)
+++ cfe/trunk/test/Driver/mips-features.c Thu Jul 20 15:23:21 2017
@@ -35,6 +35,21 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MGPOPTDEF %s
 // CHECK-MGPOPTDEF: "-mllvm" "-mgpopt"
 //
+// -mgpopt -mno-abicalls -mlocal-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mno-gpopt 
-mgpopt -mno-local-sdata -mlocal-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MLOCALSDATA %s
+// CHECK-MLOCALSDATA: "-mllvm" "-mlocal-sdata=1"
+//
+// -mgpopt -mno-abicalls -mno-local-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mno-gpopt 
-mgpopt -mlocal-sdata -mno-local-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MNOLOCALSDATA %s
+// CHECK-MNOLOCALSDATA: "-mllvm" "-mlocal-sdata=0"
+//
+// -mgpopt -mno-abicalls
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MLOCALSDATADEF %s
+// CHECK-MLOCALSDATADEF-NOT: "-mllvm" "-mlocal-sdata"
+//
 // -mips16
 // RUN: %clang -target mips-linux-gnu -### -c %s \
 // RUN: -mno-mips16 -mips16 2>&1 \


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


[PATCH] D35549: [mips] Add support for -m(no-)local-sdata

2017-07-20 Thread Simon Dardis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308683: [mips] Add support for -m(no-)local-sdata (authored 
by sdardis).

Changed prior to commit:
  https://reviews.llvm.org/D35549?vs=107071&id=107592#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35549

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/test/Driver/mips-features.c


Index: cfe/trunk/test/Driver/mips-features.c
===
--- cfe/trunk/test/Driver/mips-features.c
+++ cfe/trunk/test/Driver/mips-features.c
@@ -35,6 +35,21 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MGPOPTDEF %s
 // CHECK-MGPOPTDEF: "-mllvm" "-mgpopt"
 //
+// -mgpopt -mno-abicalls -mlocal-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mno-gpopt 
-mgpopt -mno-local-sdata -mlocal-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MLOCALSDATA %s
+// CHECK-MLOCALSDATA: "-mllvm" "-mlocal-sdata=1"
+//
+// -mgpopt -mno-abicalls -mno-local-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mno-gpopt 
-mgpopt -mlocal-sdata -mno-local-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MNOLOCALSDATA %s
+// CHECK-MNOLOCALSDATA: "-mllvm" "-mlocal-sdata=0"
+//
+// -mgpopt -mno-abicalls
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MLOCALSDATADEF %s
+// CHECK-MLOCALSDATADEF-NOT: "-mllvm" "-mlocal-sdata"
+//
 // -mips16
 // RUN: %clang -target mips-linux-gnu -### -c %s \
 // RUN: -mno-mips16 -mips16 2>&1 \
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -1480,6 +1480,19 @@
   if (NoABICalls && (!GPOpt || WantGPOpt)) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-mgpopt");
+
+Arg *LocalSData = Args.getLastArg(options::OPT_mlocal_sdata,
+  options::OPT_mno_local_sdata);
+if (LocalSData) {
+  CmdArgs.push_back("-mllvm");
+  if (LocalSData->getOption().matches(options::OPT_mlocal_sdata)) {
+CmdArgs.push_back("-mlocal-sdata=1");
+  } else {
+CmdArgs.push_back("-mlocal-sdata=0");
+  }
+  LocalSData->claim();
+}
+
   } else if ((!ABICalls || (!NoABICalls && ABICalls)) && WantGPOpt)
 D.Diag(diag::warn_drv_unsupported_gpopt) << (ABICalls ? 0 : 1);
 
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -2041,6 +2041,10 @@
 def mno_gpopt : Flag<["-"], "mno-gpopt">, Group,
   HelpText<"Do not use GP relative accesses for symbols known to be in a small"
" data section (MIPS)">;
+def mlocal_sdata : Flag<["-"], "mlocal-sdata">, Group,
+  HelpText<"Extend the -G behaviour to object local data (MIPS)">;
+def mno_local_sdata : Flag<["-"], "mno-local-sdata">, Group,
+  HelpText<"Do not extend the -G behaviour to object local data (MIPS)">;
 def mnan_EQ : Joined<["-"], "mnan=">, Group;
 def mabicalls : Flag<["-"], "mabicalls">, Group,
   HelpText<"Enable SVR4-style position-independent code (Mips only)">;


Index: cfe/trunk/test/Driver/mips-features.c
===
--- cfe/trunk/test/Driver/mips-features.c
+++ cfe/trunk/test/Driver/mips-features.c
@@ -35,6 +35,21 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MGPOPTDEF %s
 // CHECK-MGPOPTDEF: "-mllvm" "-mgpopt"
 //
+// -mgpopt -mno-abicalls -mlocal-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mno-gpopt -mgpopt -mno-local-sdata -mlocal-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MLOCALSDATA %s
+// CHECK-MLOCALSDATA: "-mllvm" "-mlocal-sdata=1"
+//
+// -mgpopt -mno-abicalls -mno-local-sdata
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mno-gpopt -mgpopt -mlocal-sdata -mno-local-sdata 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MNOLOCALSDATA %s
+// CHECK-MNOLOCALSDATA: "-mllvm" "-mlocal-sdata=0"
+//
+// -mgpopt -mno-abicalls
+// RUN: %clang -target mips-linux-gnu -### -c %s -mno-abicalls -mgpopt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MLOCALSDATADEF %s
+// CHECK-MLOCALSDATADEF-NOT: "-mllvm" "-mlocal-sdata"
+//
 // -mips16
 // RUN: %clang -target mips-linux-gnu -### -c %s \
 // RUN: -mno-mips16 -mips16 2>&1 \
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -1480,6 +1480,19 @@
   if (NoABICalls && (!GPOpt || WantGPOpt)) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-mgpopt");
+
+Arg *LocalSData = Args.getLastArg(options::OPT_mlo

[PATCH] D35683: [clang-format] Put '/**' and '*/' on own lines in multiline jsdocs

2017-07-20 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 107593.
krasimir marked an inline comment as done.
krasimir added a comment.

- Add negative tests


https://reviews.llvm.org/D35683

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestJS.cpp
  unittests/Format/FormatTestJava.cpp

Index: unittests/Format/FormatTestJava.cpp
===
--- unittests/Format/FormatTestJava.cpp
+++ unittests/Format/FormatTestJava.cpp
@@ -525,6 +525,15 @@
"  void f() {}"));
 }
 
+TEST_F(FormatTestJava, KeepsDelimitersOnOwnLineInJavaDocComments) {
+  EXPECT_EQ("/**\n"
+" * javadoc line 1\n"
+" * javadoc line 2\n"
+" */",
+format("/** javadoc line 1\n"
+   " * javadoc line 2 */"));
+}
+
 TEST_F(FormatTestJava, RetainsLogicalShifts) {
 verifyFormat("void f() {\n"
  "  int a = 1;\n"
Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -67,6 +67,99 @@
"aaa);");
 }
 
+TEST_F(FormatTestJS, JSDocComments) {
+  // Break the first line of a multiline jsdoc comment.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 1\n"
+" * jsdoc line 2\n"
+" */",
+format("/** jsdoc line 1\n"
+   " * jsdoc line 2\n"
+   " */",
+   getGoogleJSStyleWithColumns(20)));
+  // Both break after '/**' and break the line itself.
+  EXPECT_EQ("/**\n"
+" * jsdoc line long\n"
+" * long jsdoc line 2\n"
+" */",
+format("/** jsdoc line long long\n"
+   " * jsdoc line 2\n"
+   " */",
+   getGoogleJSStyleWithColumns(20)));
+  // Break a short first line if the ending '*/' is on a newline.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 1\n"
+" */",
+format("/** jsdoc line 1\n"
+   " */", getGoogleJSStyleWithColumns(20)));
+  // Don't break the first line of a short single line jsdoc comment.
+  EXPECT_EQ("/** jsdoc line 1 */",
+format("/** jsdoc line 1 */", getGoogleJSStyleWithColumns(20)));
+  // Don't break the first line of a single line jsdoc comment if it just fits
+  // the column limit.
+  EXPECT_EQ("/** jsdoc line 12 */",
+format("/** jsdoc line 12 */", getGoogleJSStyleWithColumns(20)));
+  // Don't break after '/**' and before '*/' if there is no space between
+  // '/**' and the content.
+  EXPECT_EQ(
+  "/*** nonjsdoc long\n"
+  " * line */",
+  format("/*** nonjsdoc long line */", getGoogleJSStyleWithColumns(20)));
+  EXPECT_EQ(
+  "/**strange long long\n"
+  " * line */",
+  format("/**strange long long line */", getGoogleJSStyleWithColumns(20)));
+  // Break the first line of a single line jsdoc comment if it just exceeds the
+  // column limit.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 123\n"
+" */",
+format("/** jsdoc line 123 */", getGoogleJSStyleWithColumns(20)));
+  // Break also if the leading indent of the first line is more than 1 column.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 123\n"
+" */",
+format("/**  jsdoc line 123 */", getGoogleJSStyleWithColumns(20)));
+  // Break also if the leading indent of the first line is more than 1 column.
+  EXPECT_EQ("/**\n"
+" * jsdoc line 123\n"
+" */",
+format("/**   jsdoc line 123 */", getGoogleJSStyleWithColumns(20)));
+  // Break after the content of the last line.
+  EXPECT_EQ("/**\n"
+" * line 1\n"
+" * line 2\n"
+" */",
+format("/**\n"
+   " * line 1\n"
+   " * line 2 */",
+   getGoogleJSStyleWithColumns(20)));
+  // Break both the content and after the content of the last line.
+  EXPECT_EQ("/**\n"
+" * line 1\n"
+" * line long long\n"
+" * long\n"
+" */",
+format("/**\n"
+   " * line 1\n"
+   " * line long long long */",
+   getGoogleJSStyleWithColumns(20)));
+
+  // The comment block gets indented.
+  EXPECT_EQ("function f() {\n"
+"  /**\n"
+"   * comment about\n"
+"   * x\n"
+"   */\n"
+"  var x = 1;\n"
+"}",
+format("function f() {\n"
+   "/** comment about x */\n"
+   "var x = 1;\n"
+   "}",
+   getGoogleJSStyleWithColumns(20)));
+}
+
 TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
   verifyFormat("a == = b;");
   verifyFormat("a != = b;");
Index: lib/Format/ContinuationIndenter

[PATCH] D35701: Break up Targets.cpp into a header/impl pair per target type[NFCI]

2017-07-20 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

In https://reviews.llvm.org/D35701#816703, @erichkeane wrote:

> In https://reviews.llvm.org/D35701#816680, @krytarowski wrote:
>
> > Bitrig has to be eliminated - it's dead upstream and will be removed from 
> > LLVM. (confirmed from ex developers, nobody needs it any more)
>
>
> I just did a bit of looking about, and noticed that the "Bitrig" token is in 
> a bunch of places.  I suspect what we need is for a single pair of patches 
> (llvm & clang) dedicated to removing it.  I'd prefer to do those in a 
> dedicated patchset if thats OK.


Please go for it.

Bitrig code has been merged back to OpenBSD.


https://reviews.llvm.org/D35701



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


r308684 - [clang-format] Put '/**' and '*/' on own lines in multiline jsdocs

2017-07-20 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Jul 20 15:29:39 2017
New Revision: 308684

URL: http://llvm.org/viewvc/llvm-project?rev=308684&view=rev
Log:
[clang-format] Put '/**' and '*/' on own lines in multiline jsdocs

Reviewers: mprobst

Reviewed By: mprobst

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=308684&r1=308683&r2=308684&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Thu Jul 20 15:29:39 2017
@@ -339,7 +339,8 @@ BreakableBlockComment::BreakableBlockCom
 const FormatToken &Token, unsigned StartColumn,
 unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
 encoding::Encoding Encoding, const FormatStyle &Style)
-: BreakableComment(Token, StartColumn, InPPDirective, Encoding, Style) {
+: BreakableComment(Token, StartColumn, InPPDirective, Encoding, Style),
+  DelimitersOnNewline(false) {
   assert(Tok.is(TT_BlockComment) &&
  "block comment section must start with a block comment");
 
@@ -430,8 +431,25 @@ BreakableBlockComment::BreakableBlockCom
   IndentAtLineBreak =
   std::max(IndentAtLineBreak, Decoration.size());
 
+  // Detect a multiline jsdoc comment and set DelimitersOnNewline in that case.
+  if (Style.Language == FormatStyle::LK_JavaScript ||
+  Style.Language == FormatStyle::LK_Java) {
+if ((Lines[0] == "*" || Lines[0].startswith("* ")) && Lines.size() > 1) {
+  // This is a multiline jsdoc comment.
+  DelimitersOnNewline = true;
+} else if (Lines[0].startswith("* ") && Lines.size() == 1) {
+  // Detect a long single-line comment, like:
+  // /** long long long */
+  // Below, '2' is the width of '*/'.
+  unsigned EndColumn = ContentColumn[0] + encoding::columnWidthWithTabs(
+  Lines[0], ContentColumn[0], Style.TabWidth, Encoding) + 2;
+  DelimitersOnNewline = EndColumn > Style.ColumnLimit;
+}
+  }
+
   DEBUG({
 llvm::dbgs() << "IndentAtLineBreak " << IndentAtLineBreak << "\n";
+llvm::dbgs() << "DelimitersOnNewline " << DelimitersOnNewline << "\n";
 for (size_t i = 0; i < Lines.size(); ++i) {
   llvm::dbgs() << i << " |" << Content[i] << "| "
<< "CC=" << ContentColumn[i] << "| "
@@ -580,10 +598,22 @@ unsigned BreakableBlockComment::getLineL
 return getLineLengthAfterSplit(LineIndex, TailOffset, StringRef::npos);
   }
 }
+
 void BreakableBlockComment::replaceWhitespaceBefore(
 unsigned LineIndex, unsigned PreviousEndColumn, unsigned ColumnLimit,
 Split SplitBefore, WhitespaceManager &Whitespaces) {
-  if (LineIndex == 0) return;
+  if (LineIndex == 0) {
+if (DelimitersOnNewline) {
+// Since we're breaking af index 1 below, the break position and the
+// break length are the same.
+size_t BreakLength = Lines[0].substr(1).find_first_not_of(Blanks);
+if (BreakLength != StringRef::npos) {
+  insertBreak(LineIndex, 0, Split(1, BreakLength), Whitespaces);
+  DelimitersOnNewline = true;
+}
+}
+return;
+  }
   StringRef TrimmedContent = Content[LineIndex].ltrim(Blanks);
   if (SplitBefore.first != StringRef::npos) {
 // Here we need to reflow.
@@ -651,6 +681,15 @@ void BreakableBlockComment::replaceWhite
   InPPDirective, /*Newlines=*/1, ContentColumn[LineIndex] - Prefix.size());
 }
 
+BreakableToken::Split BreakableBlockComment::getSplitAfterLastLine(
+unsigned TailOffset, unsigned ColumnLimit,
+llvm::Regex &CommentPragmasRegex) const {
+  if (DelimitersOnNewline)
+return getSplit(Lines.size() - 1, TailOffset, ColumnLimit,
+CommentPragmasRegex);
+  return Split(StringRef::npos, 0);
+}
+
 bool BreakableBlockComment::mayReflow(unsigned LineIndex,
   llvm::Regex &CommentPragmasRegex) const {
   // Content[LineIndex] may exclude the indent after the '*' decoration. In 
that

Modified: cfe/trunk/lib/Format/BreakableToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.h?rev=308684&r1=308683&r2=308684&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.h (original)
+++ cfe/trunk/lib/Format/BreakableToken.h Thu Jul 20 15:29:39 2017
@@ -64,6 +64,17 @@ struct FormatStyle;
 /// - replaceWhitespaceBefore, for executing the reflow using a whitespace
 ///   manager.
 ///
+/// For tokens that require the whitespace after the last line to be
+/// reformatted, for example in 

[PATCH] D35683: [clang-format] Put '/**' and '*/' on own lines in multiline jsdocs

2017-07-20 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308684: [clang-format] Put '/**' and '*/' on own lines in 
multiline jsdocs (authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D35683

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/lib/Format/BreakableToken.h
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp
  cfe/trunk/unittests/Format/FormatTestJava.cpp

Index: cfe/trunk/lib/Format/BreakableToken.h
===
--- cfe/trunk/lib/Format/BreakableToken.h
+++ cfe/trunk/lib/Format/BreakableToken.h
@@ -64,6 +64,17 @@
 /// - replaceWhitespaceBefore, for executing the reflow using a whitespace
 ///   manager.
 ///
+/// For tokens that require the whitespace after the last line to be
+/// reformatted, for example in multiline jsdoc comments that require the
+/// trailing '*/' to be on a line of itself, there are analogous operations
+/// that might be executed after the last line has been reformatted:
+/// - getSplitAfterLastLine, for finding a split after the last line that needs
+///   to be reflown,
+/// - getLineLengthAfterSplitAfterLastLine, for calculating the line length in
+///   columns of the remainder of the token, and
+/// - replaceWhitespaceAfterLastLine, for executing the reflow using a
+///   whitespace manager.
+///
 /// FIXME: The interface seems set in stone, so we might want to just pull the
 /// strategy into the class, instead of controlling it from the outside.
 class BreakableToken {
@@ -144,6 +155,38 @@
unsigned ColumnLimit, Split SplitBefore,
WhitespaceManager &Whitespaces) {}
 
+  /// \brief Returns a whitespace range (offset, length) of the content at
+  /// the last line that needs to be reformatted after the last line has been
+  /// reformatted.
+  ///
+  /// A result having offset == StringRef::npos means that no reformat is
+  /// necessary.
+  virtual Split getSplitAfterLastLine(unsigned TailOffset, unsigned ColumnLimit,
+  llvm::Regex &CommentPragmasRegex) const {
+return Split(StringRef::npos, 0);
+  }
+
+  /// \brief Returns the number of columns required to format the piece token
+  /// after the last line after a reformat of the whitespace range \p
+  /// \p SplitAfterLastLine on the last line has been performed.
+  virtual unsigned
+  getLineLengthAfterSplitAfterLastLine(unsigned TailOffset,
+   Split SplitAfterLastLine) const {
+return getLineLengthAfterSplit(getLineCount() - 1,
+   TailOffset + SplitAfterLastLine.first +
+   SplitAfterLastLine.second,
+   StringRef::npos);
+  }
+
+  /// \brief Replaces the whitespace from \p SplitAfterLastLine on the last line
+  /// after the last line has been formatted by performing a reformatting.
+  virtual void replaceWhitespaceAfterLastLine(unsigned TailOffset,
+  Split SplitAfterLastLine,
+  WhitespaceManager &Whitespaces) {
+insertBreak(getLineCount() - 1, TailOffset, SplitAfterLastLine,
+Whitespaces);
+  }
+
   /// \brief Updates the next token of \p State to the next token after this
   /// one. This can be used when this token manages a set of underlying tokens
   /// as a unit and is responsible for the formatting of the them.
@@ -304,6 +347,9 @@
   void replaceWhitespaceBefore(unsigned LineIndex, unsigned PreviousEndColumn,
unsigned ColumnLimit, Split SplitBefore,
WhitespaceManager &Whitespaces) override;
+  Split getSplitAfterLastLine(unsigned TailOffset, unsigned ColumnLimit,
+  llvm::Regex &CommentPragmasRegex) const override;
+
   bool mayReflow(unsigned LineIndex,
  llvm::Regex &CommentPragmasRegex) const override;
 
@@ -348,6 +394,10 @@
   // If this block comment has decorations, this is the column of the start of
   // the decorations.
   unsigned DecorationColumn;
+
+  // If true, make sure that the opening '/**' and the closing '*/' ends on a
+  // line of itself. Styles like jsdoc require this for multiline comments.
+  bool DelimitersOnNewline;
 };
 
 class BreakableLineCommentSection : public BreakableComment {
Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -339,7 +339,8 @@
 const FormatToken &Token, unsigned StartColumn,
 unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
 encoding::Encoding Encoding, const FormatStyle &Style)
-: BreakableComment(Token, StartColumn, InPPDirective, 

[PATCH] D35701: Break up Targets.cpp into a header/impl pair per target type[NFCI]

2017-07-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In https://reviews.llvm.org/D35701#816721, @krytarowski wrote:

> In https://reviews.llvm.org/D35701#816703, @erichkeane wrote:
>
> > In https://reviews.llvm.org/D35701#816680, @krytarowski wrote:
> >
> > > Bitrig has to be eliminated - it's dead upstream and will be removed from 
> > > LLVM. (confirmed from ex developers, nobody needs it any more)
> >
> >
> > I just did a bit of looking about, and noticed that the "Bitrig" token is 
> > in a bunch of places.  I suspect what we need is for a single pair of 
> > patches (llvm & clang) dedicated to removing it.  I'd prefer to do those in 
> > a dedicated patchset if thats OK.
>
>
> Please go for it.
>
> Bitrig code has been merged back to OpenBSD.


Ok, great!  I'm working on a series of patches to delete it right now on top of 
this patch.  I'll make sure to add you to the review.


https://reviews.llvm.org/D35701



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


[PATCH] D35705: [CMake] Use ABI version 2 for C++ library

2017-07-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
Herald added a subscriber: mgorny.

Repository:
  rL LLVM

https://reviews.llvm.org/D35705

Files:
  cmake/caches/Fuchsia-stage2.cmake


Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -46,6 +46,7 @@
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}-fuchsia_LIBCXX_ABI_VERSION 2 CACHE STRING "")
 endforeach()
 
 # Setup toolchain.


Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -46,6 +46,7 @@
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}-fuchsia_LIBCXX_ABI_VERSION 2 CACHE STRING "")
 endforeach()
 
 # Setup toolchain.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35705: [CMake] Use ABI version 2 for C++ library

2017-07-20 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr accepted this revision.
mcgrathr added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D35705



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


[PATCH] D35708: Remove Bitrig: Clang Changes

2017-07-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
Herald added subscribers: javed.absar, mgorny.

Bitrig code has been merged back to OpenBSD, thus the OS has been abandoned.


https://reviews.llvm.org/D35708

Files:
  lib/Basic/Targets.cpp
  lib/Basic/Targets/ARM.h
  lib/Basic/Targets/OSTargets.h
  lib/Basic/Targets/X86.h
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/CMakeLists.txt
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/Arch/X86.cpp
  lib/Driver/ToolChains/Bitrig.cpp
  lib/Driver/ToolChains/Bitrig.h
  lib/Frontend/InitHeaderSearch.cpp
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  test/CodeGen/linux-arm-atomic.c
  test/Driver/bitrig.c
  test/Frontend/gnu-mcount.c
  test/Preprocessor/init.c
  test/Sema/tls.c

Index: test/Sema/tls.c
===
--- test/Sema/tls.c
+++ test/Sema/tls.c
@@ -19,8 +19,4 @@
 // Haiku does not suppport TLS.
 // RUN: not %clang_cc1 -triple i586-pc-haiku -fsyntax-only %s
 
-// Bitrig suppports TLS.
-// RUN: %clang_cc1 -triple x86_64-pc-bitrig -fsyntax-only %s
-// RUN: %clang_cc1 -triple armv6-unknown-bitrig -fsyntax-only %s
-
 __thread int x;
Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -2413,13 +2413,6 @@
 // RUN: %clang -target x86_64-apple-darwin -arch armv7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARM-MACHO-NO-EABI %s
 // ARM-MACHO-NO-EABI-NOT: #define __ARM_EABI__ 1
 
-// RUN: %clang_cc1 -E -dM -ffreestanding -triple=armv7-bitrig-gnueabihf < /dev/null | FileCheck -match-full-lines -check-prefix ARM-BITRIG %s
-// ARM-BITRIG:#define __ARM_DWARF_EH__ 1
-// ARM-BITRIG:#define __SIZEOF_SIZE_T__ 4
-// ARM-BITRIG:#define __SIZE_MAX__ 4294967295UL
-// ARM-BITRIG:#define __SIZE_TYPE__ long unsigned int
-// ARM-BITRIG:#define __SIZE_WIDTH__ 32
-
 // Check that -mhwdiv works properly for targets which don't have the hwdiv feature enabled by default.
 
 // RUN: %clang -target arm -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMHWDIV-ARM %s
Index: test/Frontend/gnu-mcount.c
===
--- test/Frontend/gnu-mcount.c
+++ test/Frontend/gnu-mcount.c
@@ -28,10 +28,6 @@
 // RUN: %clang -target armv7-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-IOS
 // RUN: %clang -target arm64-apple-ios -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-IOS
 // RUN: %clang -target arm64-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-IOS
-// RUN: %clang -target armv7-unknown-bitrig-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-BIGRIG
-// RUN: %clang -target armv7-unknown-bitrig-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-BIGRIG
-// RUN: %clang -target aarch64-unknown-bitrig-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM64-EABI-BITRIG
-// RUN: %clang -target aarch64-unknown-bitrig-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM64-EABI-BITRIG
 // RUN: %clang -target armv7-unknown-rtems-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-RTEMS
 // RUN: %clang -target armv7-unknown-rtems-gnueabihf -meabi gnu -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-RTEMS
 // RUN: %clang -target aarch64-unknown-rtems-gnueabihf -pg -S -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM64-EABI-RTEMS
@@ -71,10 +67,6 @@
 // CHECK-ARM64-EABI-OPENBSD-NOT: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="\01__gnu_mcount_nc"{{.*}} }
 // CHECK-ARM-EABI-MEABI-GNU-NOT: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="mcount"{{.*}} }
 // CHECK-ARM-EABI-MEABI-GNU: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="\01__gnu_mcount_nc"{{.*}} }
-// CHECK-ARM-EABI-BITRIG: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="__mcount"{{.*}} }
-// CHECK-ARM-EABI-BITRIG-NOT: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="\01__gnu_mcount_nc"{{.*}} }
-// CHECK-ARM54-EABI-BITRIG: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="mcount"{{.*}} }
-// CHECK-ARM54-EABI-BITRIG-NOT: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="\01__gnu_mcount_nc"{{.*}} }
 // CHECK-ARM-EABI-RTEMS: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="mcount"{{.*}} }
 // CHECK-ARM-EABI-RTEMS-NOT: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="\01__gnu_mcount_nc"{{.*}} }
 // CHECK-ARM64-EABI-RTEMS: attributes #{{[0-9]+}} = { {{.*}}"counting-function"="mcount"{{.*}} }
Index: test/Driver/bitrig.c
===
--- te

[PATCH] D35709: Remove Bitrig: CompilerRT Changes

2017-07-20 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

Bitrig code has been merged back to OpenBSD, thus the OS has been abandoned.


https://reviews.llvm.org/D35709

Files:
  lib/builtins/clear_cache.c
  lib/builtins/int_endianness.h
  test/builtins/Unit/endianness.h


Index: test/builtins/Unit/endianness.h
===
--- test/builtins/Unit/endianness.h
+++ test/builtins/Unit/endianness.h
@@ -51,7 +51,7 @@
 
 /* .. */
 
-#if defined(__OpenBSD__) || defined(__Bitrig__)
+#if defined(__OpenBSD__)
 #include 
 
 #if _BYTE_ORDER == _BIG_ENDIAN
@@ -62,7 +62,7 @@
 #define _YUGA_BIG_ENDIAN0
 #endif /* _BYTE_ORDER */
 
-#endif /* OpenBSD and Bitrig. */
+#endif /* OpenBSD */
 
 /* .. */
 
Index: lib/builtins/int_endianness.h
===
--- lib/builtins/int_endianness.h
+++ lib/builtins/int_endianness.h
@@ -61,7 +61,7 @@
 
 #endif /* *BSD */
 
-#if defined(__OpenBSD__) || defined(__Bitrig__)
+#if defined(__OpenBSD__)
 #include 
 
 #if _BYTE_ORDER == _BIG_ENDIAN
@@ -72,7 +72,7 @@
 #define _YUGA_BIG_ENDIAN0
 #endif /* _BYTE_ORDER */
 
-#endif /* OpenBSD and Bitrig. */
+#endif /* OpenBSD */
 
 /* .. */
 
Index: lib/builtins/clear_cache.c
===
--- lib/builtins/clear_cache.c
+++ lib/builtins/clear_cache.c
@@ -23,7 +23,7 @@
 uintptr_t GetCurrentProcess(void);
 #endif
 
-#if (defined(__FreeBSD__) || defined(__Bitrig__)) && defined(__arm__)
+#if defined(__FreeBSD__) && defined(__arm__)
   #include 
   #include 
 #endif
@@ -96,7 +96,7 @@
  * so there is nothing to do
  */
 #elif defined(__arm__) && !defined(__APPLE__)
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__Bitrig__)
+#if defined(__FreeBSD__) || defined(__NetBSD__)
 struct arm_sync_icache_args arg;
 
 arg.addr = (uintptr_t)start;


Index: test/builtins/Unit/endianness.h
===
--- test/builtins/Unit/endianness.h
+++ test/builtins/Unit/endianness.h
@@ -51,7 +51,7 @@
 
 /* .. */
 
-#if defined(__OpenBSD__) || defined(__Bitrig__)
+#if defined(__OpenBSD__)
 #include 
 
 #if _BYTE_ORDER == _BIG_ENDIAN
@@ -62,7 +62,7 @@
 #define _YUGA_BIG_ENDIAN0
 #endif /* _BYTE_ORDER */
 
-#endif /* OpenBSD and Bitrig. */
+#endif /* OpenBSD */
 
 /* .. */
 
Index: lib/builtins/int_endianness.h
===
--- lib/builtins/int_endianness.h
+++ lib/builtins/int_endianness.h
@@ -61,7 +61,7 @@
 
 #endif /* *BSD */
 
-#if defined(__OpenBSD__) || defined(__Bitrig__)
+#if defined(__OpenBSD__)
 #include 
 
 #if _BYTE_ORDER == _BIG_ENDIAN
@@ -72,7 +72,7 @@
 #define _YUGA_BIG_ENDIAN0
 #endif /* _BYTE_ORDER */
 
-#endif /* OpenBSD and Bitrig. */
+#endif /* OpenBSD */
 
 /* .. */
 
Index: lib/builtins/clear_cache.c
===
--- lib/builtins/clear_cache.c
+++ lib/builtins/clear_cache.c
@@ -23,7 +23,7 @@
 uintptr_t GetCurrentProcess(void);
 #endif
 
-#if (defined(__FreeBSD__) || defined(__Bitrig__)) && defined(__arm__)
+#if defined(__FreeBSD__) && defined(__arm__)
   #include 
   #include 
 #endif
@@ -96,7 +96,7 @@
  * so there is nothing to do
  */
 #elif defined(__arm__) && !defined(__APPLE__)
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__Bitrig__)
+#if defined(__FreeBSD__) || defined(__NetBSD__)
 struct arm_sync_icache_args arg;
 
 arg.addr = (uintptr_t)start;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35701: Break up Targets.cpp into a header/impl pair per target type[NFCI]

2017-07-20 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Just review blank lines between every function. I'm too lazy to keep marking 
them.




Comment at: lib/Basic/Targets/AArch64.cpp:20
+using namespace clang::targets;
+const char *const AArch64TargetInfo::GCCRegNames[] = {
+// 32-bit Integer registers

Blank line



Comment at: lib/Basic/Targets/AArch64.h:1
+//===--- x86.h - Declare AArch64 target feature support 
---===//
+//

Header says x86



Comment at: lib/Basic/Targets/AArch64.h:1
+//===--- x86.h - Declare AArch64 target feature support 
---===//
+//

craig.topper wrote:
> Header says x86
Also I think .h files are supposed to have 'cpp' in their top line.



Comment at: lib/Basic/Targets/AArch64.h:16
+#define LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H
+#include "OSTargets.h"
+#include "clang/Basic/TargetBuiltins.h"

Prevailing style is blank line between the include guard and the includes i 
think



Comment at: lib/Basic/Targets/AArch64.h:19
+#include "llvm/Support/TargetParser.h"
+namespace clang {
+namespace targets {

Blank line



Comment at: lib/Basic/Targets/AArch64.h:20
+namespace clang {
+namespace targets {
+class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {

blank line



Comment at: lib/Basic/Targets/AArch64.h:426
+  : AArch64TargetInfo(Triple, Opts) {}
+  void getTargetDefines(const LangOptions &Opts,
+MacroBuilder &Builder) const override {

Blank line



Comment at: lib/Basic/Targets/AArch64.h:468
+};
+// 64-bit RenderScript is aarch64
+class LLVM_LIBRARY_VISIBILITY RenderScript64TargetInfo

Blank line



Comment at: lib/Basic/Targets/AMDGPU.cpp:25
+using namespace llvm;
+namespace clang {
+namespace targets {

blank line



Comment at: lib/Basic/Targets/AMDGPU.cpp:85
+} // namespace clang
+const Builtin::Info AMDGPUTargetInfo::BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS)   
\

Blank line



Comment at: lib/Basic/Targets/AMDGPU.cpp:92
+};
+const char *const AMDGPUTargetInfo::GCCRegNames[] = {"v0",
+ "v1",

Can we line break less often here.



Comment at: lib/Basic/Targets/AMDGPU.cpp:545
+}
+void AMDGPUTargetInfo::adjustTargetOptions(const CodeGenOptions &CGOpts,
+   TargetOptions &TargetOpts) const {

blank line



Comment at: lib/Basic/Targets/AMDGPU.cpp:566
+}
+AMDGPUTargetInfo::GPUKind AMDGPUTargetInfo::parseR600Name(StringRef Name) {
+  return llvm::StringSwitch(Name)

blank line



Comment at: lib/Basic/Targets/AMDGPU.h:23
+namespace targets {
+class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
+  static const Builtin::Info BuiltinInfo[];

Blank line


https://reviews.llvm.org/D35701



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


[PATCH] D35708: Remove Bitrig: Clang Changes

2017-07-20 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D35708



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


[PATCH] D35709: Remove Bitrig: CompilerRT Changes

2017-07-20 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a comment.

LGTM.


https://reviews.llvm.org/D35709



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


r308705 - [CMake] Use ABI version 2 for C++ library in Fuchsia

2017-07-20 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Thu Jul 20 17:59:38 2017
New Revision: 308705

URL: http://llvm.org/viewvc/llvm-project?rev=308705&view=rev
Log:
[CMake] Use ABI version 2 for C++ library in Fuchsia

Fuchsia has always been using ABI version 2 but I forgot this option
when setting up the cache file for runtimes build.

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

Modified:
cfe/trunk/cmake/caches/Fuchsia-stage2.cmake

Modified: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Fuchsia-stage2.cmake?rev=308705&r1=308704&r2=308705&view=diff
==
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake Thu Jul 20 17:59:38 2017
@@ -46,6 +46,7 @@ foreach(target x86_64;aarch64)
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}-fuchsia_LIBCXX_ABI_VERSION 2 CACHE STRING "")
 endforeach()
 
 # Setup toolchain.


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


[PATCH] D35705: [CMake] Use ABI version 2 for C++ library in Fuchsia

2017-07-20 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308705: [CMake] Use ABI version 2 for C++ library in Fuchsia 
(authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D35705?vs=107600&id=107617#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35705

Files:
  cfe/trunk/cmake/caches/Fuchsia-stage2.cmake


Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -46,6 +46,7 @@
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}-fuchsia_LIBCXX_ABI_VERSION 2 CACHE STRING "")
 endforeach()
 
 # Setup toolchain.


Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -46,6 +46,7 @@
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}-fuchsia_LIBCXX_ABI_VERSION 2 CACHE STRING "")
 endforeach()
 
 # Setup toolchain.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308707 - [Driver] Consider -fno-sanitize=... state when filtering out -fsanitize-coverage=...

2017-07-20 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Thu Jul 20 18:17:49 2017
New Revision: 308707

URL: http://llvm.org/viewvc/llvm-project?rev=308707&view=rev
Log:
[Driver] Consider -fno-sanitize=... state when filtering out 
-fsanitize-coverage=...

The driver ignores -fsanitize-coverage=... flags when also given
-fsanitize=... flags for sanitizer flavors that don't support the
coverage runtime. This logic failed to account for subsequent
-fno-sanitize=... flags that disable the sanitizer flavors that
conflict with -fsanitize-coverage=... flags.

Patch by Roland McGrath

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

Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize-coverage.c

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=308707&r1=308706&r2=308707&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Thu Jul 20 18:17:49 2017
@@ -504,7 +504,7 @@ SanitizerArgs::SanitizerArgs(const ToolC
 
   // Disable coverage and not claim the flags if there is at least one
   // non-supporting sanitizer.
-  if (!(AllAddedKinds & ~setGroupBits(SupportsCoverage))) {
+  if (!(AllAddedKinds & ~AllRemove & ~setGroupBits(SupportsCoverage))) {
 Arg->claim();
   } else {
 CoverageFeatures = 0;

Modified: cfe/trunk/test/Driver/fsanitize-coverage.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-coverage.c?rev=308707&r1=308706&r2=308707&view=diff
==
--- cfe/trunk/test/Driver/fsanitize-coverage.c (original)
+++ cfe/trunk/test/Driver/fsanitize-coverage.c Thu Jul 20 18:17:49 2017
@@ -95,3 +95,15 @@
 // CLANG-CL-COVERAGE-NOT: unknown argument
 // CLANG-CL-COVERAGE: -fsanitize-coverage-type=1
 // CLANG-CL-COVERAGE: -fsanitize=address
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fsanitize-coverage=trace-pc-guard %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-VS-SAFESTACK
+// CHECK-VS-SAFESTACK: -fsanitize=safe-stack
+// CHECK-VS-SAFESTACK-NOT: -fsanitize-coverage-trace-pc-guard
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fsanitize-coverage=trace-pc-guard -fno-sanitize=safe-stack %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-SAFESTACK
+// CHECK-NO-SAFESTACK-NOT: error:
+// CHECK-NO-SAFESTACK-NOT: warning:
+// CHECK-NO-SAFESTACK-NOT: argument unused
+// CHECK-NO-SAFESTACK-NOT: unknown argument
+// CHECK-NO-SAFESTACK-NOT: -fsanitize=safe-stack
+// CHECK-NO-SAFESTACK: -fsanitize-coverage-trace-pc-guard


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


[PATCH] D35603: [Driver] Consider -fno-sanitize=... state when filtering out -fsanitize-coverage=...

2017-07-20 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL308707: [Driver] Consider -fno-sanitize=... state when 
filtering out -fsanitizeā€¦ (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D35603?vs=107234&id=107620#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35603

Files:
  cfe/trunk/lib/Driver/SanitizerArgs.cpp
  cfe/trunk/test/Driver/fsanitize-coverage.c


Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -504,7 +504,7 @@
 
   // Disable coverage and not claim the flags if there is at least one
   // non-supporting sanitizer.
-  if (!(AllAddedKinds & ~setGroupBits(SupportsCoverage))) {
+  if (!(AllAddedKinds & ~AllRemove & ~setGroupBits(SupportsCoverage))) {
 Arg->claim();
   } else {
 CoverageFeatures = 0;
Index: cfe/trunk/test/Driver/fsanitize-coverage.c
===
--- cfe/trunk/test/Driver/fsanitize-coverage.c
+++ cfe/trunk/test/Driver/fsanitize-coverage.c
@@ -95,3 +95,15 @@
 // CLANG-CL-COVERAGE-NOT: unknown argument
 // CLANG-CL-COVERAGE: -fsanitize-coverage-type=1
 // CLANG-CL-COVERAGE: -fsanitize=address
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fsanitize-coverage=trace-pc-guard %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-VS-SAFESTACK
+// CHECK-VS-SAFESTACK: -fsanitize=safe-stack
+// CHECK-VS-SAFESTACK-NOT: -fsanitize-coverage-trace-pc-guard
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fsanitize-coverage=trace-pc-guard -fno-sanitize=safe-stack %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-SAFESTACK
+// CHECK-NO-SAFESTACK-NOT: error:
+// CHECK-NO-SAFESTACK-NOT: warning:
+// CHECK-NO-SAFESTACK-NOT: argument unused
+// CHECK-NO-SAFESTACK-NOT: unknown argument
+// CHECK-NO-SAFESTACK-NOT: -fsanitize=safe-stack
+// CHECK-NO-SAFESTACK: -fsanitize-coverage-trace-pc-guard


Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -504,7 +504,7 @@
 
   // Disable coverage and not claim the flags if there is at least one
   // non-supporting sanitizer.
-  if (!(AllAddedKinds & ~setGroupBits(SupportsCoverage))) {
+  if (!(AllAddedKinds & ~AllRemove & ~setGroupBits(SupportsCoverage))) {
 Arg->claim();
   } else {
 CoverageFeatures = 0;
Index: cfe/trunk/test/Driver/fsanitize-coverage.c
===
--- cfe/trunk/test/Driver/fsanitize-coverage.c
+++ cfe/trunk/test/Driver/fsanitize-coverage.c
@@ -95,3 +95,15 @@
 // CLANG-CL-COVERAGE-NOT: unknown argument
 // CLANG-CL-COVERAGE: -fsanitize-coverage-type=1
 // CLANG-CL-COVERAGE: -fsanitize=address
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -fsanitize-coverage=trace-pc-guard %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-VS-SAFESTACK
+// CHECK-VS-SAFESTACK: -fsanitize=safe-stack
+// CHECK-VS-SAFESTACK-NOT: -fsanitize-coverage-trace-pc-guard
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -fsanitize-coverage=trace-pc-guard -fno-sanitize=safe-stack %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SAFESTACK
+// CHECK-NO-SAFESTACK-NOT: error:
+// CHECK-NO-SAFESTACK-NOT: warning:
+// CHECK-NO-SAFESTACK-NOT: argument unused
+// CHECK-NO-SAFESTACK-NOT: unknown argument
+// CHECK-NO-SAFESTACK-NOT: -fsanitize=safe-stack
+// CHECK-NO-SAFESTACK: -fsanitize-coverage-trace-pc-guard
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35715: Preserve typedef names in debug info for template type parameters

2017-07-20 Thread Paul Robinson via Phabricator via cfe-commits
probinson created this revision.

If a template instantiation uses a typedef'd name as a template parameter, this 
is usually resolved
to its underlying type when we generate the name of the instance in the debug 
info.
PS4 prefers to see the original parameter as in the source.  Define an option 
that makes that happen,
and have the default for the option depend on debugger tuning.

This also provides some motivation for https://reviews.llvm.org/D14358.


https://reviews.llvm.org/D35715

Files:
  include/clang/AST/PrettyPrinter.h
  include/clang/AST/TemplateBase.h
  include/clang/AST/Type.h
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  lib/AST/TemplateBase.cpp
  lib/AST/Type.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaTemplate.cpp
  test/CodeGen/debug-template-types.cpp
  test/Driver/clang_f_opts.c
  test/Index/print-type.cpp

Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -119,7 +119,9 @@
 // CHECK: TemplateRef=Baz:9:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] [typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] [canonicaltype=outer::Qux, int>] [canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] [typekind=Int]] [isPOD=1]
+// The expression in the next line is for -femit-typedefs-in-template-types
+// which is the default on PS4.
+// CHECK: FieldDecl=qux:29:38 (Definition) [type=Qux, outer::inner::Bar::FooType>] [typekind=Unexposed] [templateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer] [type=Foo] [typekind=Unexposed] [type=outer::inner::Bar::FooType] [typekind=Typedef]] [canonicaltype=outer::Qux, {{int|outer::inner::Bar::FooType}}>] [canonicaltypekind=Record] [canonicaltemplateargs/4= [type=int] [typekind=Int] [type=char *] [typekind=Pointer] [type=outer::Foo] [typekind=Record] [type=int] [typekind=Int]] [isPOD=1]
 // CHECK: TemplateRef=Qux:12:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: TemplateRef=Foo:4:8 [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: FunctionTemplate=tbar:36:3 [type=T (int)] [typekind=FunctionProto] [canonicaltype=type-parameter-0-0 (int)] [canonicaltypekind=FunctionProto] [resulttype=T] [resulttypekind=Unexposed] [isPOD=0]
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -496,3 +496,10 @@
 // RUN: %clang -### -S -fno-allow-editor-placeholders %s 2>&1 | FileCheck -check-prefix=CHECK-NO-ALLOW-PLACEHOLDERS %s
 // CHECK-ALLOW-PLACEHOLDERS: -fallow-editor-placeholders
 // CHECK-NO-ALLOW-PLACEHOLDERS-NOT: -fallow-editor-placeholders
+
+// RUN: %clang -### -femit-typedefs-in-template-types %s 2>&1 | FileCheck -check-prefix=CHECK-EMIT-TYPEDEF-NAMES %s
+// RUN: %clang -### -fno-emit-typedefs-in-template-types %s 2>&1 | FileCheck -check-prefix=CHECK-NO-EMIT-TYPEDEF-NAMES %s
+// RUN: %clang -### -gsce %s 2>&1 | FileCheck -check-prefix=CHECK-EMIT-TYPEDEF-NAMES %s
+// RUN: %clang -### -ggdb %s 2>&1 | FileCheck -check-prefix=CHECK-NO-EMIT-TYPEDEF-NAMES %s
+// CHECK-EMIT-TYPEDEF-NAMES:-femit-typedefs-in-template-types
+// CHECK-NO-EMIT-TYPEDEF-NAMES-NOT: -femit-typedefs-in-template-types
Index: test/CodeGen/debug-template-types.cpp
===
--- test/CodeGen/debug-template-types.cpp
+++ test/CodeGen/debug-template-types.cpp
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone -fgnu-keywords -std=c++11 -femit-typedefs-in-template-types -emit-llvm %s -o - | FileCheck %s
+
+// With -femit-typedefs-in-template-types, template parameter type names should
+// not be stripped of typedef names. This test tries some more complicated
+// cases to check that we don't drop qualifiers and attach them correctly to
+// the typename.
+
+
+class A
+{
+public:
+  int i;
+  A(){}
+};
+
+typedef A myA;
+
+myA a1;
+
+volatile decltype(a1) a;
+
+template  
+class B
+{
+  T t;
+};
+
+// See that we collect all the qualifiers while finding the topmost typedef 
+B b;
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_class_type, name: "B"
+
+class C
+{
+public:
+  C(){}
+  C(volatile C&){}
+};
+
+typedef volatile C myC;
+
+const myC c;
+
+template  
+class D
+{
+  T t;
+};
+
+// See that we don't add the typedef's qualifiers to the type name
+D d;
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_class_type, name: "D"
+
+
+typedef int func();
+typedef float myFloat;
+
+template 
+class F
+{

[PATCH] D35577: Add -flookup-tables and -fno-lookup-tables flags

2017-07-20 Thread Eric Christopher via Phabricator via cfe-commits
echristo added a comment.

So, what's the overall logical idea behind the need for this option? While I 
understand that you don't want people just doing this via the -mllvm set of 
options, but if you're just doing this to provide a temporary option rather 
than turning it off in the backend I'm not sure what the point is.

Can you elaborate more on why you need to expose this via the front end?


https://reviews.llvm.org/D35577



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


[PATCH] D35715: Preserve typedef names in debug info for template type parameters

2017-07-20 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: include/clang/AST/PrettyPrinter.h:205
+
+  /// \brief When true, print template type arguments without removing 
typedefs.
+  unsigned PrintTemplateTypesWithTypedefs : 1;

`\brief` is no longer necessary and just makes the source code harder to read.



Comment at: include/clang/Basic/LangOptions.def:266
+LANGOPT(EmitTypedefNamesInTemplateTypes, 1, 0,
+"emit typedef names in template types (DWARF)")
+

Perhaps PreserveSugarInTemplateTypes since it appears to also affect qualifiers?


https://reviews.llvm.org/D35715



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


[PATCH] D35693: [Driver][Darwin] Pass -munwind-table when !UseSjLjExceptions

2017-07-20 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Does the ARM64 ABI call for unwind tables to be emitted for all functions, like 
the x86-64 ABI does?

Anyway, it seems pretty unfortunate that the default behavior breaks exceptions.


https://reviews.llvm.org/D35693



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


[PATCH] D35718: [clang-tidy] Do not issue fixit for explicit template specializations

2017-07-20 Thread Felix Berger via Phabricator via cfe-commits
flx created this revision.
Herald added subscribers: xazax.hun, JDevlieghere.

Do not issue fixit in UnnecessaryValueParamCheck if the function is an explicit 
template specialization as this could cause build breakages.


Repository:
  rL LLVM

https://reviews.llvm.org/D35718

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


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -348,3 +348,13 @@
   ExpensiveToCopyType E;
   NegativeUsingConstructor S(E);
 }
+
+template
+void templateFunction(T) {
+}
+
+template<>
+void templateFunction(ExpensiveToCopyType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:64: warning: the parameter 'E' is copied
+  E.constReference();
+}
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -58,6 +58,18 @@
   return Matches.empty();
 }
 
+bool isExplicitTemplateSpecialization(const FunctionDecl &Function) {
+  if (const auto *SpecializationInfo = 
Function.getTemplateSpecializationInfo())
+if (SpecializationInfo->getTemplateSpecializationKind() ==
+TSK_ExplicitSpecialization)
+  return true;
+  if (const auto *Method = llvm::dyn_cast(&Function))
+if (Method->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization &&
+Method->getMemberSpecializationInfo()->isExplicitSpecialization())
+  return true;
+  return false;
+}
+
 } // namespace
 
 UnnecessaryValueParamCheck::UnnecessaryValueParamCheck(
@@ -133,9 +145,11 @@
   // 2. the function is virtual as it might break overrides
   // 3. the function is referenced outside of a call expression within the
   //compilation unit as the signature change could introduce build errors.
+  // 4. the function is an explicit template specialization.
   const auto *Method = llvm::dyn_cast(Function);
   if (Param->getLocStart().isMacroID() || (Method && Method->isVirtual()) ||
-  isReferencedOutsideOfCallExpr(*Function, *Result.Context))
+  isReferencedOutsideOfCallExpr(*Function, *Result.Context) ||
+  isExplicitTemplateSpecialization(*Function))
 return;
   for (const auto *FunctionDecl = Function; FunctionDecl != nullptr;
FunctionDecl = FunctionDecl->getPreviousDecl()) {


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -348,3 +348,13 @@
   ExpensiveToCopyType E;
   NegativeUsingConstructor S(E);
 }
+
+template
+void templateFunction(T) {
+}
+
+template<>
+void templateFunction(ExpensiveToCopyType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:64: warning: the parameter 'E' is copied
+  E.constReference();
+}
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -58,6 +58,18 @@
   return Matches.empty();
 }
 
+bool isExplicitTemplateSpecialization(const FunctionDecl &Function) {
+  if (const auto *SpecializationInfo = Function.getTemplateSpecializationInfo())
+if (SpecializationInfo->getTemplateSpecializationKind() ==
+TSK_ExplicitSpecialization)
+  return true;
+  if (const auto *Method = llvm::dyn_cast(&Function))
+if (Method->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization &&
+Method->getMemberSpecializationInfo()->isExplicitSpecialization())
+  return true;
+  return false;
+}
+
 } // namespace
 
 UnnecessaryValueParamCheck::UnnecessaryValueParamCheck(
@@ -133,9 +145,11 @@
   // 2. the function is virtual as it might break overrides
   // 3. the function is referenced outside of a call expression within the
   //compilation unit as the signature change could introduce build errors.
+  // 4. the function is an explicit template specialization.
   const auto *Method = llvm::dyn_cast(Function);
   if (Param->getLocStart().isMacroID() || (Method && Method->isVirtual()) ||
-  isReferencedOutsideOfCallExpr(*Function, *Result.Context))
+  isReferencedOutsideOfCallExpr(*Function, *Result.Context) ||
+  isExplicitTemplateSpecialization(*Function))
 return;
   for (const auto *FunctionDecl = Function; FunctionDecl != nullptr;
FunctionDecl = FunctionDecl->getPreviousDecl()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r308714 - Fix tblgen error.

2017-07-20 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Thu Jul 20 21:56:48 2017
New Revision: 308714

URL: http://llvm.org/viewvc/llvm-project?rev=308714&view=rev
Log:
Fix tblgen error.

tblgen couldn't determing a unique name between "long_call" and "far", so it
errored out when generating documentation.  Copy the documentation, and give
an explicit header for "long_call".

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=308714&r1=308713&r2=308714&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Jul 20 21:56:48 2017
@@ -1191,13 +1191,13 @@ def MicroMips : InheritableAttr, TargetS
 def MipsLongCall : InheritableAttr, TargetSpecificAttr {
   let Spellings = [GCC<"long_call">, GCC<"far">];
   let Subjects = SubjectList<[Function]>;
-  let Documentation = [MipsCallStyleDocs];
+  let Documentation = [MipsLongCallStyleDocs];
 }
 
 def MipsShortCall : InheritableAttr, TargetSpecificAttr {
   let Spellings = [GCC<"near">];
   let Subjects = SubjectList<[Function]>;
-  let Documentation = [MipsCallStyleDocs];
+  let Documentation = [MipsShortCallStyleDocs];
 }
 
 def Mode : Attr {

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=308714&r1=308713&r2=308714&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu Jul 20 21:56:48 2017
@@ -1323,7 +1323,28 @@ on the command line.
   }];
 }
 
-def MipsCallStyleDocs : Documentation {
+def MipsLongCallStyleDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "long_call (gnu::long_call, gnu::far)";
+  let Content = [{
+Clang supports the ``__attribute__((long_call))``, ``__attribute__((far))``,
+and ``__attribute__((near))`` attributes on MIPS targets. These attributes may
+only be added to function declarations and change the code generated
+by the compiler when directly calling the function. The ``near`` attribute
+allows calls to the function to be made using the ``jal`` instruction, which
+requires the function to be located in the same naturally aligned 256MB
+segment as the caller.  The ``long_call`` and ``far`` attributes are synonyms
+and require the use of a different call sequence that works regardless
+of the distance between the functions.
+
+These attributes have no effect for position-independent code.
+
+These attributes take priority over command line switches such
+as ``-mlong-calls`` and ``-mno-long-calls``.
+  }];
+}
+
+def MipsShortCallStyleDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
 Clang supports the ``__attribute__((long_call))``, ``__attribute__((far))``,


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


[PATCH] D24892: [clang-tidy] Add option "LiteralInitializers" to cppcoreguidelines-pro-type-member-init

2017-07-20 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre updated this revision to Diff 107632.
mgehre marked 3 inline comments as done.
mgehre added a comment.
Herald added subscribers: kbarton, xazax.hun, JDevlieghere.

Implemented all review comments
Use global settings "UseAssignment"


https://reviews.llvm.org/D24892

Files:
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
  test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init-use-assignment.cpp
@@ -0,0 +1,40 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-member-init %t -- -config="{CheckOptions: [{key: "cppcoreguidelines-pro-type-member-init.UseAssignment", value: 1}]}" -- -std=c++11
+
+struct T {
+  int i;
+};
+
+struct S {
+  bool b;
+  // CHECK-FIXES: bool b = false;
+  char c;
+  // CHECK-FIXES: char c = 0;
+  signed char sc;
+  // CHECK-FIXES: signed char sc = 0;
+  unsigned char uc;
+  // CHECK-FIXES: unsigned char uc = 0U;
+  int i;
+  // CHECK-FIXES: int i = 0;
+  unsigned u;
+  // CHECK-FIXES: unsigned u = 0U;
+  long l;
+  // CHECK-FIXES: long l = 0L;
+  unsigned long ul;
+  // CHECK-FIXES: unsigned long ul = 0UL;
+  long long ll;
+  // CHECK-FIXES: long long ll = 0LL;
+  unsigned long long ull;
+  // CHECK-FIXES: unsigned long long ull = 0ULL;
+  float f;
+  // CHECK-FIXES: float f = 0.0F;
+  double d;
+  // CHECK-FIXES: double d = 0.0;
+  long double ld;
+  // CHECK-FIXES: double ld = 0.0L;
+  int *ptr;
+  // CHECK-FIXES: int *ptr = nullptr;
+  T t;
+  // CHECK-FIXES: T t{};
+  S() {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these fields:
+};
Index: docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
===
--- docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
+++ docs/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.rst
@@ -33,6 +33,10 @@
zero-initialized during construction. For performance critical code, it may
be important to not initialize fixed-size array members. Default is `0`.
 
+.. option:: UseAssignment
+   If set to non-zero, the check will provide fix-its with literal initializers
+   (``int i = 0;``) instead of curly braces (``int i{};``).
+
 This rule is part of the "Type safety" profile of the C++ Core
 Guidelines, corresponding to rule Type.6. See
 https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-memberinit.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -58,6 +58,11 @@
 --
 
 The improvements are...
+- Added `UseAssignment` option to `cppcoreguidelines-pro-type-member-init`
+
+  If set to true, the check will provide fix-its with literal initializers
+  (``int i = 0;``) instead of curly braces (``int i{};``).
+
 
 Improvements to include-fixer
 -
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
@@ -65,6 +65,9 @@
 
   // Whether arrays need to be initialized or not. Default is false.
   bool IgnoreArrays;
+  // Whether fix-its for initializers of fundamental type use literals. Only
+  // effective in C++11 mode. Default is false.
+  bool UseAssignment;
 };
 
 } // namespace cppcoreguidelines
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -255,7 +255,8 @@
 ProTypeMemberInitCheck::ProTypeMemberInitCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  IgnoreArrays(Options.get("IgnoreArrays", false)) {}
+  IgnoreArrays(Options.get("IgnoreArrays", false)),
+  UseAssignment(Options.getLocalOrGlobal("UseAssignment", false)) {}
 
 void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus)
@@ -319,6 +320,7 @@
 
 void ProTypeMemberInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IgnoreArrays", IgnoreArrays);
+  Options.store(Opts, "UseAssignment", UseAssignment);
 }
 
 // FIXME: Copied from clang/lib/Sema/SemaDeclCXX.cpp.
@@ -343,6 +345,56 @@
   return isIncompleteOrZeroLengthArrayType(Context, Type);
 }
 
+static const char *getInitializer(QualType QT, bool UseAssignment) {

[PATCH] D31326: Add option to export fixes to run-clang-tidy.py

2017-07-20 Thread Michael F. Herbst via Phabricator via cfe-commits
mfherbst updated this revision to Diff 107633.
mfherbst added a comment.

Remove compatiblity with clang-tidy < 4.0.0


https://reviews.llvm.org/D31326

Files:
  run-clang-tidy.py

Index: run-clang-tidy.py
===
--- run-clang-tidy.py
+++ run-clang-tidy.py
@@ -36,6 +36,7 @@
 
 from __future__ import print_function
 import argparse
+import glob
 import json
 import multiprocessing
 import os
@@ -47,6 +48,7 @@
 import tempfile
 import threading
 import traceback
+import yaml
 
 
 def find_compilation_database(path):
@@ -89,6 +91,31 @@
   return start
 
 
+def merge_replacement_files(tmpdir, mergefile):
+  """Merge all replacement files in a directory into a single file"""
+  # The fixes suggested by clang-tidy >= 4.0.0 are given under
+  # the top level key 'Diagnostics' in the output yaml files
+  mergekey="Diagnostics"
+  merged=[]
+  for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')):
+content = yaml.safe_load(open(replacefile, 'r'))
+if not content:
+  continue # Skip empty files.
+merged.extend(content.get(mergekey, []))
+
+  if merged:
+# MainSourceFile: The key is required by the definition inside
+# include/clang/Tooling/ReplacementsYaml.h, but the value
+# is actually never used inside clang-apply-replacements,
+# so we set it to '' here.
+output = { 'MainSourceFile': '', mergekey: merged }
+with open(mergefile, 'w') as out:
+  yaml.safe_dump(output, out)
+  else:
+# Empty the file:
+open(mergefile, 'w').close()
+
+
 def check_clang_apply_replacements_binary(args):
   """Checks if invoking supplied clang-apply-replacements binary works."""
   try:
@@ -101,7 +128,7 @@
 
 
 def apply_fixes(args, tmpdir):
-  """Calls clang-apply-fixes on a given directory. Deletes the dir when done."""
+  """Calls clang-apply-fixes on a given directory."""
   invocation = [args.clang_apply_replacements_binary]
   if args.format:
 invocation.append('-format')
@@ -143,6 +170,9 @@
   'headers to output diagnostics from. Diagnostics from '
   'the main file of each translation unit are always '
   'displayed.')
+  parser.add_argument('-export-fixes', metavar='filename', dest='export_fixes',
+  help='Create a yaml file to store suggested fixes in, '
+  'which can be applied with clang-apply-replacements.')
   parser.add_argument('-j', type=int, default=0,
   help='number of tidy instances to be run in parallel.')
   parser.add_argument('files', nargs='*', default=['.*'],
@@ -194,7 +224,7 @@
 max_task = multiprocessing.cpu_count()
 
   tmpdir = None
-  if args.fix:
+  if args.fix or args.export_fixes:
 check_clang_apply_replacements_binary(args)
 tmpdir = tempfile.mkdtemp()
 
@@ -222,24 +252,32 @@
 # This is a sad hack. Unfortunately subprocess goes
 # bonkers with ctrl-c and we start forking merrily.
 print('\nCtrl-C detected, goodbye.')
-if args.fix:
+if tmpdir:
   shutil.rmtree(tmpdir)
 os.kill(0, 9)
 
+  return_code = 0
+  if args.export_fixes:
+print('Writing fixes to ' + args.export_fixes + ' ...')
+try:
+  merge_replacement_files(tmpdir, args.export_fixes)
+except:
+  print('Error exporting fixes.\n', file=sys.stderr)
+  traceback.print_exc()
+  return_code=1
+
   if args.fix:
 print('Applying fixes ...')
-successfully_applied = False
-
 try:
   apply_fixes(args, tmpdir)
-  successfully_applied = True
 except:
   print('Error applying fixes.\n', file=sys.stderr)
   traceback.print_exc()
+  return_code=1
 
+  if tmpdir:
 shutil.rmtree(tmpdir)
-if not successfully_applied:
-  sys.exit(1)
+  sys.exit(return_code)
 
 if __name__ == '__main__':
   main()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits