[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-12 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp:21
+AST_MATCHER(GotoStmt, isForwardJumping) {
+  return Node.getLocStart() < Node.getLabel()->getLocStart();
+}

Hm, on a second thought, i think this will have false-positive if the label and 
the goto are on the same line, like
```
goto label; ; label: ; 
```
I wonder we could **easily** compare accounting for the position in the line, 
or it is not worth the extra complexity.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815



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


r322431 - DR126: partially implement the const-correct rules for exception handler matching.

2018-01-12 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Jan 12 21:05:45 2018
New Revision: 322431

URL: http://llvm.org/viewvc/llvm-project?rev=322431=rev
Log:
DR126: partially implement the const-correct rules for exception handler 
matching.

While here, fix up the myriad other ways in which Sema's two "can this handler
catch that exception?" implementations get things wrong and unify them.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
cfe/trunk/test/CXX/drs/dr1xx.cpp
cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
cfe/trunk/www/cxx_dr_status.html

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=322431=322430=322431=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Jan 12 21:05:45 2018
@@ -1459,6 +1459,7 @@ public:
   const PartialDiagnostic , const PartialDiagnostic & NoteID,
   const FunctionProtoType *Old, SourceLocation OldLoc,
   const FunctionProtoType *New, SourceLocation NewLoc);
+  bool handlerCanCatch(QualType HandlerType, QualType ExceptionType);
   bool CheckExceptionSpecSubset(const PartialDiagnostic ,
 const PartialDiagnostic ,
 const PartialDiagnostic ,

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=322431=322430=322431=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Fri Jan 12 21:05:45 2018
@@ -287,48 +287,21 @@ enum ThrowState {
   FoundPathWithNoThrowOutFunction,
 };
 
-static bool isThrowCaught(const CXXThrowExpr *Throw,
-  const CXXCatchStmt *Catch) {
-  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
-  if (!CaughtType)
-return true;
-  const Type *ThrowType = nullptr;
-  if (Throw->getSubExpr())
-ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
-  if (!ThrowType)
-return false;
-  if (ThrowType->isReferenceType())
-ThrowType = ThrowType->castAs()
-->getPointeeType()
-->getUnqualifiedDesugaredType();
-  if (CaughtType->isReferenceType())
-CaughtType = CaughtType->castAs()
- ->getPointeeType()
- ->getUnqualifiedDesugaredType();
-  if (ThrowType->isPointerType() && CaughtType->isPointerType()) {
-ThrowType = ThrowType->getPointeeType()->getUnqualifiedDesugaredType();
-CaughtType = CaughtType->getPointeeType()->getUnqualifiedDesugaredType();
-  }
-  if (CaughtType == ThrowType)
-return true;
-  const CXXRecordDecl *CaughtAsRecordType =
-  CaughtType->getAsCXXRecordDecl();
-  const CXXRecordDecl *ThrowTypeAsRecordType = ThrowType->getAsCXXRecordDecl();
-  if (CaughtAsRecordType && ThrowTypeAsRecordType)
-return ThrowTypeAsRecordType->isDerivedFrom(CaughtAsRecordType);
-  return false;
-}
-
-static bool isThrowCaughtByHandlers(const CXXThrowExpr *CE,
+static bool isThrowCaughtByHandlers(Sema ,
+const CXXThrowExpr *CE,
 const CXXTryStmt *TryStmt) {
   for (unsigned H = 0, E = TryStmt->getNumHandlers(); H < E; ++H) {
-if (isThrowCaught(CE, TryStmt->getHandler(H)))
+QualType Caught = TryStmt->getHandler(H)->getCaughtType();
+if (Caught.isNull() || // catch (...) catches everything
+(CE->getSubExpr() && // throw; is only caught by ...
+ S.handlerCanCatch(Caught, CE->getSubExpr()->getType(
   return true;
   }
   return false;
 }
 
-static bool doesThrowEscapePath(CFGBlock Block, SourceLocation ) {
+static bool doesThrowEscapePath(Sema , CFGBlock Block,
+SourceLocation ) {
   for (const auto  : Block) {
 if (B.getKind() != CFGElement::Statement)
   continue;
@@ -342,7 +315,7 @@ static bool doesThrowEscapePath(CFGBlock
 continue;
   if (const auto *Terminator =
   dyn_cast_or_null(I->getTerminator()))
-if (isThrowCaughtByHandlers(CE, Terminator))
+if (isThrowCaughtByHandlers(S, CE, Terminator))
   return false;
 }
 return true;
@@ -350,8 +323,8 @@ static bool doesThrowEscapePath(CFGBlock
   return false;
 }
 
-static bool hasThrowOutNonThrowingFunc(SourceLocation , CFG *BodyCFG) {
-
+static bool hasThrowOutNonThrowingFunc(Sema , SourceLocation ,
+   CFG *BodyCFG) {
   unsigned ExitID = BodyCFG->getExit().getBlockID();
 
   SmallVector States(BodyCFG->getNumBlockIDs(),
@@ -369,7 +342,7 @@ static bool hasThrowOutNonThrowingFunc(S
   if (ExitID == ID)
 

Re: r321395 - [ODRHash] Support ODR violation detection in functions.

2018-01-12 Thread Eric Fiselier via cfe-commits
Seems to be working now.

Thank you!

On Thu, Jan 11, 2018 at 9:46 PM, Richard Trieu  wrote:

> Hi Vedant and Eric,
>
> Please retry after r322350.  I suspect an interaction between templates
> and friend functions is causing this issue.  This revision disables hashing
> for friend functions for now.
>
> Richard
>
> On Thu, Jan 11, 2018 at 3:34 PM, Eric Fiselier  wrote:
>
>> I'm hitting the same issue as well.
>>
>> Please let me know if there is anything I can do to get this fixed
>> quickly.
>>
>> /Eric
>>
>> On Wed, Jan 3, 2018 at 5:20 PM, Richard Trieu via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Vedant,
>>>
>>> I'm looking into it.
>>>
>>>
>>> On Wed, Jan 3, 2018 at 11:12 AM, Vedant Kumar  wrote:
>>>
 Oops, the build log was too big to attach. Resending with just the bot
 link, then:
 http://lab.llvm.org:8080/green/view/Experimental/job/clang-s
 tage2-coverage-R/2193/consoleText

 vedant

 On Jan 3, 2018, at 11:09 AM, Vedant Kumar  wrote:

 Hi Richard,

 This commit is causing an unexpected build failure in the stage2
 modules-enabled coverage bot. I've attached the build log. Here's the 
 error:

 [3685/3899] 
 /Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/host-compiler/bin/clang++
-DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
 -D__STDC_LIMIT_MACROS -Itools/lld/COFF 
 -I/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF
  
 -I/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/include
  -Itools/lld/include -I/usr/include/libxml2 -Iinclude 
 -I/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include 
 -fPIC -fvisibility-inlines-hidden -Werror=date-time 
 -Werror=unguarded-availability-new -std=c++11 -fmodules 
 -fmodules-cache-path=/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/clang-build/module.cache
  -fcxx-modules -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
 -Wmissing-field-initializers -pedantic -Wno-long-long 
 -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
 -Wstring-conversion -fcolor-diagnostics 
 -fprofile-instr-generate='/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/clang-build/profiles/%6m.profraw'
  -fcoverage-mapping -O3 -DNDEBUG-fno-exceptions -fno-rtti -MMD -MT 
 tools/lld/COFF/CMakeFiles/lldCOFF.dir/PDB.cpp.o -MF 
 tools/lld/COFF/CMakeFiles/lldCOFF.dir/PDB.cpp.o.d -o 
 tools/lld/COFF/CMakeFiles/lldCOFF.dir/PDB.cpp.o -c 
 /Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/PDB.cpp
 FAILED: tools/lld/COFF/CMakeFiles/lldCOFF.dir/PDB.cpp.o
 /Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/host-compiler/bin/clang++
-DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
 -D__STDC_LIMIT_MACROS -Itools/lld/COFF 
 -I/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF
  
 -I/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/include
  -Itools/lld/include -I/usr/include/libxml2 -Iinclude 
 -I/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include 
 -fPIC -fvisibility-inlines-hidden -Werror=date-time 
 -Werror=unguarded-availability-new -std=c++11 -fmodules 
 -fmodules-cache-path=/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/clang-build/module.cache
  -fcxx-modules -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
 -Wmissing-field-initializers -pedantic -Wno-long-long 
 -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor 
 -Wstring-conversion -fcolor-diagnostics 
 -fprofile-instr-generate='/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/clang-build/profiles/%6m.profraw'
  -fcoverage-mapping -O3 -DNDEBUG-fno-exceptions -fno-rtti -MMD -MT 
 tools/lld/COFF/CMakeFiles/lldCOFF.dir/PDB.cpp.o -MF 
 tools/lld/COFF/CMakeFiles/lldCOFF.dir/PDB.cpp.o.d -o 
 tools/lld/COFF/CMakeFiles/lldCOFF.dir/PDB.cpp.o -c 
 /Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/PDB.cpp
 In module 'std' imported from 
 /Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/Config.h:16:
 /Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/host-compiler/include/c++/v1/list:389:10:
  error: 'std::__1::operator==' has different definitions in different 
 modules; definition in module 'std.list' first difference is function body
 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
 ~^~
 

r322396 - Refactor handling of signext/zeroext in ABIArgInfo

2018-01-12 Thread Alex Bradbury via cfe-commits
Author: asb
Date: Fri Jan 12 12:08:16 2018
New Revision: 322396

URL: http://llvm.org/viewvc/llvm-project?rev=322396=rev
Log:
Refactor handling of signext/zeroext in ABIArgInfo

As @rjmccall suggested in D40023, we can get rid of 
ABIInfo::shouldSignExtUnsignedType (used to handle cases like the Mips calling 
convention where 32-bit integers are always sign extended regardless of the 
sign of the type) by adding a SignExt field to ABIArgInfo. In the common case, 
this new field is set automatically by ABIArgInfo::getExtend based on the sign 
of the type. For targets that want greater control, they can use 
ABIArgInfo::getSignExtend or ABIArgInfo::getZeroExtend when necessary. This 
change also cleans up logic in CGCall.cpp.

There is no functional change intended in this patch, and all tests pass 
unchanged. As noted in D40023, Mips might want to sign-extend unsigned 32-bit 
integer return types. A future patch might modify 
MipsABIInfo::classifyReturnType to use MipsABIInfo::extendType.

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

Modified:
cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h
cfe/trunk/lib/CodeGen/ABIInfo.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h?rev=322396=322395=322396=diff
==
--- cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h (original)
+++ cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h Fri Jan 12 12:08:16 2018
@@ -95,6 +95,7 @@ private:
   bool SRetAfterThis : 1;   // isIndirect()
   bool InReg : 1;   // isDirect() || isExtend() || isIndirect()
   bool CanBeFlattened: 1;   // isDirect()
+  bool SignExt : 1; // isExtend()
 
   bool canHavePaddingType() const {
 return isDirect() || isExtend() || isIndirect() || isExpand();
@@ -133,15 +134,38 @@ public:
 AI.setInReg(true);
 return AI;
   }
-  static ABIArgInfo getExtend(llvm::Type *T = nullptr) {
+
+  static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T = nullptr) {
+assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
 auto AI = ABIArgInfo(Extend);
 AI.setCoerceToType(T);
 AI.setPaddingType(nullptr);
 AI.setDirectOffset(0);
+AI.setSignExt(true);
 return AI;
   }
-  static ABIArgInfo getExtendInReg(llvm::Type *T = nullptr) {
-auto AI = getExtend(T);
+
+  static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T = nullptr) {
+assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
+auto AI = ABIArgInfo(Extend);
+AI.setCoerceToType(T);
+AI.setPaddingType(nullptr);
+AI.setDirectOffset(0);
+AI.setSignExt(false);
+return AI;
+  }
+
+  // ABIArgInfo will record the argument as being extended based on the sign
+  // of its type.
+  static ABIArgInfo getExtend(QualType Ty, llvm::Type *T = nullptr) {
+assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
+if (Ty->hasSignedIntegerRepresentation())
+  return getSignExtend(Ty, T);
+return getZeroExtend(Ty, T);
+  }
+
+  static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T = nullptr) {
+auto AI = getExtend(Ty, T);
 AI.setInReg(true);
 return AI;
   }
@@ -254,6 +278,15 @@ public:
 DirectOffset = Offset;
   }
 
+  bool isSignExt() const {
+assert(isExtend() && "Invalid kind!");
+return SignExt;
+  }
+  void setSignExt(bool SExt) {
+assert(isExtend() && "Invalid kind!");
+SignExt = SExt;
+  }
+
   llvm::Type *getPaddingType() const {
 return (canHavePaddingType() ? PaddingType : nullptr);
   }

Modified: cfe/trunk/lib/CodeGen/ABIInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ABIInfo.h?rev=322396=322395=322396=diff
==
--- cfe/trunk/lib/CodeGen/ABIInfo.h (original)
+++ cfe/trunk/lib/CodeGen/ABIInfo.h Fri Jan 12 12:08:16 2018
@@ -108,8 +108,6 @@ namespace swiftcall {
 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
uint64_t Members) const;
 
-virtual bool shouldSignExtUnsignedType(QualType Ty) const;
-
 bool isHomogeneousAggregate(QualType Ty, const Type *,
 uint64_t ) const;
 

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=322396=322395=322396=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Jan 12 12:08:16 2018
@@ -1925,9 +1925,9 @@ void CodeGenModule::ConstructAttributeLi
   const ABIArgInfo  = FI.getReturnInfo();
   switch (RetAI.getKind()) {
   case ABIArgInfo::Extend:
-if (RetTy->hasSignedIntegerRepresentation())
+

[PATCH] D37035: Implement __builtin_LINE() et. al. to support source location capture.

2018-01-12 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 129746.
EricWF added a comment.

- Introduce `SourceLocExprScope.h` to help reduce code duplication.
- Merge with upstream.


https://reviews.llvm.org/D37035

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/SourceLocExprScope.h
  include/clang/AST/Stmt.h
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CodeGenCXX/builtin_FUNCTION.cpp
  test/CodeGenCXX/builtin_LINE.cpp
  test/CodeGenCXX/debug-info-line.cpp
  test/Parser/builtin_source_location.c
  test/Sema/source_location.c
  test/SemaCXX/Inputs/source-location-file.h
  test/SemaCXX/source_location.cpp

Index: test/SemaCXX/source_location.cpp
===
--- /dev/null
+++ test/SemaCXX/source_location.cpp
@@ -0,0 +1,475 @@
+// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// expected-no-diagnostics
+
+#define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
+#define CURRENT_FROM_MACRO() SL::current()
+#define FORWARD(...) __VA_ARGS__
+
+namespace std {
+namespace experimental {
+struct source_location {
+private:
+  unsigned int __m_line = 0;
+  unsigned int __m_col = 0;
+  const char *__m_file = nullptr;
+  const char *__m_func = nullptr;
+public:
+  static constexpr source_location current(
+  const char *__file = __builtin_FILE(),
+  const char *__func = __builtin_FUNCTION(),
+  unsigned int __line = __builtin_LINE(),
+  unsigned int __col = __builtin_COLUMN()) noexcept {
+source_location __loc;
+__loc.__m_line = __line;
+__loc.__m_col = __col;
+__loc.__m_file = __file;
+__loc.__m_func = __func;
+return __loc;
+  }
+  constexpr source_location() = default;
+  constexpr source_location(source_location const &) = default;
+  constexpr unsigned int line() const noexcept { return __m_line; }
+  constexpr unsigned int column() const noexcept { return __m_col; }
+  constexpr const char *file() const noexcept { return __m_file; }
+  constexpr const char *function() const noexcept { return __m_func; }
+};
+} // namespace experimental
+} // namespace std
+
+using SL = std::experimental::source_location;
+
+#include "Inputs/source-location-file.h"
+namespace SLF = source_location_file;
+
+constexpr bool is_equal(const char *LHS, const char *RHS) {
+  while (*LHS != 0 && *RHS != 0) {
+if (*LHS != *RHS)
+  return false;
+++LHS;
+++RHS;
+  }
+  return *LHS == 0 && *RHS == 0;
+}
+
+template 
+constexpr T identity(T t) {
+  return t;
+}
+
+template 
+struct Pair {
+  T first;
+  U second;
+};
+
+template 
+constexpr bool is_same = false;
+template 
+constexpr bool is_same = true;
+
+// test types
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+
+// test noexcept
+static_assert(noexcept(__builtin_LINE()));
+static_assert(noexcept(__builtin_COLUMN()));
+static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FUNCTION()));
+
+//===--===//
+//__builtin_LINE()
+//===--===//
+
+namespace test_line {
+
+static_assert(SL::current().line() == __LINE__);
+static_assert(SL::current().line() == CURRENT_FROM_MACRO().line());
+
+static constexpr SL GlobalS = SL::current();
+
+static_assert(GlobalS.line() == __LINE__ - 2);
+
+// clang-format off
+constexpr bool test_line_fn() {
+  constexpr SL S = SL::current();
+  static_assert(S.line() == (__LINE__ - 1), "");
+  // The start of the call expression to `current()` begins at the token `SL`
+  constexpr int ExpectLine = __LINE__ + 3;
+  constexpr SL S2
+  =
+  SL // Call expression starts here
+  ::
+  current
+  (
+
+  )
+  ;
+  static_assert(S2.line() == ExpectLine, "");
+
+  static_assert(
+  FORWARD(
+ __builtin_LINE
+(
+)
+  )
+== __LINE__ - 1, "");
+  static_assert(\
+\
+  __builtin_LINE()\
+\
+  

[PATCH] D42014: Disable BinPackArguments and BinPackParameters in Google Objective-C style ⚙️

2018-01-12 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added a comment.

I am still working to verify that this change represents actual consensus. I 
will hold off on adding reviewers until then.


https://reviews.llvm.org/D42014



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


[PATCH] D41977: [libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.

2018-01-12 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 129744.
EricWF added a comment.

- Address @rsmith's comments by removing the fallback implementation of the 
diagnostics.


https://reviews.llvm.org/D41977

Files:
  include/tuple
  test/libcxx/utilities/tuple/tuple.tuple/diagnose_reference_binding.fail.cpp
  test/libcxx/utilities/tuple/tuple.tuple/diagnose_reference_binding.pass.cpp
  
test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp
  
test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp

Index: test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
===
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
@@ -0,0 +1,136 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+// 
+
+// See llvm.org/PR20855
+
+#include 
+#include 
+#include "test_macros.h"
+
+#if TEST_HAS_BUILTIN_IDENTIFIER(__reference_binds_to_temporary)
+# define ASSERT_REFERENCE_BINDS_TEMPORARY(...) static_assert(__reference_binds_to_temporary(__VA_ARGS__), "")
+# define ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(...) static_assert(!__reference_binds_to_temporary(__VA_ARGS__), "")
+#else
+# define ASSERT_REFERENCE_BINDS_TEMPORARY(...) static_assert(true, "")
+# define ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(...) static_assert(true, "")
+#endif
+
+template 
+struct ConvertsTo {
+  using RawTp = typename std::remove_cv< typename std::remove_reference::type>::type;
+
+  operator Tp() const {
+return static_cast(value);
+  }
+
+  mutable RawTp value;
+};
+
+struct Base {};
+struct Derived : Base {};
+
+
+static_assert(std::is_same::value, "");
+ASSERT_REFERENCE_BINDS_TEMPORARY(std::string const&, decltype("abc"));
+ASSERT_REFERENCE_BINDS_TEMPORARY(std::string const&, decltype(("abc")));
+ASSERT_REFERENCE_BINDS_TEMPORARY(std::string const&, const char*&&);
+
+ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(int&, const ConvertsTo&);
+ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(const int&, ConvertsTo&);
+ASSERT_NOT_REFERENCE_BINDS_TEMPORARY(Base&, Derived&);
+
+
+static_assert(std::is_constructible::value, "");
+static_assert(std::is_constructible>::value, "");
+
+template  struct CannotDeduce {
+ using type = T;
+};
+
+template 
+void F(typename CannotDeduce::type const&) {}
+
+void compile_tests() {
+  {
+F(std::make_tuple(42, 42));
+  }
+  {
+F(std::make_tuple(42, 42));
+std::tuple t(std::make_tuple(42, 42));
+  }
+  {
+auto fn = ;
+fn(std::tuple(42, std::string("a")));
+fn(std::make_tuple(42, std::string("a")));
+  }
+  {
+Derived d;
+std::tuple t(d, d);
+  }
+  {
+ConvertsTo ct;
+std::tuple t(42, ct);
+  }
+}
+
+void allocator_tests() {
+std::allocator alloc;
+int x = 42;
+{
+std::tuple t(std::ref(x));
+assert(::get<0>(t) == );
+std::tuple t1(std::allocator_arg, alloc, std::ref(x));
+assert(::get<0>(t1) == );
+}
+{
+auto r = std::ref(x);
+auto const& cr = r;
+std::tuple t(r);
+assert(::get<0>(t) == );
+std::tuple t1(cr);
+assert(::get<0>(t1) == );
+std::tuple t2(std::allocator_arg, alloc, r);
+assert(::get<0>(t2) == );
+std::tuple t3(std::allocator_arg, alloc, cr);
+assert(::get<0>(t3) == );
+}
+{
+std::tuple t(std::ref(x));
+assert(::get<0>(t) == );
+std::tuple t2(std::cref(x));
+assert(::get<0>(t2) == );
+std::tuple t3(std::allocator_arg, alloc, std::ref(x));
+assert(::get<0>(t3) == );
+std::tuple t4(std::allocator_arg, alloc, std::cref(x));
+assert(::get<0>(t4) == );
+}
+{
+auto r = std::ref(x);
+auto cr = std::cref(x);
+std::tuple t(r);
+assert(::get<0>(t) == );
+std::tuple t2(cr);
+assert(::get<0>(t2) == );
+std::tuple t3(std::allocator_arg, alloc, r);
+assert(::get<0>(t3) == );
+std::tuple t4(std::allocator_arg, alloc, cr);
+assert(::get<0>(t4) == );
+}
+}
+
+
+int main() {
+  compile_tests();
+  allocator_tests();
+}
Index: test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp

[PATCH] D41816: [analyzer] Model and check unrepresentable left shifts

2018-01-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

The diagnostic text looks to me, but I do have a comment about the nested 'if' 
inline.




Comment at: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp:150
+SB.getKnownValue(state, C.getSVal(B->getRHS()));
+if ((unsigned) RHS->getZExtValue() > LHS->countLeadingZeros()) {
+  OS << "The result of the left shift is undefined due to shifting \'"

This inner 'if' looks fishy to me because if the 'else' branch is ever taken 
then OS will be empty.

If the else branch can't be taken then you should turn it into an assert(). If 
it can be taken, then you should make sure that the fall through goes through 
the "default" else case at the bottom. One way to do this is to pull out the 
"is representable logic" into a helper function and call that in the containing 
'else if'.

Something like:

```
if (B->getOpcode() == BinaryOperatorKind::BO_Shl && 
isLeftShiftResultRepresentable(LHS, RHS)) {
  OS << "The result of the left shift ..."
}
```


https://reviews.llvm.org/D41816



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


[PATCH] D41977: [libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.

2018-01-12 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

In https://reviews.llvm.org/D41977#975403, @rsmith wrote:

> This will still diagnose valid and reasonable programs, such as:
>
>   struct ConvertToRef { operator int&(); };
>   std::tuple t = {ConvertToRef()};
>
>
> ... on compilers that don't provide the trait. You could maybe try to work 
> around that by checking to see if the type has a member `.operator int&()`. 
> But perhaps it's better to remove the non-conforming check entirely, at least 
> in the case where you can't reasonably get it right.


I agree with both your comments. I'll remove the non-conforming check.


https://reviews.llvm.org/D41977



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


[PATCH] D42015: [analyzer] NFC: RetainCount: Don't dump() regions to the user.

2018-01-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks for fixing this.


Repository:
  rC Clang

https://reviews.llvm.org/D42015



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


[PATCH] D41881: [analyzer] Flag bcmp, bcopy and bzero as obsolete

2018-01-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Thanks for adding these! This looks good to me. Do you have commit access, or 
do you need someone to commit this?


Repository:
  rC Clang

https://reviews.llvm.org/D41881



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


[PATCH] D40218: [Clang] Add __builtin_launder

2018-01-12 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 129742.
EricWF added a comment.

- Improve diagnostic handling.


https://reviews.llvm.org/D40218

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins.c
  test/CodeGenCXX/builtin-launder.cpp
  test/Preprocessor/feature_tests.c
  test/Sema/builtins.c
  test/SemaCXX/builtins.cpp

Index: test/SemaCXX/builtins.cpp
===
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -53,3 +53,71 @@
 void synchronize_args() {
   __sync_synchronize(0); // expected-error {{too many arguments}}
 }
+
+namespace test_launder {
+
+struct Dummy {};
+
+using FnType = int(char);
+using MemFnType = int (Dummy::*)(char);
+using ConstMemFnType = int (Dummy::*)() const;
+
+void foo() {}
+
+void test_builtin_launder_diags(void *vp, const void *cvp, FnType *fnp,
+MemFnType mfp, ConstMemFnType cmfp) {
+  __builtin_launder(vp);   // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cvp);  // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(fnp);  // expected-error {{function pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(mfp);  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cmfp); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  (void)__builtin_launder();
+  __builtin_launder(42);  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(nullptr); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(foo)  // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+}
+
+void test_builtin_launder(char *p, const volatile int *ip, const float *,
+  double *__restrict dp) {
+  int x;
+  __builtin_launder(x); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+#define TEST_TYPE(Ptr, Type) \
+  static_assert(__is_same(decltype(__builtin_launder(Ptr)), Type), "expected same type")
+  TEST_TYPE(p, char*);
+  TEST_TYPE(ip, const volatile int*);
+  TEST_TYPE(fp, const float*);
+  TEST_TYPE(dp, double *__restrict);
+#undef TEST_TYPE
+  char *d = __builtin_launder(p);
+  const volatile int *id = __builtin_launder(ip);
+  int *id2 = __builtin_launder(ip); // expected-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'const volatile int *'}}
+  const float* fd = __builtin_launder(fp);
+}
+
+template 
+constexpr Tp *test_constexpr_launder(Tp *tp) {
+  return __builtin_launder(tp);
+}
+constexpr int const_int = 42;
+constexpr int const_int2 = 101;
+constexpr const int *const_ptr = test_constexpr_launder(_int);
+static_assert(_int == const_ptr, "");
+static_assert(const_ptr != test_constexpr_launder(_int2), "");
+
+void test_non_constexpr() {
+  constexpr int i = 42;// expected-note {{declared here}}
+  constexpr const int *ip = __builtin_launder(); // expected-error {{constexpr variable 'ip' must be initialized by a constant expression}}
+  // expected-note@-1 {{pointer to 'i' is not a constant expression}}
+}
+
+constexpr bool test_in_constexpr(const int ) {
+  return (__builtin_launder() == );
+}
+static_assert(test_in_constexpr(const_int), "");
+void f() {
+  constexpr int i = 42;
+  // FIXME: Should this work? Since `` doesn't.
+  static_assert(test_in_constexpr(i), "");
+}
+
+} // end namespace test_launder
Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -248,3 +248,21 @@
 
 return buf;
 }
+
+typedef void (fn_t)(int);
+
+void test_builtin_launder(char *p, void *vp, const void *cvp,
+  const volatile int *ip, float *restrict fp,
+  fn_t *fn) {
+  __builtin_launder(); // expected-error {{too few arguments to function call, expected 1, have 0}}
+  __builtin_launder(p, p); // expected-error {{too many arguments to function call, expected 1, have 2}}
+  int x;
+  __builtin_launder(x); // expected-error {{non-pointer argument to '__builtin_launder' is not allowed}}
+  char *d = __builtin_launder(p);
+  __builtin_launder(vp);  // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  __builtin_launder(cvp); // expected-error {{void pointer argument to '__builtin_launder' is not allowed}}
+  const volatile int *id = __builtin_launder(ip);
+  int *id2 = __builtin_launder(ip); // expected-warning {{discards qualifiers}}
+  float *fd = __builtin_launder(fp);
+  __builtin_launder(fn); // expected-error {{function pointer argument to '__builtin_launder' is not 

[PATCH] D40218: [Clang] Add __builtin_launder

2018-01-12 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 129740.
EricWF marked an inline comment as done.
EricWF added a comment.

- Address inline comments about missing diagnostics for void pointers and 
function pointers.
- Address inline comments about only enabling when `-fstrict-vtable-pointers` 
is specified, and only on types with vtables.


https://reviews.llvm.org/D40218

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtins.c
  test/CodeGenCXX/builtin-launder.cpp
  test/Preprocessor/feature_tests.c
  test/Sema/builtins.c
  test/SemaCXX/builtins.cpp

Index: test/SemaCXX/builtins.cpp
===
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -53,3 +53,71 @@
 void synchronize_args() {
   __sync_synchronize(0); // expected-error {{too many arguments}}
 }
+
+namespace test_launder {
+
+struct Dummy {};
+
+using FnType = int(char);
+using MemFnType = int (Dummy::*)(char);
+using ConstMemFnType = int (Dummy::*)() const;
+
+void foo() {}
+
+void test_builtin_launder_diags(void *vp, const void *cvp, FnType *fnp,
+MemFnType mfp, ConstMemFnType cmfp) {
+  __builtin_launder(vp);   // expected-error {{argument to '__builtin_launder' cannot be a void pointer}}
+  __builtin_launder(cvp);  // expected-error {{argument to '__builtin_launder' cannot be a void pointer}}
+  __builtin_launder(fnp);  // expected-error {{argument to '__builtin_launder' cannot be a function pointer}}
+  __builtin_launder(mfp);  // expected-error {{non-pointer argument to '__builtin_launder'}}
+  __builtin_launder(cmfp); // expected-error {{non-pointer argument to '__builtin_launder'}}
+  (void)__builtin_launder();
+  __builtin_launder(42);  // expected-error {{non-pointer argument to '__builtin_launder'}}
+  __builtin_launder(nullptr); // expected-error {{non-pointer argument to '__builtin_launder'}}
+  __builtin_launder(foo) // expected-error {{non-pointer argument to '__builtin_launder'}}
+}
+
+void test_builtin_launder(char *p, const volatile int *ip, const float *,
+  double *__restrict dp) {
+  int x;
+  __builtin_launder(x); // expected-error {{non-pointer argument to '__builtin_launder'}}
+#define TEST_TYPE(Ptr, Type) \
+  static_assert(__is_same(decltype(__builtin_launder(Ptr)), Type), "expected same type")
+  TEST_TYPE(p, char*);
+  TEST_TYPE(ip, const volatile int*);
+  TEST_TYPE(fp, const float*);
+  TEST_TYPE(dp, double *__restrict);
+#undef TEST_TYPE
+  char *d = __builtin_launder(p);
+  const volatile int *id = __builtin_launder(ip);
+  int *id2 = __builtin_launder(ip); // expected-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'const volatile int *'}}
+  const float* fd = __builtin_launder(fp);
+}
+
+template 
+constexpr Tp *test_constexpr_launder(Tp *tp) {
+  return __builtin_launder(tp);
+}
+constexpr int const_int = 42;
+constexpr int const_int2 = 101;
+constexpr const int *const_ptr = test_constexpr_launder(_int);
+static_assert(_int == const_ptr, "");
+static_assert(const_ptr != test_constexpr_launder(_int2), "");
+
+void test_non_constexpr() {
+  constexpr int i = 42;// expected-note {{declared here}}
+  constexpr const int *ip = __builtin_launder(); // expected-error {{constexpr variable 'ip' must be initialized by a constant expression}}
+  // expected-note@-1 {{pointer to 'i' is not a constant expression}}
+}
+
+constexpr bool test_in_constexpr(const int ) {
+  return (__builtin_launder() == );
+}
+static_assert(test_in_constexpr(const_int), "");
+void f() {
+  constexpr int i = 42;
+  // FIXME: Should this work? Since `` doesn't.
+  static_assert(test_in_constexpr(i), "");
+}
+
+} // end namespace test_launder
Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -248,3 +248,21 @@
 
 return buf;
 }
+
+typedef void (fn_t)(int);
+
+void test_builtin_launder(char *p, void *vp, const void *cvp,
+  const volatile int *ip, float *restrict fp,
+  fn_t *fn) {
+  __builtin_launder(); // expected-error {{too few arguments to function call, expected 1, have 0}}
+  __builtin_launder(p, p); // expected-error {{too many arguments to function call, expected 1, have 2}}
+  int x;
+  __builtin_launder(x); // expected-error {{non-pointer argument to '__builtin_launder'}}
+  char *d = __builtin_launder(p);
+  __builtin_launder(vp); // expected-error {{argument to '__builtin_launder' cannot be a void pointer}}
+  __builtin_launder(cvp); // expected-error {{argument to '__builtin_launder' cannot be a void pointer}}
+  const volatile int *id = __builtin_launder(ip);
+  int *id2 = __builtin_launder(ip); // expected-warning {{discards qualifiers}}
+  float *fd = __builtin_launder(fp);
+ 

[PATCH] D40218: [Clang] Add __builtin_launder

2018-01-12 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked 2 inline comments as done.
EricWF added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:1674
+Value *Ptr = EmitScalarExpr(E->getArg(0));
+Ptr = Builder.CreateInvariantGroupBarrier(Ptr);
+return RValue::get(Ptr);

rsmith wrote:
> It would be nice to avoid this for types that contain no const subobjects / 
> reference subobjects / vptrs. I think we can also omit this entirely if 
> `-fstrict-vtable-ptrs` is disabled, since in that case we don't generate any 
> `invariant.group` metadata.
> 
> I'd be OK with the former being left to a future change, but the latter 
> should be part of this change so we don't generate unnecessarily-inefficient 
> code in the default mode for uses of `std::launder`.
I'll put it in this change set.


https://reviews.llvm.org/D40218



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


[PATCH] D41797: [analyzer] Suppress escape of this-pointer during construction.

2018-01-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D41797



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


[PATCH] D41934: [analyzer] Fix CXXNewExpr callback order.

2018-01-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Looks great. It is nice to have this fixed and cleaned up!




Comment at: lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp:95
+  llvm::errs() << "PreCall";
+  if (const NamedDecl *ND = dyn_cast_or_null(Call.getDecl()))
+llvm::errs() << " (" << ND->getQualifiedNameAsString() << ')';

Style nit: use auto for the casts.


Repository:
  rC Clang

https://reviews.llvm.org/D41934



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


[PATCH] D41266: [analyzer] With c++-allocator-inlining, fix memory space for operator new pointers.

2018-01-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.

LGTM as well.


https://reviews.llvm.org/D41266



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


[PATCH] D42019: [Driver] Set default sysroot for Fuchsia if none is specified

2018-01-12 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr added inline comments.



Comment at: lib/Driver/ToolChains/Fuchsia.cpp:152
+  llvm::sys::path::append(P, normalizeTriple(Triple));
+  return P.str();
+}

The GCC behavior (if --with-sysroot is given to configure) is tooldir/sys-root, 
not tooldir itself.


Repository:
  rC Clang

https://reviews.llvm.org/D42019



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


[PATCH] D41250: [analyzer] Model implied cast around operator new().

2018-01-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.

This looks good to me, as well.


https://reviews.llvm.org/D41250



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


[PATCH] D40560: [analyzer] Get construction into `operator new` running in simple cases.

2018-01-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

LGTM with the TODO and the test case I requested inline.




Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:487
+if (const MemRegion *MR = I.second.getAsRegion())
+  SymReaper.markElementIndicesLive(MR);
+  }

Do we have a test for the MemRegion case? Commenting it out doesn't seem to 
affect the tests.



Comment at: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp:607
+const CXXConstructExpr *CtorExpr = Ctor.getOriginExpr();
+const Stmt *ParentExpr = CurLC->getParentMap().getParent(CtorExpr);
+

Can you add a TODO saying that we really shouldn't be using the parent map 
here? That is fragile and is a sign we're not providing enough context.



https://reviews.llvm.org/D40560



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


r322427 - Remove unused addIfPresent function.

2018-01-12 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Fri Jan 12 16:46:47 2018
New Revision: 322427

URL: http://llvm.org/viewvc/llvm-project?rev=322427=rev
Log:
Remove unused addIfPresent function.

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

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=322427=322426=322427=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Fri Jan 12 16:46:47 2018
@@ -4179,10 +4179,6 @@ void FragileHazards::emitHazardsInNewBlo
   }
 }
 
-static void addIfPresent(llvm::DenseSet , llvm::Value *V) {
-  if (V) S.insert(V);
-}
-
 static void addIfPresent(llvm::DenseSet , Address V) {
   if (V.isValid()) S.insert(V.getPointer());
 }


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


[PATCH] D39963: [RISCV] Add initial RISC-V target and driver support

2018-01-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.
Herald added a subscriber: niosHD.

This has broken our toolchain build, the log is here: 
https://logs.chromium.org/v/?s=fuchsia%2Fbuildbucket%2Fcr-buildbucket.appspot.com%2F8957686819564148864%2F%2B%2Fsteps%2Fcheck_clang%2F0%2Fstdout.
 The failure is:

   TEST 'Clang :: Driver/riscv32-toolchain.c' FAILED 

  Script:
  --
  /b/s/w/ir/tmp/rt/clangM7g4Ie/llvm_build_dir/tools/clang/stage2-bins/bin/clang 
/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/riscv32-toolchain.c 
-### -no-canonical-prefixes -target riscv32 2>&1 | 
/b/s/w/ir/tmp/rt/clangM7g4Ie/llvm_build_dir/tools/clang/stage2-bins/bin/FileCheck
 -check-prefix=CC1 
/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/riscv32-toolchain.c
  /b/s/w/ir/tmp/rt/clangM7g4Ie/llvm_build_dir/tools/clang/stage2-bins/bin/clang 
/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/riscv32-toolchain.c 
-### -no-canonical-prefixes-target riscv32-linux-unknown-elf
--gcc-toolchain=/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk

--sysroot=/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/sysroot
 2>&1| 
/b/s/w/ir/tmp/rt/clangM7g4Ie/llvm_build_dir/tools/clang/stage2-bins/bin/FileCheck
 -check-prefix=CC1-RV32-LINUX-ILP32 
/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/riscv32-toolchain.c
  /b/s/w/ir/tmp/rt/clangM7g4Ie/llvm_build_dir/tools/clang/stage2-bins/bin/clang 
/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/riscv32-toolchain.c 
-### -no-canonical-prefixes-target riscv32-linux-unknown-elf 
-march=rv32imafd -mabi=ilp32d
--gcc-toolchain=/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk

--sysroot=/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/sysroot
 2>&1| 
/b/s/w/ir/tmp/rt/clangM7g4Ie/llvm_build_dir/tools/clang/stage2-bins/bin/FileCheck
 -check-prefix=CC1-RV32-LINUX-ILP32D 
/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/riscv32-toolchain.c
  /b/s/w/ir/tmp/rt/clangM7g4Ie/llvm_build_dir/tools/clang/stage2-bins/bin/clang 
-target riscv32 
/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/riscv32-toolchain.c 
-emit-llvm -S -o - | 
/b/s/w/ir/tmp/rt/clangM7g4Ie/llvm_build_dir/tools/clang/stage2-bins/bin/FileCheck
 /b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/riscv32-toolchain.c
  --
  Exit Code: 1
  Command Output (stderr):
  --
  
/b/s/w/ir/kitchen-workdir/llvm-project/clang/test/Driver/riscv32-toolchain.c:13:26:
 error: expected string not found in input
  // CC1-RV32-LINUX-ILP32: 
"{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}ld"
   ^
  :1:1: note: scanning from here
  Fuchsia clang version 7.0.0 
(https://fuchsia.googlesource.com/a/third_party/clang 
6d538af698b9b96bc18bfbe62173dca1c103aaca) 
(https://fuchsia.googlesource.com/a/third_party/llvm 
0b5677cbf87647986caf9fa818adb7f8c355cf1f) (based on LLVM 7.0.0svn)
  ^
  --

I think the problem is that in our toolchain, we configure LLD as the default 
linker which is why that check is failing.


Repository:
  rC Clang

https://reviews.llvm.org/D39963



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


[PATCH] D41820: [coroutines] Pass coro func args to promise ctor

2018-01-12 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov added a comment.

In https://reviews.llvm.org/D41820#974116, @EricWF wrote:

> Is this behavior specified somewhere? Or are we simply adding an extension to 
> Clang? If so I would really prefer to add my `co_promise` solution (but I 
> need to write a paper in favor of it first).


Before bringing the language change proposal, it makes sense to implement the 
feature and test it out on real examples.  MSVC compiler implemented a number 
of coroutine features to do sanity testing and put in the customers hands 
before a feature was proposed.

Since this is a non-breaking change, I think it makes sense to put it in and 
play with it. This particular approach was talked about since 2014, but, no 
formal proposal was made. I am bringing the paper to upcoming Jacksonville 
meeting and would like to make sure that we have both implementation and usage 
experience for the feature.


Repository:
  rC Clang

https://reviews.llvm.org/D41820



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


[PATCH] D41977: [libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.

2018-01-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

This will still diagnose valid and reasonable programs, such as:

  struct ConvertToRef { operator int&(); };
  std::tuple t = {ConvertToRef()};

... on compilers that don't provide the trait. You could maybe try to work 
around that by checking to see if the type has a member `.operator int&()`. But 
perhaps it's better to remove the non-conforming check entirely, at least in 
the case where you can't reasonably get it right.


https://reviews.llvm.org/D41977



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


[PATCH] D41977: [libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.

2018-01-12 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/tuple:185-186
+// Allow "int&&" to bind to 'int const&'
+||  (is_rvalue_reference<_Tp>::value && is_const<_RawHp>::value &&
+is_same<_RawHp, const _RawTp>::value)
 >;

It would be reasonable to consider `is_base_of` here too.



Comment at: include/tuple:190
 || (is_lvalue_reference<_Hp>::value && _CheckLValueArg::value)
 || (is_rvalue_reference<_Hp>::value && 
!is_lvalue_reference<_Tp>::value);
+#else

This line looks wrong to me. This disallows an rvalue reference tuple member 
from binding to an rvalue reference argument, no? Can you
```
return !is_reference<_Hp>::value || (is_reference<_Tp>::value && 
is_convertible<_RawTp*, _RawHp*>::value) || (reference wrapper special case);
```
instead? That should at least only reject valid code in cases where `_RawTp` is 
a class type that converts to a reference type.


https://reviews.llvm.org/D41977



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


[PATCH] D42017: Link sanitized programs on NetBSD with -lkvm

2018-01-12 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski created this revision.
krytarowski added reviewers: joerg, vitalybuka, dvyukov.
krytarowski added a project: Sanitizers.
Herald added a subscriber: llvm-commits.

kvm - kernel memory interface

This set of functions is defined in the libkvm library.

The kvm(3) functions are used in programs that can request information
transparently either from alive kernel or a dead one. This library is used
in the NetBSD userland programs like ps(1), w(1) or who(1).

Inteceptors for the kvm(3) functions require programs linked with -lkvm,
even if they don't use the features as we leak dlerror(3) for unknown
symbols.

Sponsored by 


Repository:
  rL LLVM

https://reviews.llvm.org/D42017

Files:
  lib/Driver/ToolChains/CommonArgs.cpp


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -555,6 +555,9 @@
   // Required for backtrace on some OSes
   if (TC.getTriple().getOS() == llvm::Triple::NetBSD)
 CmdArgs.push_back("-lexecinfo");
+  // Required for kvm (kernel memory interface) on some OSes
+  if (TC.getTriple().getOS() == llvm::Triple::NetBSD)
+CmdArgs.push_back("-lkvm");
 }
 
 static void


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -555,6 +555,9 @@
   // Required for backtrace on some OSes
   if (TC.getTriple().getOS() == llvm::Triple::NetBSD)
 CmdArgs.push_back("-lexecinfo");
+  // Required for kvm (kernel memory interface) on some OSes
+  if (TC.getTriple().getOS() == llvm::Triple::NetBSD)
+CmdArgs.push_back("-lkvm");
 }
 
 static void
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42015: [analyzer] NFC: RetainCount: Don't dump() regions to the user.

2018-01-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, george.karpenkov.
Herald added subscribers: cfe-commits, a.sidorin, szepet, xazax.hun.

`RetainCountChecker` appears to be using `MemRegion::getString()` to present 
the region to the user, which is equivalent to `MemRegion->dump()` and as such 
may produce human-unreadable dumps.

Fortunately, for now `RetainCountChecker` only tracks pointer bindings through 
local variables, and treats all other bindings as pointer escapes. For local 
variables, this worked well.

Before r315736/https://reviews.llvm.org/D38877, however, it used to be possible 
to modify retain count of a pointer "in place" after writing it anywhere, eg.:

  anyWeirdLocation = x;
  SafeCFRetain(anyWeirdLocation);

...which not only caused a leak false positive, but also triggered a dump of 
`anyWeirdLocation` (which may be literally any weird location) into the 
checker's warning message.

So for now i'm not seeing any other cases where this leaks, but i still want to 
add an assertion to make sure this never happens again.


Repository:
  rC Clang

https://reviews.llvm.org/D42015

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1929,6 +1929,12 @@
  isa(E);
 }
 
+static std::string describeRegion(const MemRegion *MR) {
+  // Once we support more storage locations for bindings,
+  // this would need to be improved.
+  return cast(MR)->getDecl()->getName();
+}
+
 /// Returns true if this stack frame is for an Objective-C method that is a
 /// property getter or setter whose body has been synthesized by the analyzer.
 static bool isSynthesizedAccessor(const StackFrameContext *SFC) {
@@ -2395,7 +2401,7 @@
 
   if (FirstBinding) {
 os << "object allocated and stored into '"
-   << FirstBinding->getString() << '\'';
+   << describeRegion(FirstBinding) << '\'';
   }
   else
 os << "allocated object";
@@ -2523,7 +2529,7 @@
   os << "of an object";
 
   if (AllocBinding) {
-os << " stored into '" << AllocBinding->getString() << '\'';
+os << " stored into '" << describeRegion(AllocBinding) << '\'';
 if (IncludeAllocationLine) {
   FullSourceLoc SL(AllocStmt->getLocStart(), Ctx.getSourceManager());
   os << " (allocated on line " << SL.getSpellingLineNumber() << ")";


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1929,6 +1929,12 @@
  isa(E);
 }
 
+static std::string describeRegion(const MemRegion *MR) {
+  // Once we support more storage locations for bindings,
+  // this would need to be improved.
+  return cast(MR)->getDecl()->getName();
+}
+
 /// Returns true if this stack frame is for an Objective-C method that is a
 /// property getter or setter whose body has been synthesized by the analyzer.
 static bool isSynthesizedAccessor(const StackFrameContext *SFC) {
@@ -2395,7 +2401,7 @@
 
   if (FirstBinding) {
 os << "object allocated and stored into '"
-   << FirstBinding->getString() << '\'';
+   << describeRegion(FirstBinding) << '\'';
   }
   else
 os << "allocated object";
@@ -2523,7 +2529,7 @@
   os << "of an object";
 
   if (AllocBinding) {
-os << " stored into '" << AllocBinding->getString() << '\'';
+os << " stored into '" << describeRegion(AllocBinding) << '\'';
 if (IncludeAllocationLine) {
   FullSourceLoc SL(AllocStmt->getLocStart(), Ctx.getSourceManager());
   os << " (allocated on line " << SL.getSpellingLineNumber() << ")";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42014: Disable BinPackArguments and BinPackParameters in Google Objective-C style ⚙️

2018-01-12 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore updated this revision to Diff 129718.
stephanemoore added a comment.

Sorted the Objective-C configuration for consistency.


https://reviews.llvm.org/D42014

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -731,6 +731,8 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
 GoogleStyle.SpacesInContainerLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
+GoogleStyle.BinPackArguments = false;
+GoogleStyle.BinPackParameters = false;
 GoogleStyle.ColumnLimit = 100;
   }
 


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -731,6 +731,8 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
 GoogleStyle.SpacesInContainerLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
+GoogleStyle.BinPackArguments = false;
+GoogleStyle.BinPackParameters = false;
 GoogleStyle.ColumnLimit = 100;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42014: Disable BinPackArguments and BinPackParameters in Google Objective-C style ⚙️

2018-01-12 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore created this revision.
Herald added subscribers: cfe-commits, klimek.

Defaulting BinPackArguments and BinPackParameters to false is a better 
representation of Google Objective-C style.


Repository:
  rC Clang

https://reviews.llvm.org/D42014

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -732,6 +732,8 @@
 GoogleStyle.SpacesInContainerLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.ColumnLimit = 100;
+GoogleStyle.BinPackArguments = false;
+GoogleStyle.BinPackParameters = false;
   }
 
   return GoogleStyle;


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -732,6 +732,8 @@
 GoogleStyle.SpacesInContainerLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.ColumnLimit = 100;
+GoogleStyle.BinPackArguments = false;
+GoogleStyle.BinPackParameters = false;
   }
 
   return GoogleStyle;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322420 - Try to suppress Windows testing again.

2018-01-12 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Fri Jan 12 15:13:33 2018
New Revision: 322420

URL: http://llvm.org/viewvc/llvm-project?rev=322420=rev
Log:
Try to suppress Windows testing again.

Modified:
cfe/trunk/test/Modules/odr_hash-Friend.cpp

Modified: cfe/trunk/test/Modules/odr_hash-Friend.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash-Friend.cpp?rev=322420=322419=322420=diff
==
--- cfe/trunk/test/Modules/odr_hash-Friend.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash-Friend.cpp Fri Jan 12 15:13:33 2018
@@ -8,7 +8,7 @@
 // RUN:  -fmodules-cache-path=%t/modules.cache \
 // RUN:  -std=c++11 -x c++ %s -verify
 
-// UNSUPPORTED: windows
+// UNSUPPORTED: system-windows
 
 // expected-no-diagnostics
 


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


[PATCH] D41458: [libc++][C++17] Elementary string conversions for integral types

2018-01-12 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 129714.
lichray added a comment.

src/support/itoa/itoa.cpp in previous diffs were copyrighted by Tencent, now 
LLVM, contributed by the same author.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41458

Files:
  .gitignore
  include/charconv
  include/support/itoa/
  include/support/itoa/itoa.h
  lib/CMakeLists.txt
  src/support/itoa/
  src/support/itoa/itoa.cpp
  test/std/utilities/charconv/
  test/std/utilities/charconv/charconv.from.chars/
  test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp
  test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
  test/std/utilities/charconv/charconv.to.chars/
  test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp
  test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp
  test/support/charconv_test_helpers.h

Index: test/support/charconv_test_helpers.h
===
--- /dev/null
+++ test/support/charconv_test_helpers.h
@@ -0,0 +1,233 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef SUPPORT_CHARCONV_TEST_HELPERS_H
+#define SUPPORT_CHARCONV_TEST_HELPERS_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+using std::false_type;
+using std::true_type;
+
+template 
+constexpr auto
+is_non_narrowing(From a) -> decltype(To{a}, true_type())
+{
+return {};
+}
+
+template 
+constexpr auto
+is_non_narrowing(...) -> false_type
+{
+return {};
+}
+
+template 
+constexpr bool
+_fits_in(T, true_type /* non-narrowing*/, ...)
+{
+return true;
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, true_type /* T signed*/, true_type /* X signed */)
+{
+return xl::lowest() <= v && v <= (xl::max)();
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, true_type /* T signed */, false_type /* X unsigned*/)
+{
+return 0 <= v && typename std::make_unsigned::type(v) <= (xl::max)();
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, false_type /* T unsigned */, ...)
+{
+return v <= typename std::make_unsigned::type((xl::max)());
+}
+
+template 
+constexpr bool
+fits_in(T v)
+{
+return _fits_in(v, is_non_narrowing(v), std::is_signed(),
+   std::is_signed());
+}
+
+template 
+struct to_chars_test_base
+{
+template 
+void test(T v, char const ()[N], Ts... args)
+{
+using std::to_chars;
+std::to_chars_result r;
+
+constexpr size_t len = N - 1;
+static_assert(len > 0, "expected output won't be empty");
+
+if (!fits_in(v))
+return;
+
+r = to_chars(buf, buf + len - 1, X(v), args...);
+LIBCPP_ASSERT(r.ptr == buf + len - 1);
+LIBCPP_ASSERT(r.ec == std::errc::value_too_large);
+
+r = to_chars(buf, buf + sizeof(buf), X(v), args...);
+LIBCPP_ASSERT(r.ptr == buf + len);
+LIBCPP_ASSERT(r.ec == std::errc{});
+LIBCPP_ASSERT(memcmp(buf, expect, len) == 0);
+}
+
+template 
+void test_value(X v, Ts... args)
+{
+using std::to_chars;
+std::to_chars_result r;
+
+r = to_chars(buf, buf + sizeof(buf), v, args...);
+LIBCPP_ASSERT(r.ec == std::errc{});
+*r.ptr = '\0';
+
+auto a = fromchars(buf, r.ptr, args...);
+LIBCPP_ASSERT(v == a);
+
+auto ep = r.ptr - 1;
+r = to_chars(buf, ep, v, args...);
+LIBCPP_ASSERT(r.ptr == ep);
+LIBCPP_ASSERT(r.ec == std::errc::value_too_large);
+}
+
+private:
+using max_t = typename std::conditional::type;
+
+static auto fromchars(char const* p, char const* ep, int base, true_type)
+-> long long
+{
+char* last;
+auto r = strtoll(p, , base);
+LIBCPP_ASSERT(last == ep);
+
+return r;
+}
+
+static auto fromchars(char const* p, char const* ep, int base, false_type)
+-> unsigned long long
+{
+char* last;
+auto r = strtoull(p, , base);
+LIBCPP_ASSERT(last == ep);
+
+return r;
+}
+
+static auto fromchars(char const* p, char const* ep, int base = 10) -> max_t
+{
+return fromchars(p, ep, base, std::is_signed());
+}
+
+char buf[100];
+};
+
+template 
+struct roundtrip_test_base
+{
+template 
+void test(T v, Ts... args)
+{
+using std::from_chars;
+using std::to_chars;
+std::from_chars_result r2;
+std::to_chars_result r;
+X x = 0xc;
+
+if (fits_in(v))
+{
+r = to_chars(buf, buf + sizeof(buf), v, 

r322417 - Fix test on Windows that was added in r322382.

2018-01-12 Thread Douglas Yung via cfe-commits
Author: dyung
Date: Fri Jan 12 14:32:01 2018
New Revision: 322417

URL: http://llvm.org/viewvc/llvm-project?rev=322417=rev
Log:
Fix test on Windows that was added in r322382.

The test was using "%clang++" which on Windows became "clang.exe++". Use 
%clangxx instead.

Reviewed by Paul Robinson


Modified:
cfe/trunk/test/Driver/wasm-toolchain.cpp

Modified: cfe/trunk/test/Driver/wasm-toolchain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/wasm-toolchain.cpp?rev=322417=322416=322417=diff
==
--- cfe/trunk/test/Driver/wasm-toolchain.cpp (original)
+++ cfe/trunk/test/Driver/wasm-toolchain.cpp Fri Jan 12 14:32:01 2018
@@ -2,35 +2,35 @@
 // enabling -ffunction-sections, -fdata-sections, and -fvisibility=hidden by
 // default.
 
-// RUN: %clang++ %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 
2>&1 | FileCheck -check-prefix=CC1 %s
+// RUN: %clangxx %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 
2>&1 | FileCheck -check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} 
"-fvisibility" "hidden" {{.*}} "-ffunction-sections" "-fdata-sections"
 
 // Ditto, but ensure that a user -fno-function-sections disables the
 // default -ffunction-sections.
 
-// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-function-sections 
2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s
+// RUN: %clangxx %s -### -target wasm32-unknown-unknown -fno-function-sections 
2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s
 // NO_FUNCTION_SECTIONS-NOT: function-sections
 
 // Ditto, but ensure that a user -fno-data-sections disables the
 // default -fdata-sections.
 
-// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-data-sections 
2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s
+// RUN: %clangxx %s -### -target wasm32-unknown-unknown -fno-data-sections 
2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s
 // NO_DATA_SECTIONS-NOT: data-sections
 
 // Ditto, but ensure that a user -fvisibility=default disables the default
 // -fvisibility=hidden.
 
-// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fvisibility=default 
2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s
+// RUN: %clangxx %s -### -target wasm32-unknown-unknown -fvisibility=default 
2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s
 // FVISIBILITY_DEFAULT-NOT: hidden
 
 // A basic C++ link command-line.
 
-// RUN: %clang++ -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK %s
+// RUN: %clangxx -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
 // LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" 
"-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
 // A basic C++ link command-line with optimization.
 
-// RUN: %clang++ -### -O2 -no-canonical-prefixes -target 
wasm32-unknown-unknown --sysroot=/foo %s --stdlib=c++ 2>&1 | FileCheck 
-check-prefix=LINK_OPT %s
+// RUN: %clangxx -### -O2 -no-canonical-prefixes -target 
wasm32-unknown-unknown --sysroot=/foo %s --stdlib=c++ 2>&1 | FileCheck 
-check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
 // LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"


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


r322414 - When rebuilding an InitListExpr, don't give it a type.

2018-01-12 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Jan 12 14:21:33 2018
New Revision: 322414

URL: http://llvm.org/viewvc/llvm-project?rev=322414=rev
Log:
When rebuilding an InitListExpr, don't give it a type.

InitListExprs without types (well, with type 'void') represent not-yet-analyzed
initializer lists; InitListExpr with types fool Sema into thinking they don't
need further analysis in some cases (particularly C++17 copy omission).

Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=322414=322413=322414=diff
==
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Fri Jan 12 14:21:33 2018
@@ -2352,18 +2352,8 @@ public:
   /// Subclasses may override this routine to provide different behavior.
   ExprResult RebuildInitList(SourceLocation LBraceLoc,
  MultiExprArg Inits,
- SourceLocation RBraceLoc,
- QualType ResultTy) {
-ExprResult Result
-  = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
-if (Result.isInvalid() || ResultTy->isDependentType())
-  return Result;
-
-// Patch in the result type we were given, which may have been computed
-// when the initial InitListExpr was built.
-InitListExpr *ILE = cast((Expr *)Result.get());
-ILE->setType(ResultTy);
-return Result;
+ SourceLocation RBraceLoc) {
+return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
   }
 
   /// \brief Build a new designated initializer expression.
@@ -3394,11 +3384,10 @@ ExprResult TreeTransform::Trans
   /*IsCall*/true, NewArgs, ))
 return ExprError();
 
-  // If this was list initialization, revert to list form.
+  // If this was list initialization, revert to syntactic list form.
   if (Construct->isListInitialization())
 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
-Construct->getLocEnd(),
-Construct->getType());
+Construct->getLocEnd());
 
   // Build a ParenListExpr to represent anything else.
   SourceRange Parens = Construct->getParenOrBraceRange();
@@ -9513,7 +9502,7 @@ TreeTransform::TransformInitLis
   }
 
   return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
-  E->getRBraceLoc(), E->getType());
+  E->getRBraceLoc());
 }
 
 template

Modified: cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp?rev=322414=322413=322414=diff
==
--- cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp Fri Jan 12 
14:21:33 2018
@@ -112,3 +112,21 @@ namespace Dynamic {
   //   A_CLEANUP:
   // CHECK: call void @_ZN7Dynamic1AD1Ev({{.*}} @_ZN7Dynamic2d3E
 }
+
+namespace Instantiated1 {
+  struct A { A(); };
+  struct B : A { using A::A; };
+  template B v({});
+  template B v<0>;
+  // CHECK-LABEL: define {{.*}}global_var_init{{.*}} 
comdat($_ZN13Instantiated11vILi0EEE) {
+  // CHECK: call void @_ZN13Instantiated11BC1Ev(%{{.*}}* 
@_ZN13Instantiated11vILi0EEE)
+}
+
+namespace Instantiated2 {
+  struct A { A(); };
+  struct B : A {};
+  template B v({});
+  template B v<0>;
+  // CHECK-LABEL: define {{.*}}global_var_init{{.*}} 
comdat($_ZN13Instantiated21vILi0EEE) {
+  // CHECK: call void @_ZN13Instantiated21AC2Ev(
+}


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


[PATCH] D42011: [DWARFv5] Enable MD5 checksums

2018-01-12 Thread Paul Robinson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322413: [DWARFv5] Have -gdwarf-5 generate MD5 checksums 
(authored by probinson, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42011?vs=129703=129708#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42011

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGen/debug-info-file-checksum.c


Index: test/CodeGen/debug-info-file-checksum.c
===
--- test/CodeGen/debug-info-file-checksum.c
+++ test/CodeGen/debug-info-file-checksum.c
@@ -1,4 +1,5 @@
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c 
%S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -gdwarf-5 -x c 
%S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 
 // Check that "checksum" is created correctly for the compiled file.
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -365,7 +365,8 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView)
+  if (!CGM.getCodeGenOpts().EmitCodeView &&
+  CGM.getCodeGenOpts().DwarfVersion < 5)
 return llvm::DIFile::CSK_None;
 
   SourceManager  = CGM.getContext().getSourceManager();


Index: test/CodeGen/debug-info-file-checksum.c
===
--- test/CodeGen/debug-info-file-checksum.c
+++ test/CodeGen/debug-info-file-checksum.c
@@ -1,4 +1,5 @@
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -gdwarf-5 -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 
 // Check that "checksum" is created correctly for the compiled file.
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -365,7 +365,8 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView)
+  if (!CGM.getCodeGenOpts().EmitCodeView &&
+  CGM.getCodeGenOpts().DwarfVersion < 5)
 return llvm::DIFile::CSK_None;
 
   SourceManager  = CGM.getContext().getSourceManager();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42011: [DWARFv5] Enable MD5 checksums

2018-01-12 Thread Paul Robinson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322413: [DWARFv5] Have -gdwarf-5 generate MD5 checksums 
(authored by probinson, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42011?vs=129703=129707#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42011

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/test/CodeGen/debug-info-file-checksum.c


Index: cfe/trunk/test/CodeGen/debug-info-file-checksum.c
===
--- cfe/trunk/test/CodeGen/debug-info-file-checksum.c
+++ cfe/trunk/test/CodeGen/debug-info-file-checksum.c
@@ -1,4 +1,5 @@
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c 
%S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -gdwarf-5 -x c 
%S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 
 // Check that "checksum" is created correctly for the compiled file.
 
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -365,7 +365,8 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView)
+  if (!CGM.getCodeGenOpts().EmitCodeView &&
+  CGM.getCodeGenOpts().DwarfVersion < 5)
 return llvm::DIFile::CSK_None;
 
   SourceManager  = CGM.getContext().getSourceManager();


Index: cfe/trunk/test/CodeGen/debug-info-file-checksum.c
===
--- cfe/trunk/test/CodeGen/debug-info-file-checksum.c
+++ cfe/trunk/test/CodeGen/debug-info-file-checksum.c
@@ -1,4 +1,5 @@
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -gdwarf-5 -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 
 // Check that "checksum" is created correctly for the compiled file.
 
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -365,7 +365,8 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView)
+  if (!CGM.getCodeGenOpts().EmitCodeView &&
+  CGM.getCodeGenOpts().DwarfVersion < 5)
 return llvm::DIFile::CSK_None;
 
   SourceManager  = CGM.getContext().getSourceManager();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322413 - [DWARFv5] Have -gdwarf-5 generate MD5 checksums

2018-01-12 Thread Paul Robinson via cfe-commits
Author: probinson
Date: Fri Jan 12 14:19:03 2018
New Revision: 322413

URL: http://llvm.org/viewvc/llvm-project?rev=322413=rev
Log:
[DWARFv5] Have -gdwarf-5 generate MD5 checksums

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

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/CodeGen/debug-info-file-checksum.c

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=322413=322412=322413=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Jan 12 14:19:03 2018
@@ -365,7 +365,8 @@ llvm::DIFile::ChecksumKind
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView)
+  if (!CGM.getCodeGenOpts().EmitCodeView &&
+  CGM.getCodeGenOpts().DwarfVersion < 5)
 return llvm::DIFile::CSK_None;
 
   SourceManager  = CGM.getContext().getSourceManager();

Modified: cfe/trunk/test/CodeGen/debug-info-file-checksum.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-file-checksum.c?rev=322413=322412=322413=diff
==
--- cfe/trunk/test/CodeGen/debug-info-file-checksum.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-file-checksum.c Fri Jan 12 14:19:03 2018
@@ -1,4 +1,5 @@
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c 
%S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -gdwarf-5 -x c 
%S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 
 // Check that "checksum" is created correctly for the compiled file.
 


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


[PATCH] D41935: [analyzer] NFC: Mark default constructors for ProgramPoints.

2018-01-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D41935



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


[PATCH] D41384: [analyzer] Suppress false positive warnings form security.insecureAPI.strcpy

2018-01-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322410: [analyzer] Dont flag strcpy of string literals 
into sufficiently large buffers. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D41384?vs=129676=129706#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41384

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  cfe/trunk/test/Analysis/security-syntax-checks.m


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -510,6 +510,17 @@
   if (!checkCall_strCommon(CE, FD))
 return;
 
+  const auto *Target = CE->getArg(0)->IgnoreImpCasts(),
+ *Source = CE->getArg(1)->IgnoreImpCasts();
+  if (const auto *DeclRef = dyn_cast(Target))
+if (const auto *Array = dyn_cast(DeclRef->getType())) {
+  uint64_t ArraySize = BR.getContext().getTypeSize(Array) / 8;
+  if (const auto *String = dyn_cast(Source)) {
+if (ArraySize >= String->getLength() + 1)
+  return;
+  }
+}
+
   // Issue a warning.
   PathDiagnosticLocation CELoc =
 PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
Index: cfe/trunk/test/Analysis/security-syntax-checks.m
===
--- cfe/trunk/test/Analysis/security-syntax-checks.m
+++ cfe/trunk/test/Analysis/security-syntax-checks.m
@@ -146,6 +146,16 @@
   strcpy(x, y); //expected-warning{{Call to function 'strcpy' is insecure as 
it does not provide bounding of the memory buffer. Replace unbounded copy 
functions with analogous functions that support length arguments such as 
'strlcpy'. CWE-119}}
 }
 
+void test_strcpy_2() {
+  char x[4];
+  strcpy(x, "abcd"); //expected-warning{{Call to function 'strcpy' is insecure 
as it does not provide bounding of the memory buffer. Replace unbounded copy 
functions with analogous functions that support length arguments such as 
'strlcpy'. CWE-119}}
+}
+
+void test_strcpy_safe() {
+  char x[5];
+  strcpy(x, "abcd");
+}
+
 //===--===
 // strcat()
 //===--===


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -510,6 +510,17 @@
   if (!checkCall_strCommon(CE, FD))
 return;
 
+  const auto *Target = CE->getArg(0)->IgnoreImpCasts(),
+ *Source = CE->getArg(1)->IgnoreImpCasts();
+  if (const auto *DeclRef = dyn_cast(Target))
+if (const auto *Array = dyn_cast(DeclRef->getType())) {
+  uint64_t ArraySize = BR.getContext().getTypeSize(Array) / 8;
+  if (const auto *String = dyn_cast(Source)) {
+if (ArraySize >= String->getLength() + 1)
+  return;
+  }
+}
+
   // Issue a warning.
   PathDiagnosticLocation CELoc =
 PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
Index: cfe/trunk/test/Analysis/security-syntax-checks.m
===
--- cfe/trunk/test/Analysis/security-syntax-checks.m
+++ cfe/trunk/test/Analysis/security-syntax-checks.m
@@ -146,6 +146,16 @@
   strcpy(x, y); //expected-warning{{Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119}}
 }
 
+void test_strcpy_2() {
+  char x[4];
+  strcpy(x, "abcd"); //expected-warning{{Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119}}
+}
+
+void test_strcpy_safe() {
+  char x[5];
+  strcpy(x, "abcd");
+}
+
 //===--===
 // strcat()
 //===--===
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322410 - [analyzer] Don't flag strcpy of string literals into sufficiently large buffers.

2018-01-12 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Fri Jan 12 14:12:11 2018
New Revision: 322410

URL: http://llvm.org/viewvc/llvm-project?rev=322410=rev
Log:
[analyzer] Don't flag strcpy of string literals into sufficiently large buffers.

In the security package, we have a simple syntactic check that warns about
strcpy() being insecure, due to potential buffer overflows.

Suppress that check's warning in the trivial situation when the source is an
immediate null-terminated string literal and the target is an immediate
sufficiently large buffer.

Patch by András Leitereg!

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
cfe/trunk/test/Analysis/security-syntax-checks.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp?rev=322410=322409=322410=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp Fri Jan 
12 14:12:11 2018
@@ -510,6 +510,17 @@ void WalkAST::checkCall_strcpy(const Cal
   if (!checkCall_strCommon(CE, FD))
 return;
 
+  const auto *Target = CE->getArg(0)->IgnoreImpCasts(),
+ *Source = CE->getArg(1)->IgnoreImpCasts();
+  if (const auto *DeclRef = dyn_cast(Target))
+if (const auto *Array = dyn_cast(DeclRef->getType())) {
+  uint64_t ArraySize = BR.getContext().getTypeSize(Array) / 8;
+  if (const auto *String = dyn_cast(Source)) {
+if (ArraySize >= String->getLength() + 1)
+  return;
+  }
+}
+
   // Issue a warning.
   PathDiagnosticLocation CELoc =
 PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);

Modified: cfe/trunk/test/Analysis/security-syntax-checks.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/security-syntax-checks.m?rev=322410=322409=322410=diff
==
--- cfe/trunk/test/Analysis/security-syntax-checks.m (original)
+++ cfe/trunk/test/Analysis/security-syntax-checks.m Fri Jan 12 14:12:11 2018
@@ -146,6 +146,16 @@ void test_strcpy() {
   strcpy(x, y); //expected-warning{{Call to function 'strcpy' is insecure as 
it does not provide bounding of the memory buffer. Replace unbounded copy 
functions with analogous functions that support length arguments such as 
'strlcpy'. CWE-119}}
 }
 
+void test_strcpy_2() {
+  char x[4];
+  strcpy(x, "abcd"); //expected-warning{{Call to function 'strcpy' is insecure 
as it does not provide bounding of the memory buffer. Replace unbounded copy 
functions with analogous functions that support length arguments such as 
'strlcpy'. CWE-119}}
+}
+
+void test_strcpy_safe() {
+  char x[5];
+  strcpy(x, "abcd");
+}
+
 //===--===
 // strcat()
 //===--===


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


[PATCH] D42011: [DWARFv5] Enable MD5 checksums

2018-01-12 Thread Paul Robinson via Phabricator via cfe-commits
probinson created this revision.
probinson added reviewers: dblaikie, aprantl.
probinson added a project: debug-info.
Herald added subscribers: cfe-commits, JDevlieghere.

Under `-gdwarf-5` generate MD5 checksums of source files to emit to the DWARF 
v5 line table.

This consumes 16 bytes per source file in the line table, but allows a debugger 
to verify that
the source file hasn't changed since build time, which Clang has never allowed 
before.


Repository:
  rC Clang

https://reviews.llvm.org/D42011

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-file-checksum.c


Index: clang/test/CodeGen/debug-info-file-checksum.c
===
--- clang/test/CodeGen/debug-info-file-checksum.c
+++ clang/test/CodeGen/debug-info-file-checksum.c
@@ -1,4 +1,5 @@
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c 
%S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -gdwarf-5 -x c 
%S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 
 // Check that "checksum" is created correctly for the compiled file.
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -365,7 +365,8 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView)
+  if (!CGM.getCodeGenOpts().EmitCodeView &&
+  CGM.getCodeGenOpts().DwarfVersion < 5)
 return llvm::DIFile::CSK_None;
 
   SourceManager  = CGM.getContext().getSourceManager();


Index: clang/test/CodeGen/debug-info-file-checksum.c
===
--- clang/test/CodeGen/debug-info-file-checksum.c
+++ clang/test/CodeGen/debug-info-file-checksum.c
@@ -1,4 +1,5 @@
 // RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -gdwarf-5 -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
 
 // Check that "checksum" is created correctly for the compiled file.
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -365,7 +365,8 @@
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> ) const {
   Checksum.clear();
 
-  if (!CGM.getCodeGenOpts().EmitCodeView)
+  if (!CGM.getCodeGenOpts().EmitCodeView &&
+  CGM.getCodeGenOpts().DwarfVersion < 5)
 return llvm::DIFile::CSK_None;
 
   SourceManager  = CGM.getContext().getSourceManager();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40569: Use default IR alignment for cleanup.dest.slot.

2018-01-12 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.

r322406


Repository:
  rC Clang

https://reviews.llvm.org/D40569



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


r322406 - Allocate and access NormalCleanupDest with the natural alignment of i32.

2018-01-12 Thread John McCall via cfe-commits
Author: rjmccall
Date: Fri Jan 12 14:07:01 2018
New Revision: 322406

URL: http://llvm.org/viewvc/llvm-project?rev=322406=rev
Log:
Allocate and access NormalCleanupDest with the natural alignment of i32.

This alignment can be less than 4 on certain embedded targets, which may
not even be able to deal with 4-byte alignment on the stack.

Patch by Jacob Young!

Modified:
cfe/trunk/lib/CodeGen/CGCleanup.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGCleanup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=322406=322405=322406=diff
==
--- cfe/trunk/lib/CodeGen/CGCleanup.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCleanup.cpp Fri Jan 12 14:07:01 2018
@@ -624,7 +624,7 @@ static void destroyOptimisticNormalEntry
   si->eraseFromParent();
 
   // Destroy the load.
-  assert(condition->getOperand(0) == CGF.NormalCleanupDest);
+  assert(condition->getOperand(0) == CGF.NormalCleanupDest.getPointer());
   assert(condition->use_empty());
   condition->eraseFromParent();
 }
@@ -833,7 +833,7 @@ void CodeGenFunction::PopCleanupBlock(bo
 if (NormalCleanupDestSlot->hasOneUse()) {
   NormalCleanupDestSlot->user_back()->eraseFromParent();
   NormalCleanupDestSlot->eraseFromParent();
-  NormalCleanupDest = nullptr;
+  NormalCleanupDest = Address::invalid();
 }
 
 llvm::BasicBlock *BranchAfter = Scope.getBranchAfterBlock(0);
@@ -1250,10 +1250,10 @@ void CodeGenFunction::DeactivateCleanupB
 }
 
 Address CodeGenFunction::getNormalCleanupDestSlot() {
-  if (!NormalCleanupDest)
+  if (!NormalCleanupDest.isValid())
 NormalCleanupDest =
-  CreateTempAlloca(Builder.getInt32Ty(), "cleanup.dest.slot");
-  return Address(NormalCleanupDest, CharUnits::fromQuantity(4));
+  CreateDefaultAlignTempAlloca(Builder.getInt32Ty(), "cleanup.dest.slot");
+  return NormalCleanupDest;
 }
 
 /// Emits all the code to cause the given temporary to be cleaned up.

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=322406=322405=322406=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Jan 12 14:07:01 2018
@@ -70,7 +70,7 @@ CodeGenFunction::CodeGenFunction(CodeGen
   IsSanitizerScope(false), CurFuncIsThunk(false), AutoreleaseResult(false),
   SawAsmBlock(false), IsOutlinedSEHHelper(false), BlockInfo(nullptr),
   BlockPointer(nullptr), LambdaThisCaptureField(nullptr),
-  NormalCleanupDest(nullptr), NextCleanupDestIndex(1),
+  NormalCleanupDest(Address::invalid()), NextCleanupDestIndex(1),
   FirstBlockInfo(nullptr), EHResumeBlock(nullptr), ExceptionSlot(nullptr),
   EHSelectorSlot(nullptr), DebugInfo(CGM.getModuleDebugInfo()),
   DisableDebugInfo(false), DidCallStackSave(false), 
IndirectBranch(nullptr),
@@ -439,10 +439,11 @@ void CodeGenFunction::FinishFunction(Sou
   // if compiled with no optimizations. We do it for coroutine as the lifetime
   // of CleanupDestSlot alloca make correct coroutine frame building very
   // difficult.
-  if (NormalCleanupDest && isCoroutine()) {
+  if (NormalCleanupDest.isValid() && isCoroutine()) {
 llvm::DominatorTree DT(*CurFn);
-llvm::PromoteMemToReg(NormalCleanupDest, DT);
-NormalCleanupDest = nullptr;
+llvm::PromoteMemToReg(
+cast(NormalCleanupDest.getPointer()), DT);
+NormalCleanupDest = Address::invalid();
   }
 }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=322406=322405=322406=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Jan 12 14:07:01 2018
@@ -434,7 +434,7 @@ public:
   };
 
   /// i32s containing the indexes of the cleanup destinations.
-  llvm::AllocaInst *NormalCleanupDest;
+  Address NormalCleanupDest;
 
   unsigned NextCleanupDestIndex;
 


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


r322405 - Disable test for Windows to fix Windows buildbots.

2018-01-12 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Fri Jan 12 13:49:20 2018
New Revision: 322405

URL: http://llvm.org/viewvc/llvm-project?rev=322405=rev
Log:
Disable test for Windows to fix Windows buildbots.

Modified:
cfe/trunk/test/Modules/odr_hash-Friend.cpp

Modified: cfe/trunk/test/Modules/odr_hash-Friend.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash-Friend.cpp?rev=322405=322404=322405=diff
==
--- cfe/trunk/test/Modules/odr_hash-Friend.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash-Friend.cpp Fri Jan 12 13:49:20 2018
@@ -8,6 +8,8 @@
 // RUN:  -fmodules-cache-path=%t/modules.cache \
 // RUN:  -std=c++11 -x c++ %s -verify
 
+// UNSUPPORTED: windows
+
 // expected-no-diagnostics
 
 #include "Box.h"


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


[PATCH] D41746: Make std::get_temporary_buffer respect overaligned types when possible

2018-01-12 Thread Chris Kennelly via Phabricator via cfe-commits
ckennelly marked 2 inline comments as done.
ckennelly added a comment.

In https://reviews.llvm.org/D41746#973941, @EricWF wrote:

> This LGTM minus nits.
>
> Is there a LWG issue or paper that specifies this change? or is it just a 
> general bug fix?


This is just a general bug fix.




Comment at: include/memory:2007
+#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
+if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+{

EricWF wrote:
> Please use the `alignment_of` trait; since that's always available within the 
> library, but different spellings of the `alignof` keyword aren't.
I also guarded for __STDCPP_DEFAULT_NEW_ALIGNMENT__


Repository:
  rCXX libc++

https://reviews.llvm.org/D41746



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


[PATCH] D41820: [coroutines] Pass coro func args to promise ctor

2018-01-12 Thread Eric Niebler via Phabricator via cfe-commits
eric_niebler added a comment.

> Is this behavior specified somewhere? Or are we simply adding an extension to 
> Clang?

It is not specified anywhere //yet// but Gor has promised a paper for 
Jacksonville.

> If so I would really prefer to add my co_promise solution (but I need to 
> write a paper in favor of it first).

I have no problem with you making a separate proposal. I don't consider this an 
either/or thing.


Repository:
  rC Clang

https://reviews.llvm.org/D41820



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


[PATCH] D41746: Make std::get_temporary_buffer respect overaligned types when possible

2018-01-12 Thread Chris Kennelly via Phabricator via cfe-commits
ckennelly updated this revision to Diff 129698.

Repository:
  rCXX libc++

https://reviews.llvm.org/D41746

Files:
  include/memory
  test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp

Index: test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp
===
--- /dev/null
+++ test/std/utilities/memory/temporary.buffer/overaligned.pass.cpp
@@ -0,0 +1,33 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template 
+//   pair
+//   get_temporary_buffer(ptrdiff_t n);
+//
+// template 
+//   void
+//   return_temporary_buffer(T* p);
+
+#include 
+#include 
+
+struct alignas(32) A {
+int field;
+};
+
+int main()
+{
+std::pair ip = std::get_temporary_buffer(5);
+assert(!(ip.first == nullptr) ^ (ip.second == 0));
+assert(reinterpret_cast(ip.first) % alignof(A) == 0);
+std::return_temporary_buffer(ip.first);
+}
Index: include/memory
===
--- include/memory
+++ include/memory
@@ -2003,7 +2003,38 @@
 __n = __m;
 while (__n > 0)
 {
+#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
+#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
+if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+#else
+if (std::alignment_of<_Tp>::value >
+std::alignment_of::value)
+#endif
+{
+std::align_val_t __al =
+std::align_val_t(std::alignment_of<_Tp>::value);
+__r.first = static_cast<_Tp*>(::operator new(
+__n * sizeof(_Tp), __al, nothrow));
+} else {
+__r.first = static_cast<_Tp*>(::operator new(
+__n * sizeof(_Tp), nothrow));
+}
+#else
+#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
+if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+#else
+if (std::alignment_of<_Tp>::value >
+std::alignment_of::value)
+#endif
+{
+// Since aligned operator new is unavailable, return an empty
+// buffer rather than one with invalid alignment.
+return __r;
+}
+
 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
+#endif
+
 if (__r.first)
 {
 __r.second = __n;
@@ -2016,7 +2047,23 @@
 
 template 
 inline _LIBCPP_INLINE_VISIBILITY
-void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
+void return_temporary_buffer(_Tp* __p) _NOEXCEPT
+{
+#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
+#if defined(__STDCPP_DEFAULT_NEW_ALIGNMENT__)
+if (std::alignment_of<_Tp>::value > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+#else
+if (std::alignment_of<_Tp>::value >
+std::alignment_of::value)
+#endif
+{
+std::align_val_t __al = std::align_val_t(std::alignment_of<_Tp>::value);
+::operator delete(__p, __al);
+return;
+}
+#endif
+::operator delete(__p);
+}
 
 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/bugprone/UnusedReturnValueCheck.cpp:47
+"^::std::launder$|"
+"^::std::unique_ptr<.*>::release$|"
+"^::std::.*::allocate$|"

Is the following type a problem for you check?

`std::unique_ptr` should not be matchable with regex but I 
don't know if that would have an impact on the functionality.


https://reviews.llvm.org/D41655



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


[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-12 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.

LGTM

Not sure if anyone's mentioned it yet, but there's a C ABI testing tool in 
clang/utils/ABITest/ which you'll probably want to try at some point.




Comment at: lib/CodeGen/TargetInfo.cpp:8913
+  }
+  return getNaturalAlignIndirect(Ty, /*ByVal=*/true);
+}

asb wrote:
> efriedma wrote:
> > The spec says "Aggregates larger than 2✕XLEN bits are passed by reference 
> > and are replaced in the argument list with the address".  That's not byval.
> The LLVM backend lowers byval in that way. Given that at this point we have a 
> trivial data type (plain struct or similar) which is copied-by-value by C 
> semantics, the only difference is whether the generated IR indicates implicit 
> copying with 'byval' or relies on the caller explicitly doing the copy. For 
> some reason I thought 'byval' was preferred, but looking again it seems 
> uncommon to do it this way. I've changed it to false - thanks for spotting 
> this.
"byval" generally means the value is memcpy'ed into the argument list (so there 
is no pointer in the argument list). This is useful for handling C calling 
conventions which allow excessively large structs to be passed in the argument 
list, so the backend can emit a memcpy rather than expanding the operation into 
straight-line code.  The RISCV backend handling of byval is wrong, in the sense 
that it isn't consistent with what any other backend does.

This isn't relevant to the RISC-V C calling convention, but you should probably 
fix the backend at some point to avoid future confusion.


https://reviews.llvm.org/D40023



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


[PATCH] D41976: Low-hanging fruit optimization in string::__move_assign().

2018-01-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added reviewers: EricWF, mclow.lists, hiraditya.
vsk added a comment.

Adding some folks who may be interested.


https://reviews.llvm.org/D41976



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


[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-12 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.  LGTM, but you should wait for Eli's sign-off, too.


https://reviews.llvm.org/D40023



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


[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2018-01-12 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a comment.

I just checked both my qemu copy and  on my mips64 machine and it seems to be a 
a copy / paste error. Reposting here directly from my machines:

MIPS64:

  diff --git a/test/libunwind/test/config.py b/test/libunwind/test/config.py
  index 2a0c828..a8952c3 100644
  --- a/test/libunwind/test/config.py
  +++ b/test/libunwind/test/config.py
  @@ -48,6 +48,8 @@ class Configuration(LibcxxConfiguration):
   # Stack unwinding tests need unwinding tables and these are not
   # generated by default on all Targets.
   self.cxx.compile_flags += ['-funwind-tables']
  +   self.cxx.compile_flags += ['-mabi=n32']
  +self.cxx.link_flags += ['-mabi=n32']
   if not self.get_lit_bool('enable_threads', True):
   self.cxx.compile_flags += ['-D_LIBUNWIND_HAS_NO_THREADS']
   self.config.available_features.add('libunwind-no-threads')

X86_64:

  diff --git a/test/libunwind/test/config.py b/test/libunwind/test/config.py
  index 2a0c828..f1953e2 100644
  --- a/test/libunwind/test/config.py
  +++ b/test/libunwind/test/config.py
  @@ -48,6 +48,8 @@ class Configuration(LibcxxConfiguration):
   # Stack unwinding tests need unwinding tables and these are not
   # generated by default on all Targets.
   self.cxx.compile_flags += ['-funwind-tables']
  +   self.cxx.compile_flags += ['-mabi=n32']
  +self.cxx.link_flags += ['-mabi=n32', 
'/home/sdardis/mips-mti-linux-gnu/2016.05-06/bin/../lib/gcc/mips-mti-linux-gnu/4.9.2/../../../../mips-mti-linux-gnu/lib/mips-r2-hard/lib32/libgcc_s.so.1']
   if not self.get_lit_bool('enable_threads', True):
   self.cxx.compile_flags += ['-D_LIBUNWIND_HAS_NO_THREADS']
   self.config.available_features.add('libunwind-no-threads')

I corrected whitespace nit before I posted the comment.


https://reviews.llvm.org/D39074



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


[PATCH] D40854: [clang-tidy] WIP implement cppcoreguidelines check for mixed integer arithmetic

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129693.
JonasToth added a comment.

rebase to 7.0.0


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40854

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MixedIntArithmeticCheck.cpp
  clang-tidy/cppcoreguidelines/MixedIntArithmeticCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-mixed-int-arithmetic.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-mixed-int-arithmetic.cpp

Index: test/clang-tidy/cppcoreguidelines-mixed-int-arithmetic.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-mixed-int-arithmetic.cpp
@@ -0,0 +1,188 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-mixed-int-arithmetic %t
+
+enum UnsignedEnum : unsigned char {
+  UEnum1,
+  UEnum2
+};
+
+enum SignedEnum : signed char {
+  SEnum1,
+  SEnum2
+};
+
+unsigned char returnUnsignedCharacter() { return 42; }
+unsigned returnUnsignedNumber() { return 42u; }
+long returnBigNumber() { return 42; }
+float unrelatedThing() { return 42.f; }
+SignedEnum returnSignedEnum() { return SEnum1; }
+UnsignedEnum returnUnsignedEnum() { return UEnum1; }
+
+void mixed_binary() {
+  unsigned int UInt1 = 42;
+  signed int SInt1 = 42;
+  UnsignedEnum UE1 = UEnum1;
+  SignedEnum SE1 = SEnum1;
+  float UnrelatedFloat = 42.f;
+
+  // Test traditional integer types.
+  auto R1 = UInt1 + SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:21: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  int R2 = UInt1 - SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:20: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:12: note: unsigned operand
+
+  unsigned int R3 = UInt1 * SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:29: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:21: note: unsigned operand
+
+  unsigned int R4 = UInt1 / returnBigNumber();
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:29: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:21: note: unsigned operand
+
+  char R5 = returnUnsignedCharacter() + SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:41: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  auto R6 = SInt1 - 10u;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:13: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:21: note: unsigned operand
+
+  auto R7 = UInt1 * 10;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:21: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  auto R8 = 10u / returnBigNumber();
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:19: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  auto R9 = 10 + returnUnsignedCharacter();
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:13: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:18: note: unsigned operand
+
+  // Test enum types.
+  char R10 = returnUnsignedEnum() - SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:37: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:14: note: unsigned operand
+
+  unsigned char R11 = returnSignedEnum() * UInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:23: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:23: note: signed operand
+  // CHECK-MESSAGES: 

[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-12 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst:6-7
+
+The usage of ``goto`` has been discouraged for a long time and is diagnosed
+with this check.
+

JonasToth wrote:
> aaron.ballman wrote:
> > This doesn't really help the user understand what's bad about goto or why 
> > it should be diagnosed. You should expound a bit here.
> Is it better now?
Much better now! Thank you for fix!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815



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


[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129691.
JonasToth added a comment.

- minor issues fixed


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to declare constants
+
+#define PROBLEMATIC_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate functions
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate variadic templates
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+The relevant sections in the C++ Coreguidelines are 
+`Enum.1 `_,
+`ES.30 `_,
+`ES.31 `_ and
+`ES.33 `_.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,12 @@
 Improvements to clang-tidy
 --
 
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
+
 - New `fuchsia-statically-constructed-objects
   `_ check
 
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.h
@@ -0,0 +1,38 @@
+//===--- MacroUsageCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+
+#include "../ClangTidy.h"
+#include "clang/Lex/Preprocessor.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+enum class MacroUsageMode { Constant, Function, Variadic };
+/// Find macro usage that is considered problematic because better language
+/// constructs exist for the task.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-macro-usage.html
+class MacroUsageCheck : public ClangTidyCheck {
+public:
+  MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerPPCallbacks(CompilerInstance ) override;
+  void warnMacro(const MacroDirective *MD);
+};
+
+} // namespace 

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129690.
JonasToth marked 3 inline comments as done.
JonasToth added a comment.

- address review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to declare constants
+
+#define PROBLEMATIC_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate functions
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate variadic templates
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+The relevant sections in the C++ Coreguidelines are 
+`Enum.1 `_,
+`ES.30 `_,
+`ES.31 `_ and
+`ES.33 `_.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,13 +57,20 @@
 Improvements to clang-tidy
 --
 
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
+
 - New `fuchsia-statically-constructed-objects
   `_ check
 
   Warns if global, non-trivial objects with static storage are constructed, unless the 
   object is statically initialized with a ``constexpr`` constructor or has no 
   explicit constructor.
 
+
 Improvements to include-fixer
 -
 
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.h
@@ -0,0 +1,38 @@
+//===--- MacroUsageCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+
+#include "../ClangTidy.h"
+#include "clang/Lex/Preprocessor.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+enum class MacroUsageMode { Constant, Function, Variadic };
+/// Find macro usage that is considered problematic because better language
+/// constructs exist for the task.
+///
+/// For the user-facing documentation see:
+/// 

[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2018-01-12 Thread John Baldwin via Phabricator via cfe-commits
bsdjhb added a comment.

In https://reviews.llvm.org/D39074#974913, @sdardis wrote:

> This was libunwind's test suite:
>
>   Compiled test failed unexpectedly!
>   
>   Testing Time: 0.53s
>   
>   Failing Tests (1):
>   libunwind :: libunwind_02.pass.cpp
>  
> Expected Passes: 3
> Unexpected Failures: 1 
>   
>   
>
> The hacky patch I used to test n32:
>
>   --- a/test/libunwind/test/config.py
>   +++ b/test/libunwind/test/config.py
>   @@ -48,6 +48,8 @@ class Configuration(LibcxxConfiguration):
># Stack unwinding tests need unwinding tables and these are not
># generated by default on all Targets.
>self.cxx.compile_flags += ['-funwind-tables']
>   +self.cxx.compile_flags += ['-mabi=n33']
>   +self.cxx.link_flags += ['-mabi=n32']
>if not self.get_lit_bool('enable_threads', True):
>self.cxx.compile_flags += ['-D_LIBUNWIND_HAS_NO_THREADS']
>self.config.available_features.add('libunwind-no-threads')
>   
>   


Just to be sure, is that '-mabi=n33' in the compile flags a copy and paste typo 
in the diff or do you have it locally in the real change as well?


https://reviews.llvm.org/D39074



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


[PATCH] D41976: Low-hanging fruit optimization in string::__move_assign().

2018-01-12 Thread Timothy VanSlyke via Phabricator via cfe-commits
tvanslyke updated this revision to Diff 129685.
tvanslyke added a comment.

I went ahead and just pulled it out to a small inline member function and added 
it to __copy_assign_alloc().  Removed some other redundancies.


https://reviews.llvm.org/D41976

Files:
  string


Index: string
===
--- string
+++ string
@@ -1407,24 +1407,30 @@
   
__alloc_traits::propagate_on_container_copy_assignment::value>());}
 
 _LIBCPP_INLINE_VISIBILITY
+void __clear_and_shrink() 
+{
+clear();
+if(__is_long())
+__alloc_traits::deallocate(__alloc(), __get_long_pointer(), 
capacity() + 1);
+} 
+
+_LIBCPP_INLINE_VISIBILITY
 void __copy_assign_alloc(const basic_string& __str, true_type)
 {
 if (__alloc() == __str.__alloc())
 __alloc() = __str.__alloc();
 else
 {
 if (!__str.__is_long())
 {
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __alloc() = __str.__alloc();
 }
 else
 {
 allocator_type __a = __str.__alloc();
 pointer __p = __alloc_traits::allocate(__a, 
__str.__get_long_cap());
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __alloc() = _VSTD::move(__a);
 __set_long_pointer(__p);
 __set_long_cap(__str.__get_long_cap());
@@ -2102,8 +2108,7 @@
 _NOEXCEPT_(is_nothrow_move_assignable::value)
 #endif
 {
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __r_.first() = __str.__r_.first();
 __move_assign_alloc(__str);
 __str.__zero();


Index: string
===
--- string
+++ string
@@ -1407,24 +1407,30 @@
   __alloc_traits::propagate_on_container_copy_assignment::value>());}
 
 _LIBCPP_INLINE_VISIBILITY
+void __clear_and_shrink() 
+{
+clear();
+if(__is_long())
+__alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
+} 
+
+_LIBCPP_INLINE_VISIBILITY
 void __copy_assign_alloc(const basic_string& __str, true_type)
 {
 if (__alloc() == __str.__alloc())
 __alloc() = __str.__alloc();
 else
 {
 if (!__str.__is_long())
 {
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __alloc() = __str.__alloc();
 }
 else
 {
 allocator_type __a = __str.__alloc();
 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __alloc() = _VSTD::move(__a);
 __set_long_pointer(__p);
 __set_long_cap(__str.__get_long_cap());
@@ -2102,8 +2108,7 @@
 _NOEXCEPT_(is_nothrow_move_assignable::value)
 #endif
 {
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __r_.first() = __str.__r_.first();
 __move_assign_alloc(__str);
 __str.__zero();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40737: [clang-tidy] Resubmit hicpp-multiway-paths-covered without breaking test

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129686.
JonasToth added a comment.

- get up to date to 7.0


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40737

Files:
  clang-tidy/hicpp/CMakeLists.txt
  clang-tidy/hicpp/HICPPTidyModule.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/hicpp-multiway-paths-covered.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/hicpp-multiway-paths-covered-else.cpp
  test/clang-tidy/hicpp-multiway-paths-covered.cpp

Index: test/clang-tidy/hicpp-multiway-paths-covered.cpp
===
--- /dev/null
+++ test/clang-tidy/hicpp-multiway-paths-covered.cpp
@@ -0,0 +1,472 @@
+// RUN: %check_clang_tidy %s hicpp-multiway-paths-covered %t
+
+enum OS { Mac,
+  Windows,
+  Linux };
+
+struct Bitfields {
+  unsigned UInt : 3;
+  int SInt : 1;
+};
+
+int return_integer() { return 42; }
+
+void bad_switch(int i) {
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case 0:
+break;
+  }
+  // No default in this switch
+  switch (i) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+break;
+  case 1:
+break;
+  case 2:
+break;
+  }
+
+  // degenerate, maybe even warning
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch without labels
+  }
+
+  switch (int j = return_integer()) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+  case 2:
+break;
+  }
+
+  // Degenerated, only default case.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch with default label only
+  default:
+break;
+  }
+
+  // Degenerated, only one case label and default case -> Better as if-stmt.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch could be better written as an if/else statement
+  case 0:
+break;
+  default:
+break;
+  }
+
+  unsigned long long BigNumber = 0;
+  switch (BigNumber) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+
+  const int  = i;
+  switch (IntRef) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+
+  char C = 'A';
+  switch (C) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 'A':
+break;
+  case 'B':
+break;
+  }
+
+  Bitfields Bf;
+  // UInt has 3 bits size.
+  switch (Bf.UInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.UInt) {
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+break;
+  }
+  // SInt has 1 bit size, so this is somewhat degenerated.
+  switch (Bf.SInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case 0:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.SInt) {
+  case 0:
+  case 1:
+break;
+  }
+
+  bool Flag = false;
+  switch (Flag) {
+// CHECK-MESSAGES:[[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case true:
+break;
+  }
+
+  switch (Flag) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch with default label only
+  default:
+break;
+  }
+
+  // This `switch` will create a frontend warning from '-Wswitch-bool' but is
+  // ok for this check.
+  switch (Flag) {
+  case true:
+break;
+  case false:
+break;
+  }
+}
+
+void unproblematic_switch(unsigned char c) {
+  //
+  switch (c) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+  case 8:
+  case 9:
+  case 10:
+  case 11:
+  case 12:
+  case 13:
+  case 14:
+  case 15:
+  case 16:
+  case 17:
+  case 18:
+  case 19:
+  case 20:
+  case 21:
+  case 22:
+  case 23:
+  case 24:
+  case 25:
+  case 26:
+  case 27:
+  case 28:
+  case 29:
+  case 30:
+  case 31:
+  case 32:
+  case 33:
+  case 34:
+  case 35:
+  case 36:
+  case 37:
+  case 38:
+  case 39:
+  case 40:
+  case 41:
+  case 42:
+  case 43:
+  case 44:
+  case 45:
+  case 46:
+  case 47:
+  case 48:
+  case 49:
+  case 50:
+  case 51:
+  case 52:
+  case 53:
+  case 54:
+  case 55:
+  case 56:
+  case 57:
+  case 58:
+  case 59:
+  case 60:
+  case 61:
+  case 62:
+  case 63:
+  case 64:
+  case 65:
+  case 66:
+  case 67:
+  case 68:
+  case 69:
+  case 70:
+  case 71:
+  case 72:
+  case 73:
+  case 74:
+  case 75:
+  case 76:
+  case 77:
+  case 78:
+  case 79:

[PATCH] D40737: [clang-tidy] Resubmit hicpp-multiway-paths-covered without breaking test

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

@sbenza and/or @klimek did you have time to address the stackoverflow caused 
from the ASTMatchers?

I forgot to add the link to the original break: 
http://green.lab.llvm.org/green/job/clang-stage2-cmake-RgSan/5470/consoleFull#17462642768254eaf0-7326-4999-85b0-388101f2d404


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40737



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


[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129684.
JonasToth added a comment.

- simplified the code and merged diagnostics


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
@@ -0,0 +1,89 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
+
+void noop() {}
+
+int main() {
+  noop();
+  goto jump_to_me;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  noop();
+
+jump_to_me:;
+
+jump_backwards:;
+  noop();
+  goto jump_backwards;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-4]]:1: note: label defined here
+
+  // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+some_label:;
+  void *dynamic_label = &_label;
+
+  // FIXME: Not detected
+  goto *dynamic_label;
+}
+
+void forward_jump_out_nested_loop() {
+  for (int i = 0; i < 10; ++i) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (i + j > 10)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (int i = 0; i < 10; ++i) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit1;
+}
+noop();
+  }
+  // Jumping further results in error, because the variable declaration would
+  // be skipped.
+early_exit1:;
+
+  int i = 0;
+  while (true) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit2;
+  i++;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (j > 5)
+goto early_exit2;
+}
+noop();
+  }
+
+early_exit2:;
+}
+
+void jump_out_backwards() {
+
+before_the_loop:
+  noop();
+
+  for (int i = 0; i < 10; ++i) {
+for (int j = 0; j < 10; ++j) {
+  if (i * j > 80)
+goto before_the_loop;
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+}
+  }
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -52,6 +52,7 @@
cert-msc30-c (redirects to cert-msc50-cpp) 
cert-msc50-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 
+   cppcoreguidelines-avoid-goto
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
Index: docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-goto
+
+cppcoreguidelines-avoid-goto
+
+
+The usage of ``goto`` for control flow is error prone and should be replaced
+with looping constructs. Only forward jumps in nested loops are accepted.
+
+This check implements `ES.76 `_ 
+from the CppCoreGuidelines and 
+`6.3.1 from High Integrity C++ `_.
+
+For more information on why to avoid programming 
+with ``goto`` you can read the famous paper `A Case against the GO TO Statement. `_.
+
+The check diagnoses ``goto`` for backward jumps in every language mode. These
+should be replaced with `C/C++` looping constructs.
+
+.. code-block:: c++
+
+  // Bad, handwritten for loop.
+  int i = 0;
+  // Jump label for the loop
+  loop_start:
+  do_some_operation();
+
+  if (i < 100) {
+++i;
+goto loop_start;
+  }
+
+  // Better
+  for(int i = 0; i < 100; ++i)
+do_some_operation();
+
+Modern C++ needs ``goto`` only to jump out of nested loops.
+
+.. code-block:: c++
+
+  for(int i = 0; i < 100; ++i) {
+for(int j = 0; j < 100; ++j) {
+  if (i * j > 500)
+goto early_exit;
+}
+  }
+
+  early_exit:
+  some_operation();
+
+For C++11 or higher all other uses of ``goto`` are diagnosed.
Index: docs/ReleaseNotes.rst
===

[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb updated this revision to Diff 129683.
asb marked 8 inline comments as done.
asb added a comment.

Rebase after ABIArgInfo signext/zeroext refactoring 
https://reviews.llvm.org/D41999 / https://reviews.llvm.org/rL322396. We no 
longer need to modify CGCall.cpp for unsigned 32-bit return values to be sign 
extended as required by the RV64 ABI.


https://reviews.llvm.org/D40023

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGen/riscv32-abi.c
  test/CodeGen/riscv64-abi.c
  test/Driver/riscv32-toolchain.c
  test/Driver/riscv64-toolchain.c

Index: test/Driver/riscv64-toolchain.c
===
--- test/Driver/riscv64-toolchain.c
+++ test/Driver/riscv64-toolchain.c
@@ -42,3 +42,50 @@
 
 // CHECK: @align_vl = global i32 8
 int align_vl = __alignof(va_list);
+
+// Check types
+
+// CHECK: define zeroext i8 @check_char()
+char check_char() { return 0; }
+
+// CHECK: define signext i16 @check_short()
+short check_short() { return 0; }
+
+// CHECK: define signext i32 @check_int()
+int check_int() { return 0; }
+
+// CHECK: define signext i32 @check_wchar_t()
+int check_wchar_t() { return 0; }
+
+// CHECK: define i64 @check_long()
+long check_long() { return 0; }
+
+// CHECK: define i64 @check_longlong()
+long long check_longlong() { return 0; }
+
+// CHECK: define zeroext i8 @check_uchar()
+unsigned char check_uchar() { return 0; }
+
+// CHECK: define zeroext i16 @check_ushort()
+unsigned short check_ushort() { return 0; }
+
+// CHECK: define signext i32 @check_uint()
+unsigned int check_uint() { return 0; }
+
+// CHECK: define i64 @check_ulong()
+unsigned long check_ulong() { return 0; }
+
+// CHECK: define i64 @check_ulonglong()
+unsigned long long check_ulonglong() { return 0; }
+
+// CHECK: define i64 @check_size_t()
+size_t check_size_t() { return 0; }
+
+// CHECK: define float @check_float()
+float check_float() { return 0; }
+
+// CHECK: define double @check_double()
+double check_double() { return 0; }
+
+// CHECK: define fp128 @check_longdouble()
+long double check_longdouble() { return 0; }
Index: test/Driver/riscv32-toolchain.c
===
--- test/Driver/riscv32-toolchain.c
+++ test/Driver/riscv32-toolchain.c
@@ -73,3 +73,50 @@
 
 // CHECK: @align_vl = global i32 4
 int align_vl = __alignof(va_list);
+
+// Check types
+
+// CHECK: zeroext i8 @check_char()
+char check_char() { return 0; }
+
+// CHECK: define signext i16 @check_short()
+short check_short() { return 0; }
+
+// CHECK: define i32 @check_int()
+int check_int() { return 0; }
+
+// CHECK: define i32 @check_wchar_t()
+int check_wchar_t() { return 0; }
+
+// CHECK: define i32 @check_long()
+long check_long() { return 0; }
+
+// CHECK: define i64 @check_longlong()
+long long check_longlong() { return 0; }
+
+// CHECK: define zeroext i8 @check_uchar()
+unsigned char check_uchar() { return 0; }
+
+// CHECK: define zeroext i16 @check_ushort()
+unsigned short check_ushort() { return 0; }
+
+// CHECK: define i32 @check_uint()
+unsigned int check_uint() { return 0; }
+
+// CHECK: define i32 @check_ulong()
+unsigned long check_ulong() { return 0; }
+
+// CHECK: define i64 @check_ulonglong()
+unsigned long long check_ulonglong() { return 0; }
+
+// CHECK: define i32 @check_size_t()
+size_t check_size_t() { return 0; }
+
+// CHECK: define float @check_float()
+float check_float() { return 0; }
+
+// CHECK: define double @check_double()
+double check_double() { return 0; }
+
+// CHECK: define fp128 @check_longdouble()
+long double check_longdouble() { return 0; }
Index: test/CodeGen/riscv64-abi.c
===
--- /dev/null
+++ test/CodeGen/riscv64-abi.c
@@ -0,0 +1,425 @@
+// RUN: %clang_cc1 -triple riscv64 -emit-llvm %s -o - | FileCheck %s
+
+#include 
+#include 
+
+// CHECK-LABEL: define void @f_void()
+void f_void(void) {}
+
+// Scalar arguments and return values smaller than the word size are extended
+// according to the sign of their type, up to 32 bits
+
+// CHECK-LABEL: define zeroext i1 @f_scalar_0(i1 zeroext %x)
+_Bool f_scalar_0(_Bool x) { return x; }
+
+// CHECK-LABEL: define signext i8 @f_scalar_1(i8 signext %x)
+int8_t f_scalar_1(int8_t x) { return x; }
+
+// CHECK-LABEL: define zeroext i8 @f_scalar_2(i8 zeroext %x)
+uint8_t f_scalar_2(uint8_t x) { return x; }
+
+// CHECK-LABEL: define signext i32 @f_scalar_3(i32 signext %x)
+uint32_t f_scalar_3(int32_t x) { return x; }
+
+// CHECK-LABEL: define i64 @f_scalar_4(i64 %x)
+int64_t f_scalar_4(int64_t x) { return x; }
+
+// CHECK-LABEL: define float @f_fp_scalar_1(float %x)
+float f_fp_scalar_1(float x) { return x; }
+
+// CHECK-LABEL: define double @f_fp_scalar_2(double %x)
+double f_fp_scalar_2(double x) { return x; }
+
+// CHECK-LABEL: define fp128 @f_fp_scalar_3(fp128 %x)
+long double f_fp_scalar_3(long double x) { return x; }
+
+// Empty structs or unions are ignored.
+
+struct empty_s {};
+
+// CHECK-LABEL: define void 

[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth marked 5 inline comments as done.
JonasToth added inline comments.



Comment at: docs/ReleaseNotes.rst:63
+
+  The usage of ``goto`` has been discouraged for a long time and is diagnosed
+  with this check.

Eugene.Zelenko wrote:
> I think will be good idea to reformulate this statement and its copy in 
> documentation. //diagnosed with this check// is tautological for any check.
Reformulated, is it ok now?



Comment at: docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst:6-7
+
+The usage of ``goto`` has been discouraged for a long time and is diagnosed
+with this check.
+

aaron.ballman wrote:
> This doesn't really help the user understand what's bad about goto or why it 
> should be diagnosed. You should expound a bit here.
Is it better now?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815



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


[PATCH] D40673: Add _Float128 as alias to __float128 to enable compilations on Fedora27/glibc2-26

2018-01-12 Thread Szabolcs Nagy via Phabricator via cfe-commits
nsz added a comment.

In https://reviews.llvm.org/D40673#973638, @efriedma wrote:

> > as this patch is committed clang is broken (cannot use glibc headers)
>
> This patch was supposed to *fix* compatibility with the glibc headers.  If it 
> doesn't, we should clearly revert it... but we need to figure out what we 
> need to do to be compatible first.
>
> From what I can see on this thread, we *must* define _Float128 on x86-64 
> Linux, and we *must not* define _Float128 for any other glibc target.  Is 
> that correct?  Or does it depend on the glibc version?


it is not clear to me from the original bug report what "fedora 27 workloads" 
break because of the lack of _Float128 type on x86.  The glibc headers refer to 
_Float128, but normal include should not break unless the compiler claims to be 
>=gcc-7 or somebody explicitly requested the _Float128 support.

if clang defines _Float128 then the headers "work" on x86 as in simple math.h 
include is not broken, but some macro definitions will use the f128 const 
suffix (e.g. FLT128_MAX) which won't cause much breakage now but in the future 
users will want to know whether they can use these macros or not.

so either clang have to introduce all these features that are used by glibc 
together or provide ways for users (and glibc) to figure out what is supported 
and what isn't.

on non-x86 targets a glibc fix can solve the problem such that they "work" on 
the same level as x86, i.e. no immediate build breakage on most code, but some 
features are not supported. i think that's the right way forward, but it's not 
clear if anybody has time to do the header changes in glibc before release (it 
has to be tested on several targets).

if glibc is released as is today then those non-x86 targets don't want a 
_Float128 definition in clang-6 that breaks any math.h include on a glibc-2.27 
system.

> (We have a bit of time before the 6.0 release, so we can adjust the behavior 
> here to make it work.  We probably don't want to try to add full _Float128 
> support on the branch, though.)




Repository:
  rC Clang

https://reviews.llvm.org/D40673



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


[PATCH] D41228: [ObjC] Enable __strong pointers in structs under ARC

2018-01-12 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/AST/Type.h:1148
+DK_objc_weak_lifetime,
+DK_c_struct_strong_field
   };

ahatanak wrote:
> rjmccall wrote:
> > I don't think you want to refer to the fact that the C struct specifically 
> > contains a __strong field here.  As we add more reasons, would we create a 
> > new enumerator for each?  What if a struct is non-trivial for multiple 
> > reasons?  Just say that it's a non-trivial C struct.
> I added an enumerator for DK_c_struct_strong_field since 
> CodeGenFunction::needsEHCleanup distinguishes between `__weak` and `__strong` 
> types. Is it not necessary to distinguish between a struct that has a 
> `__weak` field and a struct that has a `__strong` field but not a `__weak` 
> field? 
Oh, that's right.

I... hmm.  The problem is that that's really a special-case behavior, and we're 
designing a more general feature.  If we try to handle the special case in the 
first patch, we'll end up trivializing the general case, and that will permeate 
the design in unfortunate ways.

So I recommend that we *not* treat them separately right now; just emit 
cleanups for them unconditionally.  You're still planning to add support for 
`__weak` properties in a follow-up patch, right?  Once that's in, it will make 
more sense to carve out the `__strong`-only behavior as a special case.


https://reviews.llvm.org/D41228



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


[PATCH] D41999: Refactor handling of signext/zeroext in ABIArgInfo

2018-01-12 Thread Alex Bradbury via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322396: Refactor handling of signext/zeroext in ABIArgInfo 
(authored by asb, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41999

Files:
  include/clang/CodeGen/CGFunctionInfo.h
  lib/CodeGen/ABIInfo.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/TargetInfo.cpp

Index: include/clang/CodeGen/CGFunctionInfo.h
===
--- include/clang/CodeGen/CGFunctionInfo.h
+++ include/clang/CodeGen/CGFunctionInfo.h
@@ -95,6 +95,7 @@
   bool SRetAfterThis : 1;   // isIndirect()
   bool InReg : 1;   // isDirect() || isExtend() || isIndirect()
   bool CanBeFlattened: 1;   // isDirect()
+  bool SignExt : 1; // isExtend()
 
   bool canHavePaddingType() const {
 return isDirect() || isExtend() || isIndirect() || isExpand();
@@ -133,15 +134,38 @@
 AI.setInReg(true);
 return AI;
   }
-  static ABIArgInfo getExtend(llvm::Type *T = nullptr) {
+
+  static ABIArgInfo getSignExtend(QualType Ty, llvm::Type *T = nullptr) {
+assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
 auto AI = ABIArgInfo(Extend);
 AI.setCoerceToType(T);
 AI.setPaddingType(nullptr);
 AI.setDirectOffset(0);
+AI.setSignExt(true);
 return AI;
   }
-  static ABIArgInfo getExtendInReg(llvm::Type *T = nullptr) {
-auto AI = getExtend(T);
+
+  static ABIArgInfo getZeroExtend(QualType Ty, llvm::Type *T = nullptr) {
+assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
+auto AI = ABIArgInfo(Extend);
+AI.setCoerceToType(T);
+AI.setPaddingType(nullptr);
+AI.setDirectOffset(0);
+AI.setSignExt(false);
+return AI;
+  }
+
+  // ABIArgInfo will record the argument as being extended based on the sign
+  // of its type.
+  static ABIArgInfo getExtend(QualType Ty, llvm::Type *T = nullptr) {
+assert(Ty->isIntegralOrEnumerationType() && "Unexpected QualType");
+if (Ty->hasSignedIntegerRepresentation())
+  return getSignExtend(Ty, T);
+return getZeroExtend(Ty, T);
+  }
+
+  static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T = nullptr) {
+auto AI = getExtend(Ty, T);
 AI.setInReg(true);
 return AI;
   }
@@ -254,6 +278,15 @@
 DirectOffset = Offset;
   }
 
+  bool isSignExt() const {
+assert(isExtend() && "Invalid kind!");
+return SignExt;
+  }
+  void setSignExt(bool SExt) {
+assert(isExtend() && "Invalid kind!");
+SignExt = SExt;
+  }
+
   llvm::Type *getPaddingType() const {
 return (canHavePaddingType() ? PaddingType : nullptr);
   }
Index: lib/CodeGen/ABIInfo.h
===
--- lib/CodeGen/ABIInfo.h
+++ lib/CodeGen/ABIInfo.h
@@ -108,8 +108,6 @@
 virtual bool isHomogeneousAggregateSmallEnough(const Type *Base,
uint64_t Members) const;
 
-virtual bool shouldSignExtUnsignedType(QualType Ty) const;
-
 bool isHomogeneousAggregate(QualType Ty, const Type *,
 uint64_t ) const;
 
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1925,9 +1925,9 @@
   const ABIArgInfo  = FI.getReturnInfo();
   switch (RetAI.getKind()) {
   case ABIArgInfo::Extend:
-if (RetTy->hasSignedIntegerRepresentation())
+if (RetAI.isSignExt())
   RetAttrs.addAttribute(llvm::Attribute::SExt);
-else if (RetTy->hasUnsignedIntegerRepresentation())
+else
   RetAttrs.addAttribute(llvm::Attribute::ZExt);
 LLVM_FALLTHROUGH;
   case ABIArgInfo::Direct:
@@ -2006,14 +2006,10 @@
 // sense to do it here because parameters are so messed up.
 switch (AI.getKind()) {
 case ABIArgInfo::Extend:
-  if (ParamType->isSignedIntegerOrEnumerationType())
+  if (AI.isSignExt())
 Attrs.addAttribute(llvm::Attribute::SExt);
-  else if (ParamType->isUnsignedIntegerOrEnumerationType()) {
-if (getTypes().getABIInfo().shouldSignExtUnsignedType(ParamType))
-  Attrs.addAttribute(llvm::Attribute::SExt);
-else
-  Attrs.addAttribute(llvm::Attribute::ZExt);
-  }
+  else
+Attrs.addAttribute(llvm::Attribute::ZExt);
   LLVM_FALLTHROUGH;
 case ABIArgInfo::Direct:
   if (ArgNo == 0 && FI.isChainCall())
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -201,10 +201,6 @@
   return false;
 }
 
-bool ABIInfo::shouldSignExtUnsignedType(QualType Ty) const {
-  return false;
-}
-
 LLVM_DUMP_METHOD void ABIArgInfo::dump() const {
   raw_ostream  = llvm::errs();
   OS << "(ABIArgInfo Kind=";
@@ -682,8 +678,8 @@
   if (const EnumType *EnumTy = Ty->getAs())
 Ty = EnumTy->getDecl()->getIntegerType();
 
-  return (Ty->isPromotableIntegerType() ?

[PATCH] D41384: [analyzer] Suppress false positive warnings form security.insecureAPI.strcpy

2018-01-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp:517
+if (const auto *Array = dyn_cast(
+DeclRef->getDecl()->getType().getTypePtr())) {
+  unsigned long long ArraySize = Array->getSize().getLimitedValue();

leanil wrote:
> NoQ wrote:
> > This can be simplified to `const auto *Array = 
> > DeclRef->getType()->getAs()`.
> > `.getTypePtr()` is almost always redundant because of the fancy 
> > `operator->()` on `QualType`.
> Using `getAs` yielded: 
> > error: static assertion failed: ArrayType cannot be used with getAs!
> 
> 
Whoops, yeah, right, array types are the rare exception. It should be 
`ASTContext.getAsConstantArrayType()`, see the docs for `getAsArrayType()` for 
some explanation of why it was made this way. I guess we don't really care 
about these aspects, so your code is fine :)


https://reviews.llvm.org/D41384



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


[PATCH] D41384: [analyzer] Suppress false positive warnings form security.insecureAPI.strcpy

2018-01-12 Thread András Leitereg via Phabricator via cfe-commits
leanil marked 2 inline comments as done.
leanil added a comment.

In https://reviews.llvm.org/D41384#973851, @NoQ wrote:

> Do you have commit access or should someone else commit it for you?


I don't have, please commit it.




Comment at: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp:517
+if (const auto *Array = dyn_cast(
+DeclRef->getDecl()->getType().getTypePtr())) {
+  unsigned long long ArraySize = Array->getSize().getLimitedValue();

NoQ wrote:
> This can be simplified to `const auto *Array = 
> DeclRef->getType()->getAs()`.
> `.getTypePtr()` is almost always redundant because of the fancy 
> `operator->()` on `QualType`.
Using `getAs` yielded: 
> error: static assertion failed: ArrayType cannot be used with getAs!




https://reviews.llvm.org/D41384



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


[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 129677.
JonasToth marked 8 inline comments as done.
JonasToth added a comment.

- address review comments
- add better documentation with code examples


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815

Files:
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp
  clang-tidy/cppcoreguidelines/AvoidGotoCheck.h
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-avoid-goto.cpp

Index: test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-avoid-goto.cpp
@@ -0,0 +1,91 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-goto %t
+
+void noop() {}
+
+int main() {
+  noop();
+  goto jump_to_me;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  noop();
+
+jump_to_me:;
+
+jump_backwards:;
+  noop();
+  goto jump_backwards;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+  // CHECK-MESSAGES: [[@LINE-2]]:3: warning: do not jump backwards with 'goto'
+  // CHECK-MESSAGES: [[@LINE-5]]:1: note: label defined here
+
+  // Test the GNU extension https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
+some_label:;
+  void *dynamic_label = &_label;
+
+  // FIXME: Not detected
+  goto *dynamic_label;
+  // CHECK MESSAGES: [[@LINE-1]]:3: warning: avoid using 'goto' for flow control
+}
+
+void forward_jump_out_nested_loop() {
+  for (int i = 0; i < 10; ++i) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (i + j > 10)
+goto early_exit1;
+}
+noop();
+  }
+
+  for (int i = 0; i < 10; ++i) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit1;
+}
+noop();
+  }
+  // Jumping further results in error, because the variable declaration would
+  // be skipped.
+early_exit1:;
+
+  int i = 0;
+  while (true) {
+noop();
+while (true) {
+  noop();
+  if (i > 5)
+goto early_exit2;
+  i++;
+}
+noop();
+  }
+
+  while (true) {
+noop();
+for (int j = 0; j < 10; ++j) {
+  noop();
+  if (j > 5)
+goto early_exit2;
+}
+noop();
+  }
+
+early_exit2:;
+}
+
+void jump_out_backwards() {
+
+before_the_loop:
+  noop();
+
+  for (int i = 0; i < 10; ++i) {
+for (int j = 0; j < 10; ++j) {
+  if (i * j > 80)
+goto before_the_loop;
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: do not jump backwards with 'goto'
+  // CHECK-MESSAGES: [[@LINE-8]]:1: note: label defined here
+}
+  }
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -52,6 +52,7 @@
cert-msc30-c (redirects to cert-msc50-cpp) 
cert-msc50-cpp
cert-oop11-cpp (redirects to performance-move-constructor-init) 
+   cppcoreguidelines-avoid-goto
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
cppcoreguidelines-no-malloc
Index: docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-avoid-goto.rst
@@ -0,0 +1,50 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-goto
+
+cppcoreguidelines-avoid-goto
+
+
+The usage of ``goto`` for control flow is error prone and should be replaced
+with looping constructs. Only forward jumps in nested loops are accepted.
+
+This check implements `ES.76 `_ 
+from the CppCoreGuidelines and 
+`6.3.1 from High Integrity C++ `_.
+
+For more information on why to avoid programming 
+with ``goto`` you can read the famous paper `A Case against the GO TO Statement. `_.
+
+The check diagnoses ``goto`` for backward jumps in every language mode. These
+should be replaced with `C/C++` looping constructs.
+
+.. code-block:: c++
+
+  // Bad, handwritten for loop.
+  int i = 0;
+  // Jump label for the loop
+  loop_start:
+  do_some_operation();
+
+  if (i < 100) {
+++i;
+goto loop_start;
+  }
+
+  // Better
+  for(int i = 0; i < 100; ++i)
+do_some_operation();
+
+Modern C++ needs ``goto`` only to jump out of nested loops.
+
+.. code-block:: c++
+
+  for(int i = 0; i < 100; ++i) {
+for(int j = 0; j < 100; ++j) {
+  if (i * j > 500)
+

[PATCH] D41384: [analyzer] Suppress false positive warnings form security.insecureAPI.strcpy

2018-01-12 Thread András Leitereg via Phabricator via cfe-commits
leanil updated this revision to Diff 129676.
leanil marked an inline comment as done.
leanil added a comment.

Measure array size in bytes instead of elements.


https://reviews.llvm.org/D41384

Files:
  lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
  test/Analysis/security-syntax-checks.m


Index: test/Analysis/security-syntax-checks.m
===
--- test/Analysis/security-syntax-checks.m
+++ test/Analysis/security-syntax-checks.m
@@ -146,6 +146,16 @@
   strcpy(x, y); //expected-warning{{Call to function 'strcpy' is insecure as 
it does not provide bounding of the memory buffer. Replace unbounded copy 
functions with analogous functions that support length arguments such as 
'strlcpy'. CWE-119}}
 }
 
+void test_strcpy_2() {
+  char x[4];
+  strcpy(x, "abcd"); //expected-warning{{Call to function 'strcpy' is insecure 
as it does not provide bounding of the memory buffer. Replace unbounded copy 
functions with analogous functions that support length arguments such as 
'strlcpy'. CWE-119}}
+}
+
+void test_strcpy_safe() {
+  char x[5];
+  strcpy(x, "abcd");
+}
+
 //===--===
 // strcat()
 //===--===
Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -510,6 +510,17 @@
   if (!checkCall_strCommon(CE, FD))
 return;
 
+  const auto *Target = CE->getArg(0)->IgnoreImpCasts(),
+ *Source = CE->getArg(1)->IgnoreImpCasts();
+  if (const auto *DeclRef = dyn_cast(Target))
+if (const auto *Array = dyn_cast(DeclRef->getType())) {
+  uint64_t ArraySize = BR.getContext().getTypeSize(Array) / 8;
+  if (const auto *String = dyn_cast(Source)) {
+if (ArraySize >= String->getLength() + 1)
+  return;
+  }
+}
+
   // Issue a warning.
   PathDiagnosticLocation CELoc =
 PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);


Index: test/Analysis/security-syntax-checks.m
===
--- test/Analysis/security-syntax-checks.m
+++ test/Analysis/security-syntax-checks.m
@@ -146,6 +146,16 @@
   strcpy(x, y); //expected-warning{{Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119}}
 }
 
+void test_strcpy_2() {
+  char x[4];
+  strcpy(x, "abcd"); //expected-warning{{Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119}}
+}
+
+void test_strcpy_safe() {
+  char x[5];
+  strcpy(x, "abcd");
+}
+
 //===--===
 // strcat()
 //===--===
Index: lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
===
--- lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
@@ -510,6 +510,17 @@
   if (!checkCall_strCommon(CE, FD))
 return;
 
+  const auto *Target = CE->getArg(0)->IgnoreImpCasts(),
+ *Source = CE->getArg(1)->IgnoreImpCasts();
+  if (const auto *DeclRef = dyn_cast(Target))
+if (const auto *Array = dyn_cast(DeclRef->getType())) {
+  uint64_t ArraySize = BR.getContext().getTypeSize(Array) / 8;
+  if (const auto *String = dyn_cast(Source)) {
+if (ArraySize >= String->getLength() + 1)
+  return;
+  }
+}
+
   // Issue a warning.
   PathDiagnosticLocation CELoc =
 PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2018-01-12 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a comment.

Um, I now appear to be getting different results for running under QEMU doing 
it the proper way. I was previously rebuilding the failing test by hand and 
running under qemu. I don't believe I changed anything important, I'll have to 
take a longer look.

If you define an Executor for libunwind you can run the testsuite under QEMU, 
automagically.

I have:

  LIBUNWIND_EXECUTOR   
PrefixExecutor(['/home/sdardis/bin/qemu-mipsn32.sh'],LocalExecutor())

/home/sdardis/bin/qemu-mips32.sh for is a simple bash script:

  #!/bin/bash
  ~/mips-mti-linux-gnu/2016.05-06/bin/qemu-mipsn32 -L 
/home/snd-local/mips-mti-linux-gnu/2016.05-06/sysroot/mips-r2-hard/ -E 
LD_LIBRARY_PATH=/home/snd-local/mips-mti-linux-gnu/2016.05-06/mips-mti-linux-gnu/lib/mips-r2-hard/lib32/
 "$@"

Hope this helps.

Thanks for all the work you're putting into this.


https://reviews.llvm.org/D39074



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


[PATCH] D42005: [docs] Use monospace for PCH option flags

2018-01-12 Thread Brian Gesiak via Phabricator via cfe-commits
modocache created this revision.
modocache added reviewers: sepavloff, aaron.ballman.

Use monospace for option flags in the PCH section, instead of the
italics that were being used previously.

I believe these used to be links, for which single backticks would
have been appropriate, but since they were un-link-ified in
https://reviews.llvm.org/rL275560, I believe monospace is now more
appropriate, and so two backticks are needed.

Test Plan:
Build the `docs-clang-html` target and confirm the options are rendered
using monospace font.


Repository:
  rC Clang

https://reviews.llvm.org/D42005

Files:
  docs/UsersManual.rst


Index: docs/UsersManual.rst
===
--- docs/UsersManual.rst
+++ docs/UsersManual.rst
@@ -1075,7 +1075,7 @@
 Building a relocatable precompiled header requires two additional
 arguments. First, pass the ``--relocatable-pch`` flag to indicate that
 the resulting PCH file should be relocatable. Second, pass
-`-isysroot /path/to/build`, which makes all includes for your library
+``-isysroot /path/to/build``, which makes all includes for your library
 relative to the build directory. For example:
 
 .. code-block:: console
@@ -1085,9 +1085,9 @@
 When loading the relocatable PCH file, the various headers used in the
 PCH file are found from the system header root. For example, ``mylib.h``
 can be found in ``/usr/include/mylib.h``. If the headers are installed
-in some other system root, the `-isysroot` option can be used provide
+in some other system root, the ``-isysroot`` option can be used provide
 a different system root from which the headers will be based. For
-example, `-isysroot /Developer/SDKs/MacOSX10.4u.sdk` will look for
+example, ``-isysroot /Developer/SDKs/MacOSX10.4u.sdk`` will look for
 ``mylib.h`` in ``/Developer/SDKs/MacOSX10.4u.sdk/usr/include/mylib.h``.
 
 Relocatable precompiled headers are intended to be used in a limited


Index: docs/UsersManual.rst
===
--- docs/UsersManual.rst
+++ docs/UsersManual.rst
@@ -1075,7 +1075,7 @@
 Building a relocatable precompiled header requires two additional
 arguments. First, pass the ``--relocatable-pch`` flag to indicate that
 the resulting PCH file should be relocatable. Second, pass
-`-isysroot /path/to/build`, which makes all includes for your library
+``-isysroot /path/to/build``, which makes all includes for your library
 relative to the build directory. For example:
 
 .. code-block:: console
@@ -1085,9 +1085,9 @@
 When loading the relocatable PCH file, the various headers used in the
 PCH file are found from the system header root. For example, ``mylib.h``
 can be found in ``/usr/include/mylib.h``. If the headers are installed
-in some other system root, the `-isysroot` option can be used provide
+in some other system root, the ``-isysroot`` option can be used provide
 a different system root from which the headers will be based. For
-example, `-isysroot /Developer/SDKs/MacOSX10.4u.sdk` will look for
+example, ``-isysroot /Developer/SDKs/MacOSX10.4u.sdk`` will look for
 ``mylib.h`` in ``/Developer/SDKs/MacOSX10.4u.sdk/usr/include/mylib.h``.
 
 Relocatable precompiled headers are intended to be used in a limited
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r322390 - [Lex] Avoid out-of-bounds dereference in LexAngledStringLiteral.

2018-01-12 Thread Volodymyr Sapsai via cfe-commits
Hans, I am nominating this change to be merged into 6.0.0 release branch.

Thanks,
Volodymyr

> On Jan 12, 2018, at 10:54, Volodymyr Sapsai via cfe-commits 
>  wrote:
> 
> Author: vsapsai
> Date: Fri Jan 12 10:54:35 2018
> New Revision: 322390
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=322390=rev
> Log:
> [Lex] Avoid out-of-bounds dereference in LexAngledStringLiteral.
> 
> Fix makes the loop in LexAngledStringLiteral more like the loops in
> LexStringLiteral, LexCharConstant. When we skip a character after
> backslash, we need to check if we reached the end of the file instead of
> reading the next character unconditionally.
> 
> Discovered by OSS-Fuzz:
> https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3832
> 
> rdar://problem/35572754
> 
> Reviewers: arphaman, kcc, rsmith, dexonsmith
> 
> Reviewed By: rsmith, dexonsmith
> 
> Subscribers: cfe-commits, rsmith, dexonsmith
> 
> Differential Revision: https://reviews.llvm.org/D41423
> 
> Added:
>cfe/trunk/test/Lexer/null-character-in-literal.c   (with props)
> Modified:
>cfe/trunk/lib/Lex/Lexer.cpp
>cfe/trunk/unittests/Lex/LexerTest.cpp
> 
> Modified: cfe/trunk/lib/Lex/Lexer.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=322390=322389=322390=diff
> ==
> --- cfe/trunk/lib/Lex/Lexer.cpp (original)
> +++ cfe/trunk/lib/Lex/Lexer.cpp Fri Jan 12 10:54:35 2018
> @@ -2009,18 +2009,21 @@ bool Lexer::LexAngledStringLiteral(Token
>   const char *AfterLessPos = CurPtr;
>   char C = getAndAdvanceChar(CurPtr, Result);
>   while (C != '>') {
> -// Skip escaped characters.
> -if (C == '\\' && CurPtr < BufferEnd) {
> -  // Skip the escaped character.
> -  getAndAdvanceChar(CurPtr, Result);
> -} else if (C == '\n' || C == '\r' || // Newline.
> -   (C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
> -   isCodeCompletionPoint(CurPtr-1 {
> +// Skip escaped characters.  Escaped newlines will already be processed 
> by
> +// getAndAdvanceChar.
> +if (C == '\\')
> +  C = getAndAdvanceChar(CurPtr, Result);
> +
> +if (C == '\n' || C == '\r' || // Newline.
> +(C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
> +isCodeCompletionPoint(CurPtr-1 {
>   // If the filename is unterminated, then it must just be a lone <
>   // character.  Return this as such.
>   FormTokenWithChars(Result, AfterLessPos, tok::less);
>   return true;
> -} else if (C == 0) {
> +}
> +
> +if (C == 0) {
>   NulCharacter = CurPtr-1;
> }
> C = getAndAdvanceChar(CurPtr, Result);
> 
> Added: cfe/trunk/test/Lexer/null-character-in-literal.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/null-character-in-literal.c?rev=322390=auto
> ==
> Binary file - no diff available.
> 
> Propchange: cfe/trunk/test/Lexer/null-character-in-literal.c
> --
>svn:mime-type = application/octet-stream
> 
> Modified: cfe/trunk/unittests/Lex/LexerTest.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/LexerTest.cpp?rev=322390=322389=322390=diff
> ==
> --- cfe/trunk/unittests/Lex/LexerTest.cpp (original)
> +++ cfe/trunk/unittests/Lex/LexerTest.cpp Fri Jan 12 10:54:35 2018
> @@ -475,6 +475,8 @@ TEST_F(LexerTest, GetBeginningOfTokenWit
> 
> TEST_F(LexerTest, AvoidPastEndOfStringDereference) {
>   EXPECT_TRUE(Lex("  //  \\\n").empty());
> +  EXPECT_TRUE(Lex("#include <").empty());
> +  EXPECT_TRUE(Lex("#include <\n").empty());
> }
> 
> TEST_F(LexerTest, StringizingRasString) {
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


r322393 - [OPENMP] Replace calls of getAssociatedStmt().

2018-01-12 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Jan 12 11:39:11 2018
New Revision: 322393

URL: http://llvm.org/viewvc/llvm-project?rev=322393=rev
Log:
[OPENMP] Replace calls of getAssociatedStmt().

getAssociatedStmt() returns the outermost captured statement for the
OpenMP directive. It may return incorrect region in case of combined
constructs. Reworked the code to reduce the number of calls of
getAssociatedStmt() and used getInnermostCapturedStmt() and
getCapturedStmt() functions instead.
In case of firstprivate variables it may lead to an extra allocas
generation for private copies even if the variable is passed by value
into outlined function and could be used directly as private copy.

Modified:
cfe/trunk/include/clang/AST/StmtOpenMP.h
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/OpenMP/nvptx_target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_firstprivate_codegen.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_firstprivate_codegen.cpp

cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_firstprivate_codegen.cpp

Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=322393=322392=322393=diff
==
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Fri Jan 12 11:39:11 2018
@@ -222,6 +222,25 @@ public:
 llvm_unreachable("Incorrect RegionKind specified for directive.");
   }
 
+  /// Get innermost captured statement for the construct.
+  CapturedStmt *getInnermostCapturedStmt() {
+assert(hasAssociatedStmt() && getAssociatedStmt() &&
+   "Must have associated statement.");
+SmallVector CaptureRegions;
+getOpenMPCaptureRegions(CaptureRegions, getDirectiveKind());
+assert(!CaptureRegions.empty() &&
+   "At least one captured statement must be provided.");
+auto *CS = cast(getAssociatedStmt());
+for (unsigned Level = CaptureRegions.size(); Level > 1; --Level)
+  CS = cast(CS->getCapturedStmt());
+return CS;
+  }
+
+  const CapturedStmt *getInnermostCapturedStmt() const {
+return const_cast(this)
+->getInnermostCapturedStmt();
+  }
+
   OpenMPDirectiveKind getDirectiveKind() const { return Kind; }
 
   static bool classof(const Stmt *S) {
@@ -903,9 +922,8 @@ public:
   }
   const Stmt *getBody() const {
 // This relies on the loop form is already checked by Sema.
-const Stmt *Body = getAssociatedStmt()->IgnoreContainers(true);
-while(const auto *CS = dyn_cast(Body))
-  Body = CS->getCapturedStmt();
+const Stmt *Body =
+getInnermostCapturedStmt()->getCapturedStmt()->IgnoreContainers();
 Body = cast(Body)->getBody();
 for (unsigned Cnt = 1; Cnt < CollapsedNum; ++Cnt) {
   Body = Body->IgnoreContainers();

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=322393=322392=322393=diff
==
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Jan 12 11:39:11 2018
@@ -1034,12 +1034,8 @@ void StmtPrinter::PrintOMPExecutableDire
   OS << ' ';
 }
   OS << "\n";
-  if (S->hasAssociatedStmt() && S->getAssociatedStmt() && !ForceNoStmt) {
-assert(isa(S->getAssociatedStmt()) &&
-   "Expected captured statement!");
-Stmt *CS = cast(S->getAssociatedStmt())->getCapturedStmt();
-PrintStmt(CS);
-  }
+  if (!ForceNoStmt && S->hasAssociatedStmt())
+PrintStmt(S->getInnermostCapturedStmt()->getCapturedStmt());
 }
 
 void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) {
@@ -1142,7 +1138,7 @@ void StmtPrinter::VisitOMPFlushDirective
 
 void StmtPrinter::VisitOMPOrderedDirective(OMPOrderedDirective *Node) {
   Indent() << "#pragma omp ordered ";
-  PrintOMPExecutableDirective(Node);
+  PrintOMPExecutableDirective(Node, Node->hasClausesOfKind());
 }
 
 void StmtPrinter::VisitOMPAtomicDirective(OMPAtomicDirective *Node) {

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=322393=322392=322393=diff
==
--- 

[PATCH] D42004: [Driver] Suggest valid integrated tools

2018-01-12 Thread Brian Gesiak via Phabricator via cfe-commits
modocache created this revision.
modocache added reviewers: sepavloff, bkramer, phosek.

There are only two valid integrated Clang driver tools: `-cc1` and
`-cc1as`. If a user asks for an unknown tool, such as `-cc1asphalt`,
an error message is displayed to indicate that there is no such tool,
but the message doesn't indicate what the valid options are.

Include the valid options in the error message.

Test Plan: `check-clang`


Repository:
  rC Clang

https://reviews.llvm.org/D42004

Files:
  test/Driver/unknown-arg.c
  tools/driver/driver.cpp


Index: tools/driver/driver.cpp
===
--- tools/driver/driver.cpp
+++ tools/driver/driver.cpp
@@ -311,7 +311,8 @@
 return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
 
   // Reject unknown tools.
-  llvm::errs() << "error: unknown integrated tool '" << Tool << "'\n";
+  llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
+   << "Valid tools include '-cc1' and '-cc1as'.\n";
   return 1;
 }
 
Index: test/Driver/unknown-arg.c
===
--- test/Driver/unknown-arg.c
+++ test/Driver/unknown-arg.c
@@ -12,6 +12,8 @@
 // RUN: FileCheck %s --check-prefix=CL-ERROR-DID-YOU-MEAN
 // RUN: %clang_cl -cake-is-lie -%0 -%d - -munknown-to-clang-option 
-print-stats -funknown-to-clang-option -c -Wno-unknown-argument -### -- %s 2>&1 
| \
 // RUN: FileCheck %s --check-prefix=SILENT
+// RUN: not %clang -cc1asphalt -help 2>&1 | \
+// RUN: FileCheck %s --check-prefix=UNKNOWN-INTEGRATED
 
 // CHECK: error: unknown argument: '-cake-is-lie'
 // CHECK: error: unknown argument: '-%0'
@@ -41,6 +43,7 @@
 // CL-ERROR-DID-YOU-MEAN: error: unknown argument ignored in clang-cl '-helo' 
(did you mean '-help'?)
 // SILENT-NOT: error:
 // SILENT-NOT: warning:
+// UNKNOWN-INTEGRATED: error: unknown integrated tool 'asphalt'. Valid tools 
include '-cc1' and '-cc1as'.
 
 
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s


Index: tools/driver/driver.cpp
===
--- tools/driver/driver.cpp
+++ tools/driver/driver.cpp
@@ -311,7 +311,8 @@
 return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
 
   // Reject unknown tools.
-  llvm::errs() << "error: unknown integrated tool '" << Tool << "'\n";
+  llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
+   << "Valid tools include '-cc1' and '-cc1as'.\n";
   return 1;
 }
 
Index: test/Driver/unknown-arg.c
===
--- test/Driver/unknown-arg.c
+++ test/Driver/unknown-arg.c
@@ -12,6 +12,8 @@
 // RUN: FileCheck %s --check-prefix=CL-ERROR-DID-YOU-MEAN
 // RUN: %clang_cl -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Wno-unknown-argument -### -- %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=SILENT
+// RUN: not %clang -cc1asphalt -help 2>&1 | \
+// RUN: FileCheck %s --check-prefix=UNKNOWN-INTEGRATED
 
 // CHECK: error: unknown argument: '-cake-is-lie'
 // CHECK: error: unknown argument: '-%0'
@@ -41,6 +43,7 @@
 // CL-ERROR-DID-YOU-MEAN: error: unknown argument ignored in clang-cl '-helo' (did you mean '-help'?)
 // SILENT-NOT: error:
 // SILENT-NOT: warning:
+// UNKNOWN-INTEGRATED: error: unknown integrated tool 'asphalt'. Valid tools include '-cc1' and '-cc1as'.
 
 
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41815: [clang-tidy] implement check for goto

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth marked 3 inline comments as done.
JonasToth added inline comments.



Comment at: clang-tidy/cppcoreguidelines/AvoidGotoCheck.cpp:20
+
+AST_MATCHER(GotoStmt, isForwardJumping) {
+

lebedev.ri wrote:
> JonasToth wrote:
> > lebedev.ri wrote:
> > > It would be nice to have it in standard ASTMatchers, i believe it will be 
> > > useful for `else-after-return` check.
> > > Though the ASTMatchers are stuck due to the doc-dumping script being 
> > > 'broken' (see D41455)
> > Yes. The GNU extension goto does not have ASTMatcher yet, so i will pack 
> > these together in a review. What do you think how long the ASTMatcher issue 
> > will be there? Maybe it could be done after that check lands?
> > Maybe it could be done after that check lands?
> 
> Yes, absolutely. I did not meant that as a blocker here.
On my todo list.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41815



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


[PATCH] D41423: [Lex] Avoid out-of-bounds dereference in LexAngledStringLiteral.

2018-01-12 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322390: [Lex] Avoid out-of-bounds dereference in 
LexAngledStringLiteral. (authored by vsapsai, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41423?vs=129379=129666#toc

Repository:
  rC Clang

https://reviews.llvm.org/D41423

Files:
  lib/Lex/Lexer.cpp
  test/Lexer/null-character-in-literal.c
  unittests/Lex/LexerTest.cpp


Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -2009,18 +2009,21 @@
   const char *AfterLessPos = CurPtr;
   char C = getAndAdvanceChar(CurPtr, Result);
   while (C != '>') {
-// Skip escaped characters.
-if (C == '\\' && CurPtr < BufferEnd) {
-  // Skip the escaped character.
-  getAndAdvanceChar(CurPtr, Result);
-} else if (C == '\n' || C == '\r' || // Newline.
-   (C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
-   isCodeCompletionPoint(CurPtr-1 {
+// Skip escaped characters.  Escaped newlines will already be processed by
+// getAndAdvanceChar.
+if (C == '\\')
+  C = getAndAdvanceChar(CurPtr, Result);
+
+if (C == '\n' || C == '\r' || // Newline.
+(C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
+isCodeCompletionPoint(CurPtr-1 {
   // If the filename is unterminated, then it must just be a lone <
   // character.  Return this as such.
   FormTokenWithChars(Result, AfterLessPos, tok::less);
   return true;
-} else if (C == 0) {
+}
+
+if (C == 0) {
   NulCharacter = CurPtr-1;
 }
 C = getAndAdvanceChar(CurPtr, Result);
Index: unittests/Lex/LexerTest.cpp
===
--- unittests/Lex/LexerTest.cpp
+++ unittests/Lex/LexerTest.cpp
@@ -475,6 +475,8 @@
 
 TEST_F(LexerTest, AvoidPastEndOfStringDereference) {
   EXPECT_TRUE(Lex("  //  \\\n").empty());
+  EXPECT_TRUE(Lex("#include <").empty());
+  EXPECT_TRUE(Lex("#include <\n").empty());
 }
 
 TEST_F(LexerTest, StringizingRasString) {


Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -2009,18 +2009,21 @@
   const char *AfterLessPos = CurPtr;
   char C = getAndAdvanceChar(CurPtr, Result);
   while (C != '>') {
-// Skip escaped characters.
-if (C == '\\' && CurPtr < BufferEnd) {
-  // Skip the escaped character.
-  getAndAdvanceChar(CurPtr, Result);
-} else if (C == '\n' || C == '\r' || // Newline.
-   (C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
-   isCodeCompletionPoint(CurPtr-1 {
+// Skip escaped characters.  Escaped newlines will already be processed by
+// getAndAdvanceChar.
+if (C == '\\')
+  C = getAndAdvanceChar(CurPtr, Result);
+
+if (C == '\n' || C == '\r' || // Newline.
+(C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
+isCodeCompletionPoint(CurPtr-1 {
   // If the filename is unterminated, then it must just be a lone <
   // character.  Return this as such.
   FormTokenWithChars(Result, AfterLessPos, tok::less);
   return true;
-} else if (C == 0) {
+}
+
+if (C == 0) {
   NulCharacter = CurPtr-1;
 }
 C = getAndAdvanceChar(CurPtr, Result);
Index: unittests/Lex/LexerTest.cpp
===
--- unittests/Lex/LexerTest.cpp
+++ unittests/Lex/LexerTest.cpp
@@ -475,6 +475,8 @@
 
 TEST_F(LexerTest, AvoidPastEndOfStringDereference) {
   EXPECT_TRUE(Lex("  //  \\\n").empty());
+  EXPECT_TRUE(Lex("#include <").empty());
+  EXPECT_TRUE(Lex("#include <\n").empty());
 }
 
 TEST_F(LexerTest, StringizingRasString) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322390 - [Lex] Avoid out-of-bounds dereference in LexAngledStringLiteral.

2018-01-12 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Jan 12 10:54:35 2018
New Revision: 322390

URL: http://llvm.org/viewvc/llvm-project?rev=322390=rev
Log:
[Lex] Avoid out-of-bounds dereference in LexAngledStringLiteral.

Fix makes the loop in LexAngledStringLiteral more like the loops in
LexStringLiteral, LexCharConstant. When we skip a character after
backslash, we need to check if we reached the end of the file instead of
reading the next character unconditionally.

Discovered by OSS-Fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3832

rdar://problem/35572754

Reviewers: arphaman, kcc, rsmith, dexonsmith

Reviewed By: rsmith, dexonsmith

Subscribers: cfe-commits, rsmith, dexonsmith

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

Added:
cfe/trunk/test/Lexer/null-character-in-literal.c   (with props)
Modified:
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/unittests/Lex/LexerTest.cpp

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=322390=322389=322390=diff
==
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Fri Jan 12 10:54:35 2018
@@ -2009,18 +2009,21 @@ bool Lexer::LexAngledStringLiteral(Token
   const char *AfterLessPos = CurPtr;
   char C = getAndAdvanceChar(CurPtr, Result);
   while (C != '>') {
-// Skip escaped characters.
-if (C == '\\' && CurPtr < BufferEnd) {
-  // Skip the escaped character.
-  getAndAdvanceChar(CurPtr, Result);
-} else if (C == '\n' || C == '\r' || // Newline.
-   (C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
-   isCodeCompletionPoint(CurPtr-1 {
+// Skip escaped characters.  Escaped newlines will already be processed by
+// getAndAdvanceChar.
+if (C == '\\')
+  C = getAndAdvanceChar(CurPtr, Result);
+
+if (C == '\n' || C == '\r' || // Newline.
+(C == 0 && (CurPtr-1 == BufferEnd ||  // End of file.
+isCodeCompletionPoint(CurPtr-1 {
   // If the filename is unterminated, then it must just be a lone <
   // character.  Return this as such.
   FormTokenWithChars(Result, AfterLessPos, tok::less);
   return true;
-} else if (C == 0) {
+}
+
+if (C == 0) {
   NulCharacter = CurPtr-1;
 }
 C = getAndAdvanceChar(CurPtr, Result);

Added: cfe/trunk/test/Lexer/null-character-in-literal.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/null-character-in-literal.c?rev=322390=auto
==
Binary file - no diff available.

Propchange: cfe/trunk/test/Lexer/null-character-in-literal.c
--
svn:mime-type = application/octet-stream

Modified: cfe/trunk/unittests/Lex/LexerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/LexerTest.cpp?rev=322390=322389=322390=diff
==
--- cfe/trunk/unittests/Lex/LexerTest.cpp (original)
+++ cfe/trunk/unittests/Lex/LexerTest.cpp Fri Jan 12 10:54:35 2018
@@ -475,6 +475,8 @@ TEST_F(LexerTest, GetBeginningOfTokenWit
 
 TEST_F(LexerTest, AvoidPastEndOfStringDereference) {
   EXPECT_TRUE(Lex("  //  \\\n").empty());
+  EXPECT_TRUE(Lex("#include <").empty());
+  EXPECT_TRUE(Lex("#include <\n").empty());
 }
 
 TEST_F(LexerTest, StringizingRasString) {


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


[PATCH] D42001: [Driver] Add "did you mean?" suggestions to -cc1as

2018-01-12 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D42001



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


[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2018-01-12 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a comment.

This was libunwind's test suite:

  Compiled test failed unexpectedly!
  
  Testing Time: 0.53s
  
  Failing Tests (1):
  libunwind :: libunwind_02.pass.cpp
  
Expected Passes: 3
Unexpected Failures: 1 

The hacky patch I used to test n32:

  --- a/test/libunwind/test/config.py
  +++ b/test/libunwind/test/config.py
  @@ -48,6 +48,8 @@ class Configuration(LibcxxConfiguration):
   # Stack unwinding tests need unwinding tables and these are not
   # generated by default on all Targets.
   self.cxx.compile_flags += ['-funwind-tables']
  +self.cxx.compile_flags += ['-mabi=n33']
  +self.cxx.link_flags += ['-mabi=n32']
   if not self.get_lit_bool('enable_threads', True):
   self.cxx.compile_flags += ['-D_LIBUNWIND_HAS_NO_THREADS']
   self.config.available_features.add('libunwind-no-threads')


https://reviews.llvm.org/D39074



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


[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2018-01-12 Thread John Baldwin via Phabricator via cfe-commits
bsdjhb added a comment.

To be clear, are you getting the failure running libunwind's test suite or your 
own test?  I've managed to get libunwind to cross-compile for me using GCC 
6.3.0 on FreeBSD for O32, N32, and N64, but only to build the library, not the 
tests.  I've been running a simple C++ test program (which is using a patched 
libunwind along with libc++ as it's C++ runtime) for testing.  The program uses 
_Unwind_Backtrace() as well as throws a couple of C++ exceptions with catch 
handlers that print out the values thrown.  If you are able to cross-build the 
libunwind tests and then run them under qemu I'd appreciate a pointer to get 
that working as I'd be happier running libunwind's tests than my own.


https://reviews.llvm.org/D39074



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


[PATCH] D41228: [ObjC] Enable __strong pointers in structs under ARC

2018-01-12 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: include/clang/AST/Type.h:1148
+DK_objc_weak_lifetime,
+DK_c_struct_strong_field
   };

rjmccall wrote:
> I don't think you want to refer to the fact that the C struct specifically 
> contains a __strong field here.  As we add more reasons, would we create a 
> new enumerator for each?  What if a struct is non-trivial for multiple 
> reasons?  Just say that it's a non-trivial C struct.
I added an enumerator for DK_c_struct_strong_field since 
CodeGenFunction::needsEHCleanup distinguishes between `__weak` and `__strong` 
types. Is it not necessary to distinguish between a struct that has a `__weak` 
field and a struct that has a `__strong` field but not a `__weak` field? 


https://reviews.llvm.org/D41228



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


[PATCH] D41996: [clangd] Code completion uses Sema for NS-level things in the current file.

2018-01-12 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322387: [clangd] Code completion uses Sema for NS-level 
things in the current file. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D41996?vs=129637=129659#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41996

Files:
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  clang-tools-extra/trunk/clangd/index/FileIndex.cpp
  clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Index: clang-tools-extra/trunk/clangd/CodeComplete.cpp
===
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp
@@ -642,8 +642,10 @@
   Result.IncludeGlobals = IncludeGlobals;
   Result.IncludeBriefComments = IncludeBriefComments;
 
-  // Enable index-based code completion when Index is provided.
-  Result.IncludeNamespaceLevelDecls = !Index;
+  // When an is used, Sema is responsible for completing the main file,
+  // the index can provide results from the preamble.
+  // Tell Sema not to deserialize the preamble to look for results.
+  Result.LoadExternal = !Index;
 
   return Result;
 }
Index: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
===
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp
@@ -20,6 +20,8 @@
  std::shared_ptr PP,
  llvm::ArrayRef Decls) {
   SymbolCollector::Options CollectorOpts;
+  // Code completion gets main-file results from Sema.
+  // But we leave this option on because features like go-to-definition want it.
   CollectorOpts.IndexMainFiles = true;
   auto Collector = std::make_shared(std::move(CollectorOpts));
   Collector->setPreprocessor(std::move(PP));
Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
@@ -57,6 +57,7 @@
 using ::testing::Each;
 using ::testing::ElementsAre;
 using ::testing::Not;
+using ::testing::UnorderedElementsAre;
 
 class IgnoreDiagnostics : public DiagnosticsConsumer {
   void
@@ -104,7 +105,7 @@
   /*StorePreamblesInMemory=*/true);
   auto File = getVirtualTestFilePath("foo.cpp");
   Annotations Test(Text);
-  Server.addDocument(Context::empty(), File, Test.code());
+  Server.addDocument(Context::empty(), File, Test.code()).wait();
   auto CompletionList =
   Server.codeComplete(Context::empty(), File, Test.point(), Opts)
   .get()
@@ -506,11 +507,11 @@
   Opts.Index = nullptr;
 
   auto Results = completions(R"cpp(
-  namespace ns { class No {}; }
+  namespace ns { class Local {}; }
   void f() { ns::^ }
   )cpp",
  Opts);
-  EXPECT_THAT(Results.items, Has("No"));
+  EXPECT_THAT(Results.items, Has("Local"));
 }
 
 TEST(CompletionTest, StaticAndDynamicIndex) {
@@ -538,13 +539,13 @@
   Opts.Index = I.get();
 
   auto Results = completions(R"cpp(
-  namespace ns { class No {}; }
+  namespace ns { int local; }
   void f() { ns::^ }
   )cpp",
  Opts);
   EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
   EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
-  EXPECT_THAT(Results.items, Not(Has("No")));
+  EXPECT_THAT(Results.items, Has("local"));
 }
 
 TEST(CompletionTest, IndexBasedWithFilter) {
@@ -585,6 +586,41 @@
   EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
 }
 
+TEST(CompletionTest, IndexSuppressesPreambleCompletions) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true);
+
+  FS.Files[getVirtualTestFilePath("bar.h")] =
+  R"cpp(namespace ns { int preamble; })cpp";
+  auto File = getVirtualTestFilePath("foo.cpp");
+  Annotations Test(R"cpp(
+  #include "bar.h"
+  namespace ns { int local; }
+  void f() { ns::^ }
+  )cpp");
+  Server.addDocument(Context::empty(), File, Test.code()).wait();
+  clangd::CodeCompleteOptions Opts = {};
+
+  auto WithoutIndex =
+  Server.codeComplete(Context::empty(), File, Test.point(), Opts)
+  .get()
+  .second.Value;
+  EXPECT_THAT(WithoutIndex.items,
+  UnorderedElementsAre(Named("local"), Named("preamble")));
+
+  auto I = simpleIndexFromSymbols({{"ns::index", index::SymbolKind::Variable}});
+  Opts.Index = I.get();
+  auto WithIndex =
+  Server.codeComplete(Context::empty(), File, Test.point(), Opts)
+  .get()
+  

[clang-tools-extra] r322387 - [clangd] Code completion uses Sema for NS-level things in the current file.

2018-01-12 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Jan 12 10:30:08 2018
New Revision: 322387

URL: http://llvm.org/viewvc/llvm-project?rev=322387=rev
Log:
[clangd] Code completion uses Sema for NS-level things in the current file.

Summary:
To stay fast, it avoids deserializing anything outside the current file, by
disabling the LoadExternal code completion option added in r322377, when the
index is enabled.

Reviewers: hokein

Subscribers: klimek, ilya-biryukov, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=322387=322386=322387=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Jan 12 10:30:08 2018
@@ -642,8 +642,10 @@ clang::CodeCompleteOptions CodeCompleteO
   Result.IncludeGlobals = IncludeGlobals;
   Result.IncludeBriefComments = IncludeBriefComments;
 
-  // Enable index-based code completion when Index is provided.
-  Result.IncludeNamespaceLevelDecls = !Index;
+  // When an is used, Sema is responsible for completing the main file,
+  // the index can provide results from the preamble.
+  // Tell Sema not to deserialize the preamble to look for results.
+  Result.LoadExternal = !Index;
 
   return Result;
 }

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=322387=322386=322387=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Fri Jan 12 10:30:08 2018
@@ -20,6 +20,8 @@ std::unique_ptr indexAST(AST
  std::shared_ptr PP,
  llvm::ArrayRef Decls) {
   SymbolCollector::Options CollectorOpts;
+  // Code completion gets main-file results from Sema.
+  // But we leave this option on because features like go-to-definition want 
it.
   CollectorOpts.IndexMainFiles = true;
   auto Collector = std::make_shared(std::move(CollectorOpts));
   Collector->setPreprocessor(std::move(PP));

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=322387=322386=322387=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri Jan 12 
10:30:08 2018
@@ -57,6 +57,7 @@ using ::testing::Contains;
 using ::testing::Each;
 using ::testing::ElementsAre;
 using ::testing::Not;
+using ::testing::UnorderedElementsAre;
 
 class IgnoreDiagnostics : public DiagnosticsConsumer {
   void
@@ -104,7 +105,7 @@ CompletionList completions(StringRef Tex
   /*StorePreamblesInMemory=*/true);
   auto File = getVirtualTestFilePath("foo.cpp");
   Annotations Test(Text);
-  Server.addDocument(Context::empty(), File, Test.code());
+  Server.addDocument(Context::empty(), File, Test.code()).wait();
   auto CompletionList =
   Server.codeComplete(Context::empty(), File, Test.point(), Opts)
   .get()
@@ -506,11 +507,11 @@ TEST(CompletionTest, NoIndex) {
   Opts.Index = nullptr;
 
   auto Results = completions(R"cpp(
-  namespace ns { class No {}; }
+  namespace ns { class Local {}; }
   void f() { ns::^ }
   )cpp",
  Opts);
-  EXPECT_THAT(Results.items, Has("No"));
+  EXPECT_THAT(Results.items, Has("Local"));
 }
 
 TEST(CompletionTest, StaticAndDynamicIndex) {
@@ -538,13 +539,13 @@ TEST(CompletionTest, SimpleIndexBased) {
   Opts.Index = I.get();
 
   auto Results = completions(R"cpp(
-  namespace ns { class No {}; }
+  namespace ns { int local; }
   void f() { ns::^ }
   )cpp",
  Opts);
   EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
   EXPECT_THAT(Results.items, Has("foo", CompletionItemKind::Function));
-  EXPECT_THAT(Results.items, Not(Has("No")));
+  EXPECT_THAT(Results.items, Has("local"));
 }
 
 TEST(CompletionTest, IndexBasedWithFilter) {
@@ -585,6 +586,41 @@ TEST(CompletionTest, FullyQualifiedScope
   EXPECT_THAT(Results.items, Has("XYZ", CompletionItemKind::Class));
 }
 
+TEST(CompletionTest, IndexSuppressesPreambleCompletions) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  

[PATCH] D42001: [Driver] Add "did you mean?" suggestions to -cc1as

2018-01-12 Thread Brian Gesiak via Phabricator via cfe-commits
modocache created this revision.
modocache added reviewers: v.g.vassilev, bruno.

In https://reviews.llvm.org/D41733, the driver was modified such that,
when a user provided a mispelled option such as `-hel`, it would
suggest a valid option with a nearby edit distance: "did you mean
'-help'?".

Add these suggestions to invocations of `clang -cc1as` as well.

Test Plan: `check-clang`


Repository:
  rC Clang

https://reviews.llvm.org/D42001

Files:
  test/Driver/unknown-arg.c
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -181,7 +181,13 @@
 
   // Issue errors on unknown arguments.
   for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
-Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
+auto ArgString = A->getAsString(Args);
+std::string Nearest;
+if (OptTbl->findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
+  Diags.Report(diag::err_drv_unknown_argument) << ArgString;
+else
+  Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
+  << ArgString << Nearest;
 Success = false;
   }
 
Index: test/Driver/unknown-arg.c
===
--- test/Driver/unknown-arg.c
+++ test/Driver/unknown-arg.c
@@ -12,6 +12,8 @@
 // RUN: FileCheck %s --check-prefix=CL-ERROR-DID-YOU-MEAN
 // RUN: %clang_cl -cake-is-lie -%0 -%d - -munknown-to-clang-option 
-print-stats -funknown-to-clang-option -c -Wno-unknown-argument -### -- %s 2>&1 
| \
 // RUN: FileCheck %s --check-prefix=SILENT
+// RUN: not %clang -cc1as -hell --version -debug-info-macros 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CC1AS-DID-YOU-MEAN
 
 // CHECK: error: unknown argument: '-cake-is-lie'
 // CHECK: error: unknown argument: '-%0'
@@ -41,6 +43,9 @@
 // CL-ERROR-DID-YOU-MEAN: error: unknown argument ignored in clang-cl '-helo' 
(did you mean '-help'?)
 // SILENT-NOT: error:
 // SILENT-NOT: warning:
+// CC1AS-DID-YOU-MEAN: error: unknown argument '-hell', did you mean '-help'?
+// CC1AS-DID-YOU-MEAN: error: unknown argument '--version', did you mean 
'-version'?
+// CC1AS-DID-YOU-MEAN: error: unknown argument '-debug-info-macros', did you 
mean '-debug-info-macro'?
 
 
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck 
--check-prefix=IGNORED %s


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -181,7 +181,13 @@
 
   // Issue errors on unknown arguments.
   for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
-Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
+auto ArgString = A->getAsString(Args);
+std::string Nearest;
+if (OptTbl->findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
+  Diags.Report(diag::err_drv_unknown_argument) << ArgString;
+else
+  Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
+  << ArgString << Nearest;
 Success = false;
   }
 
Index: test/Driver/unknown-arg.c
===
--- test/Driver/unknown-arg.c
+++ test/Driver/unknown-arg.c
@@ -12,6 +12,8 @@
 // RUN: FileCheck %s --check-prefix=CL-ERROR-DID-YOU-MEAN
 // RUN: %clang_cl -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Wno-unknown-argument -### -- %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=SILENT
+// RUN: not %clang -cc1as -hell --version -debug-info-macros 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CC1AS-DID-YOU-MEAN
 
 // CHECK: error: unknown argument: '-cake-is-lie'
 // CHECK: error: unknown argument: '-%0'
@@ -41,6 +43,9 @@
 // CL-ERROR-DID-YOU-MEAN: error: unknown argument ignored in clang-cl '-helo' (did you mean '-help'?)
 // SILENT-NOT: error:
 // SILENT-NOT: warning:
+// CC1AS-DID-YOU-MEAN: error: unknown argument '-hell', did you mean '-help'?
+// CC1AS-DID-YOU-MEAN: error: unknown argument '--version', did you mean '-version'?
+// CC1AS-DID-YOU-MEAN: error: unknown argument '-debug-info-macros', did you mean '-debug-info-macro'?
 
 
 // RUN: %clang -S %s -o %t.s  -Wunknown-to-clang-option 2>&1 | FileCheck --check-prefix=IGNORED %s
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41809: Clang counterpart change for fuzzer FreeBSD support

2018-01-12 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski added a comment.

Looks good, please improve the description of the commit (and not your 
authorship that will be preserved in the commit message).

Once accepted by another developer, I can commit it for you.


https://reviews.llvm.org/D41809



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


[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-12 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:1937
+RetAttrs.addAttribute(llvm::Attribute::ZExt);
+}
 // FALL THROUGH

asb wrote:
> rjmccall wrote:
> > asb wrote:
> > > rjmccall wrote:
> > > > I feel like a better design would be to record whether to do a sext or 
> > > > a zext in the ABIArgInfo.  Add getSignExtend and getZeroExtend static 
> > > > functions to ABIArgInfo and make getExtend a convenience function that 
> > > > takes a QualType and uses its signedness.
> > > I could see how that might be cleaner, but that's a larger refactoring 
> > > that's going to touch a lot more code. Are you happy for this patch to 
> > > stick with this more incremental change (applying the same sign-extension 
> > > logic to return values as is used for arguments), and to leave your 
> > > suggested refactoring for a future patch?
> > I won't insist that you do it, but I don't think this refactor would be as 
> > bad as you think.  Doing these refactors incrementally when we realize that 
> > the existing infrastructure is failing us in some way is how we make sure 
> > they actually happen.  Individual contributors rarely have any incentive to 
> > ever do that "future patch".
> I've submitted this refactoring in D41999.
Much appreciated, thanks!


https://reviews.llvm.org/D40023



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


[PATCH] D41999: Refactor handling of signext/zeroext in ABIArgInfo

2018-01-12 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.  I appreciate you doing this.


Repository:
  rC Clang

https://reviews.llvm.org/D41999



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


[PATCH] D40023: [RISCV] Implement ABI lowering

2018-01-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:1937
+RetAttrs.addAttribute(llvm::Attribute::ZExt);
+}
 // FALL THROUGH

rjmccall wrote:
> asb wrote:
> > rjmccall wrote:
> > > I feel like a better design would be to record whether to do a sext or a 
> > > zext in the ABIArgInfo.  Add getSignExtend and getZeroExtend static 
> > > functions to ABIArgInfo and make getExtend a convenience function that 
> > > takes a QualType and uses its signedness.
> > I could see how that might be cleaner, but that's a larger refactoring 
> > that's going to touch a lot more code. Are you happy for this patch to 
> > stick with this more incremental change (applying the same sign-extension 
> > logic to return values as is used for arguments), and to leave your 
> > suggested refactoring for a future patch?
> I won't insist that you do it, but I don't think this refactor would be as 
> bad as you think.  Doing these refactors incrementally when we realize that 
> the existing infrastructure is failing us in some way is how we make sure 
> they actually happen.  Individual contributors rarely have any incentive to 
> ever do that "future patch".
I've submitted this refactoring in D41999.


https://reviews.llvm.org/D40023



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


[PATCH] D41999: Refactor handling of signext/zeroext in ABIArgInfo

2018-01-12 Thread Alex Bradbury via Phabricator via cfe-commits
asb created this revision.
asb added a reviewer: rjmccall.
Herald added subscribers: cfe-commits, arichardson.

As @rjmccall suggested in https://reviews.llvm.org/D40023, we can get rid of 
ABIInfo::shouldSignExtUnsignedType (used to handle cases like the Mips calling 
convention where 32-bit integers are always sign extended regardless of the 
sign of the type) by adding a SignExt field to ABIArgInfo. In the common case, 
this new field is set automatically by ABIArgInfo::getExtend based on the sign 
of the type. For targets that want greater control, they can use 
ABIArgInfo::getSignExtend or ABIArgInfo::getZeroExtend when necessary. This 
change also cleans up logic in CGCall.cpp.

There is no functional change intended in this patch, and all tests pass 
unchanged. As noted in https://reviews.llvm.org/D40023, Mips might want to 
32-bit integer return types. A future patch might modify 
MipsABIInfo::classifyReturnType to use MipsABIInfo::extendType.


Repository:
  rC Clang

https://reviews.llvm.org/D41999

Files:
  include/clang/CodeGen/CGFunctionInfo.h
  lib/CodeGen/ABIInfo.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/TargetInfo.cpp

Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -201,10 +201,6 @@
   return false;
 }
 
-bool ABIInfo::shouldSignExtUnsignedType(QualType Ty) const {
-  return false;
-}
-
 LLVM_DUMP_METHOD void ABIArgInfo::dump() const {
   raw_ostream  = llvm::errs();
   OS << "(ABIArgInfo Kind=";
@@ -682,8 +678,8 @@
   if (const EnumType *EnumTy = Ty->getAs())
 Ty = EnumTy->getDecl()->getIntegerType();
 
-  return (Ty->isPromotableIntegerType() ?
-  ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
+  return (Ty->isPromotableIntegerType() ? ABIArgInfo::getExtend(Ty)
+: ABIArgInfo::getDirect());
 }
 
 ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy) const {
@@ -697,8 +693,8 @@
   if (const EnumType *EnumTy = RetTy->getAs())
 RetTy = EnumTy->getDecl()->getIntegerType();
 
-  return (RetTy->isPromotableIntegerType() ?
-  ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
+  return (RetTy->isPromotableIntegerType() ? ABIArgInfo::getExtend(RetTy)
+   : ABIArgInfo::getDirect());
 }
 
 //===--===//
@@ -845,8 +841,8 @@
 return ABIArgInfo::getDirect();
   }
 
-  return (Ty->isPromotableIntegerType() ?
-  ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
+  return (Ty->isPromotableIntegerType() ? ABIArgInfo::getExtend(Ty)
+: ABIArgInfo::getDirect());
 }
 
 ABIArgInfo PNaClABIInfo::classifyReturnType(QualType RetTy) const {
@@ -861,8 +857,8 @@
   if (const EnumType *EnumTy = RetTy->getAs())
 RetTy = EnumTy->getDecl()->getIntegerType();
 
-  return (RetTy->isPromotableIntegerType() ?
-  ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
+  return (RetTy->isPromotableIntegerType() ? ABIArgInfo::getExtend(RetTy)
+   : ABIArgInfo::getDirect());
 }
 
 /// IsX86_MMXType - Return true if this is an MMX type.
@@ -1403,8 +1399,8 @@
   if (const EnumType *EnumTy = RetTy->getAs())
 RetTy = EnumTy->getDecl()->getIntegerType();
 
-  return (RetTy->isPromotableIntegerType() ?
-  ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
+  return (RetTy->isPromotableIntegerType() ? ABIArgInfo::getExtend(RetTy)
+   : ABIArgInfo::getDirect());
 }
 
 static bool isSSEVectorType(ASTContext , QualType Ty) {
@@ -1676,8 +1672,8 @@
 
   if (Ty->isPromotableIntegerType()) {
 if (InReg)
-  return ABIArgInfo::getExtendInReg();
-return ABIArgInfo::getExtend();
+  return ABIArgInfo::getExtendInReg(Ty);
+return ABIArgInfo::getExtend(Ty);
   }
 
   if (InReg)
@@ -2865,8 +2861,8 @@
 if (const EnumType *EnumTy = Ty->getAs())
   Ty = EnumTy->getDecl()->getIntegerType();
 
-return (Ty->isPromotableIntegerType() ?
-ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
+return (Ty->isPromotableIntegerType() ? ABIArgInfo::getExtend(Ty)
+  : ABIArgInfo::getDirect());
   }
 
   return getNaturalAlignIndirect(Ty);
@@ -2898,8 +2894,8 @@
 if (const EnumType *EnumTy = Ty->getAs())
   Ty = EnumTy->getDecl()->getIntegerType();
 
-return (Ty->isPromotableIntegerType() ?
-ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
+return (Ty->isPromotableIntegerType() ? ABIArgInfo::getExtend(Ty)
+  : ABIArgInfo::getDirect());
   }
 
   if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
@@ -3268,7 +3264,7 @@
 
   if (RetTy->isIntegralOrEnumerationType() &&
   RetTy->isPromotableIntegerType())
-return 

[PATCH] D41996: [clangd] Code completion uses Sema for NS-level things in the current file.

2018-01-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In https://reviews.llvm.org/D41996#974751, @hokein wrote:

> nice, LGTM.
>
> By `r322377`, I think you mean `r322371`.


Done.

> We also need to set `CollectorOpts.IndexMainFiles` to `false` in  
> `FileIndex.cpp::indexAST` -- we don't need dynamic index to catch the symbols 
> in current main file since sema does that for us now :)

This would fix the problem. But it will break index-based go-to-definition for 
modified files, so I'd rather leave this at least for now, and pursue 
deduplicating symbols instead.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41996



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


[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.

2018-01-12 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

@arphaman: ping.


https://reviews.llvm.org/D41788



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


[PATCH] D41937: [WebAssembly] supports -stdlib=libc++ switch

2018-01-12 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322382: [WebAssembly] Support -stdlib=libc++ switch 
(authored by sbc, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41937?vs=129572=129649#toc

Repository:
  rC Clang

https://reviews.llvm.org/D41937

Files:
  lib/Driver/ToolChains/WebAssembly.cpp
  lib/Driver/ToolChains/WebAssembly.h
  test/Driver/wasm-toolchain.cpp


Index: lib/Driver/ToolChains/WebAssembly.cpp
===
--- lib/Driver/ToolChains/WebAssembly.cpp
+++ lib/Driver/ToolChains/WebAssembly.cpp
@@ -11,6 +11,7 @@
 #include "CommonArgs.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 
@@ -117,6 +118,12 @@
 }
 
 ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList ) 
const {
+  if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
+StringRef Value = A->getValue();
+if (Value != "libc++")
+  getDriver().Diag(diag::err_drv_invalid_stdlib_name)
+  << A->getAsString(Args);
+  }
   return ToolChain::CST_Libcxx;
 }
 
@@ -134,6 +141,19 @@
  getDriver().SysRoot + "/include/c++/v1");
 }
 
+void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const 
{
+
+  switch (GetCXXStdlibType(Args)) {
+  case ToolChain::CST_Libcxx:
+CmdArgs.push_back("-lc++");
+CmdArgs.push_back("-lc++abi");
+break;
+  case ToolChain::CST_Libstdcxx:
+llvm_unreachable("invalid stdlib name");
+  }
+}
+
 std::string WebAssembly::getThreadModel() const {
   // The WebAssembly MVP does not yet support threads; for now, use the
   // "single" threading model, which lowers atomics to non-atomic operations.
Index: lib/Driver/ToolChains/WebAssembly.h
===
--- lib/Driver/ToolChains/WebAssembly.h
+++ lib/Driver/ToolChains/WebAssembly.h
@@ -62,6 +62,8 @@
   void AddClangCXXStdlibIncludeArgs(
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
+  void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
   std::string getThreadModel() const override;
 
   const char *getDefaultLinker() const override {
Index: test/Driver/wasm-toolchain.cpp
===
--- test/Driver/wasm-toolchain.cpp
+++ test/Driver/wasm-toolchain.cpp
@@ -0,0 +1,36 @@
+// A basic clang -cc1 command-line. WebAssembly is somewhat special in
+// enabling -ffunction-sections, -fdata-sections, and -fvisibility=hidden by
+// default.
+
+// RUN: %clang++ %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 
2>&1 | FileCheck -check-prefix=CC1 %s
+// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} 
"-fvisibility" "hidden" {{.*}} "-ffunction-sections" "-fdata-sections"
+
+// Ditto, but ensure that a user -fno-function-sections disables the
+// default -ffunction-sections.
+
+// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-function-sections 
2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s
+// NO_FUNCTION_SECTIONS-NOT: function-sections
+
+// Ditto, but ensure that a user -fno-data-sections disables the
+// default -fdata-sections.
+
+// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-data-sections 
2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s
+// NO_DATA_SECTIONS-NOT: data-sections
+
+// Ditto, but ensure that a user -fvisibility=default disables the default
+// -fvisibility=hidden.
+
+// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fvisibility=default 
2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s
+// FVISIBILITY_DEFAULT-NOT: hidden
+
+// A basic C++ link command-line.
+
+// RUN: %clang++ -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK %s
+// LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" 
"-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+
+// A basic C++ link command-line with optimization.
+
+// RUN: %clang++ -### -O2 -no-canonical-prefixes -target 
wasm32-unknown-unknown --sysroot=/foo %s --stdlib=c++ 2>&1 | FileCheck 
-check-prefix=LINK_OPT %s
+// LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"


Index: lib/Driver/ToolChains/WebAssembly.cpp
===
--- lib/Driver/ToolChains/WebAssembly.cpp
+++ lib/Driver/ToolChains/WebAssembly.cpp
@@ -11,6 +11,7 @@
 #include "CommonArgs.h"
 

r322382 - [WebAssembly] Support -stdlib=libc++ switch

2018-01-12 Thread Sam Clegg via cfe-commits
Author: sbc
Date: Fri Jan 12 09:54:49 2018
New Revision: 322382

URL: http://llvm.org/viewvc/llvm-project?rev=322382=rev
Log:
[WebAssembly] Support -stdlib=libc++ switch

Referenced implementation from Fuchsia and Darwin Toolchain.
Still only support CST_Libcxx.  Now checks that the argument
is really '-stdlib=libc++', and display error.

Also, now will pass -lc++ and -lc++abi to the linker.

Patch by Patrick Cheng!

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

Added:
cfe/trunk/test/Driver/wasm-toolchain.cpp   (with props)
Modified:
cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
cfe/trunk/lib/Driver/ToolChains/WebAssembly.h

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp?rev=322382=322381=322382=diff
==
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp Fri Jan 12 09:54:49 2018
@@ -11,6 +11,7 @@
 #include "CommonArgs.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 
@@ -117,6 +118,12 @@ ToolChain::RuntimeLibType WebAssembly::G
 }
 
 ToolChain::CXXStdlibType WebAssembly::GetCXXStdlibType(const ArgList ) 
const {
+  if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
+StringRef Value = A->getValue();
+if (Value != "libc++")
+  getDriver().Diag(diag::err_drv_invalid_stdlib_name)
+  << A->getAsString(Args);
+  }
   return ToolChain::CST_Libcxx;
 }
 
@@ -134,6 +141,19 @@ void WebAssembly::AddClangCXXStdlibInclu
  getDriver().SysRoot + "/include/c++/v1");
 }
 
+void WebAssembly::AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
+  llvm::opt::ArgStringList ) const 
{
+
+  switch (GetCXXStdlibType(Args)) {
+  case ToolChain::CST_Libcxx:
+CmdArgs.push_back("-lc++");
+CmdArgs.push_back("-lc++abi");
+break;
+  case ToolChain::CST_Libstdcxx:
+llvm_unreachable("invalid stdlib name");
+  }
+}
+
 std::string WebAssembly::getThreadModel() const {
   // The WebAssembly MVP does not yet support threads; for now, use the
   // "single" threading model, which lowers atomics to non-atomic operations.

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.h?rev=322382=322381=322382=diff
==
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.h Fri Jan 12 09:54:49 2018
@@ -62,6 +62,8 @@ private:
   void AddClangCXXStdlibIncludeArgs(
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
+  void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
   std::string getThreadModel() const override;
 
   const char *getDefaultLinker() const override {

Added: cfe/trunk/test/Driver/wasm-toolchain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/wasm-toolchain.cpp?rev=322382=auto
==
--- cfe/trunk/test/Driver/wasm-toolchain.cpp (added)
+++ cfe/trunk/test/Driver/wasm-toolchain.cpp Fri Jan 12 09:54:49 2018
@@ -0,0 +1,36 @@
+// A basic clang -cc1 command-line. WebAssembly is somewhat special in
+// enabling -ffunction-sections, -fdata-sections, and -fvisibility=hidden by
+// default.
+
+// RUN: %clang++ %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 
2>&1 | FileCheck -check-prefix=CC1 %s
+// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} 
"-fvisibility" "hidden" {{.*}} "-ffunction-sections" "-fdata-sections"
+
+// Ditto, but ensure that a user -fno-function-sections disables the
+// default -ffunction-sections.
+
+// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-function-sections 
2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s
+// NO_FUNCTION_SECTIONS-NOT: function-sections
+
+// Ditto, but ensure that a user -fno-data-sections disables the
+// default -fdata-sections.
+
+// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fno-data-sections 
2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s
+// NO_DATA_SECTIONS-NOT: data-sections
+
+// Ditto, but ensure that a user -fvisibility=default disables the default
+// -fvisibility=hidden.
+
+// RUN: %clang++ %s -### -target wasm32-unknown-unknown -fvisibility=default 
2>&1 | FileCheck -check-prefix=FVISIBILITY_DEFAULT %s
+// FVISIBILITY_DEFAULT-NOT: hidden
+
+// A basic C++ link command-line.
+
+// RUN: %clang++ -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK %s
+// 

[PATCH] D41998: [clang-tidy] Expand readability-redundant-smartptr-get to understand implicit converions to bool in more contexts.

2018-01-12 Thread Samuel Benzaquen via Phabricator via cfe-commits
sbenza created this revision.
sbenza added a reviewer: hokein.
Herald added subscribers: cfe-commits, xazax.hun, klimek.

Expand readability-redundant-smartptr-get to understand implicit converions to 
bool in more contexts.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41998

Files:
  clang-tidy/readability/RedundantSmartptrGetCheck.cpp
  test/clang-tidy/readability-redundant-smartptr-get.cpp

Index: test/clang-tidy/readability-redundant-smartptr-get.cpp
===
--- test/clang-tidy/readability-redundant-smartptr-get.cpp
+++ test/clang-tidy/readability-redundant-smartptr-get.cpp
@@ -9,13 +9,15 @@
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 template 
 struct shared_ptr {
   T& operator*() const;
   T* operator->() const;
   T* get() const;
+  explicit operator bool() const noexcept;
 };
 
 }  // namespace std
@@ -28,6 +30,7 @@
   Bar* operator->();
   Bar& operator*();
   Bar* get();
+  explicit operator bool() const;
 };
 struct int_ptr {
   int* get();
@@ -110,6 +113,23 @@
   // CHECK-MESSAGES: uu.get() == nullptr;
   // CHECK-FIXES: bool bb = uu == nullptr;
 
+  if (up->get());
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+  // CHECK-MESSAGES: if (up->get());
+  // CHECK-FIXES: if (*up);
+  if ((uu.get()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: if ((uu.get()));
+  // CHECK-FIXES: if ((uu));
+  bb = !ss->get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant get() call
+  // CHECK-MESSAGES: bb = !ss->get();
+  // CHECK-FIXES: bb = !*ss;
+  bb = u.get() ? true : false;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: bb = u.get() ? true : false;
+  // CHECK-FIXES: bb = u ? true : false;
+
   bb = nullptr != ss->get();
   // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant get() call
   // CHECK-MESSAGES: nullptr != ss->get();
@@ -146,10 +166,6 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call
   // CHECK-MESSAGES: if (NULL == x.get());
   // CHECK-FIXES: if (NULL == x);
-  if (x.get());
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
-  // CHECK-MESSAGES: if (x.get());
-  // CHECK-FIXES: if (x);
 }
 
 void Negative() {
@@ -175,4 +191,6 @@
 
   int_ptr ip;
   bool bb = ip.get() == nullptr;
+  bb = !ip.get();
+  bb = ip.get() ? true : false;
 }
Index: clang-tidy/readability/RedundantSmartptrGetCheck.cpp
===
--- clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -18,6 +18,7 @@
 namespace readability {
 
 namespace {
+
 internal::Matcher callToGet(const internal::Matcher ) {
   return cxxMemberCallExpr(
  on(expr(anyOf(hasType(OnClass),
@@ -51,6 +52,20 @@
   unaryOperator(hasOperatorName("*"),
 hasUnaryOperand(callToGet(QuacksLikeASmartptr))),
   Callback);
+
+  // Catch '!ptr.get()'
+  const auto CallToGetAsBool = ignoringParenImpCasts(callToGet(recordDecl(
+  QuacksLikeASmartptr, has(cxxConversionDecl(returns(booleanType()));
+  Finder->addMatcher(
+  unaryOperator(hasOperatorName("!"), hasUnaryOperand(CallToGetAsBool)),
+  Callback);
+
+  // Catch 'if(ptr.get())'
+  Finder->addMatcher(ifStmt(hasCondition(CallToGetAsBool)), Callback);
+
+  // Catch 'ptr.get() ? X : Y'
+  Finder->addMatcher(conditionalOperator(hasCondition(CallToGetAsBool)),
+ Callback);
 }
 
 void registerMatchersForGetEquals(MatchFinder *Finder,
@@ -72,11 +87,6 @@
  hasEitherOperand(callToGet(IsAKnownSmartptr))),
   Callback);
 
-  // Matches against if(ptr.get())
-  Finder->addMatcher(
-  ifStmt(hasCondition(ignoringImpCasts(callToGet(IsAKnownSmartptr,
-  Callback);
-
   // FIXME: Match and fix if (l.get() == r.get()).
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41963: [clang-tidy] Adding Fuchsia checker for thread local storage.

2018-01-12 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 129647.
juliehockett marked 3 inline comments as done.
juliehockett added a comment.

Fixing comments


https://reviews.llvm.org/D41963

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/ThreadLocalCheck.cpp
  clang-tidy/fuchsia/ThreadLocalCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-thread-local.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-thread-local.cpp

Index: test/clang-tidy/fuchsia-thread-local.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-thread-local.cpp
@@ -0,0 +1,14 @@
+// RUN: %check_clang_tidy %s fuchsia-thread-local %t
+
+int main() {
+  thread_local int foo;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: thread local storage is disallowed
+  // CHECK-NEXT:  thread_local int foo;
+
+  extern thread_local int bar;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: thread local storage is disallowed
+  // CHECK-NEXT:  extern thread_local int bar;
+  int baz;
+  
+  return 0;
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -71,6 +71,7 @@
fuchsia-default-arguments
fuchsia-overloaded-operator
fuchsia-statically-constructed-objects
+   fuchsia-thread-local
fuchsia-virtual-inheritance
google-build-explicit-make-pair
google-build-namespaces
Index: docs/clang-tidy/checks/fuchsia-thread-local.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-thread-local.rst
@@ -0,0 +1,15 @@
+.. title:: clang-tidy - fuchsia-thread-local
+
+fuchsia-thread-local
+
+
+Warns if thread storage duration is used.
+
+For example, using ``thread_local`` or ``extern thread_local`` is not allowed:
+
+.. code-block:: c++
+
+  thread_local int foo;   // Warning
+  extern thread_local int bar;// Warning
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -64,6 +64,11 @@
   object is statically initialized with a ``constexpr`` constructor or has no 
   explicit constructor.
 
+- New `fuchsia-thread-local
+  `_ check
+
+  Warns if thread storage duration is used.
+
 Improvements to include-fixer
 -
 
Index: clang-tidy/fuchsia/ThreadLocalCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/ThreadLocalCheck.h
@@ -0,0 +1,35 @@
+//===--- ThreadLocalCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_THREAD_LOCAL_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_THREAD_LOCAL_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Thread storage duration is disallowed.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-thread-local.html
+class ThreadLocalCheck : public ClangTidyCheck {
+public:
+  ThreadLocalCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_THREAD_LOCAL_H
Index: clang-tidy/fuchsia/ThreadLocalCheck.cpp
===
--- /dev/null
+++ clang-tidy/fuchsia/ThreadLocalCheck.cpp
@@ -0,0 +1,32 @@
+//===--- ThreadLocalCheck.cpp - clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ThreadLocalCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+void ThreadLocalCheck::registerMatchers(MatchFinder *Finder) {
+  // Using thread storage duration is disallowed.
+  Finder->addMatcher(varDecl(hasThreadStorageDuration()).bind("decl"), 

[PATCH] D41228: [ObjC] Enable __strong pointers in structs under ARC

2018-01-12 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/AST/Decl.h:3529
+  /// Basic properties of non-trivial C structs.
+  bool HasStrongObjCPointer : 1;
+

Is it interesting to track all the individual reasons that a struct is 
non-trivial at the struct level, as opposed to (like we do with 
CXXDefinitionData) just tracking the four aggregate properties you've described 
below?



Comment at: include/clang/AST/Type.h:1098
+  /// and return the kind.
+  PrimitiveCopyKind isNonTrivialToPrimitiveDefaultInitialize() const;
+

I think this one should probably get its own enum.  It's not too hard to 
imagine types (maybe relative references, or something else that's 
address-sensitive?) that require non-trivial copy semantics but isn't 
non-trivial to default-initialize.



Comment at: include/clang/AST/Type.h:1108
+  /// move and return the kind.
+  PrimitiveCopyKind isNonTrivialToPrimitiveDestructiveMove() const;
+

You need to define what you mean by "destructive move":

- A C++-style move leaves the source in a still-initialized state, just 
potentially with a different value (such as nil for a __strong reference).  
This is what we would do when e.g. loading from an r-value reference in C++.  
It's also what we have to do when moving a __block variable to the heap, since 
there may still be pointers to the stack copy of the variable, and since the 
compiler will unconditionally attempt to destroy that stack copy when it goes 
out of scope.  Since the source still needs to be destroyed, a 
non-trivially-copyable type will probably always have to do non-trivial work to 
do this.  Because of that, a function for this query could reasonably just 
return PrimitiveCopyKind.

- A truly primitive destructive move is something that actually leaves the 
source uninitialized.  This is generally only possible in narrow circumstances 
where the compiler can guarantee that the previous value is never again going 
to be referenced, including to destroy it.  I don't know if you have a reason 
to track this at all (i.e. whether there are copies you want to perform with a 
destructive move in IRGen), but if you do, you should use a different return 
type, because many types that are non-trivial to "C++-style move" are trivial 
to "destructively move": for example, __strong references are trivial to 
destructively move.



Comment at: include/clang/AST/Type.h:1113
+  /// the kind.
+  PrimitiveCopyKind isNonTrivialToPrimitiveDestroy() const;
+

Is there a reason we need this in addition to isDestructedType()?  It seems to 
me that it's exactly the same except ruling out the possibility of a C++ 
destructor.



Comment at: include/clang/AST/Type.h:1137
+return isNonTrivialToPrimitiveDestroy() == PCK_Struct;
+  }
+

Are these four queries really important enough to provide API for them on 
QualType?



Comment at: include/clang/AST/Type.h:1148
+DK_objc_weak_lifetime,
+DK_c_struct_strong_field
   };

I don't think you want to refer to the fact that the C struct specifically 
contains a __strong field here.  As we add more reasons, would we create a new 
enumerator for each?  What if a struct is non-trivial for multiple reasons?  
Just say that it's a non-trivial C struct.



Comment at: lib/AST/ASTContext.cpp:5778
+  if (Ty.isNonTrivialToPrimitiveDestructiveMoveStruct() ||
+  Ty.isNonTrivialToPrimitiveDestroyStruct())
+return true;

I think you should use the non-struct-specific checks here.  In addition to 
being cleaner, it would also let you completely short-circuit the rest of this 
function in ARC mode.  In non-ARC mode, you do still have to check lifetime 
(only to see if it's __unsafe_unretained; the __strong and __weak cases would 
be unreachable), and you need the type-specific special cases.


https://reviews.llvm.org/D41228



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


[PATCH] D41996: [clangd] Code completion uses Sema for NS-level things in the current file.

2018-01-12 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.

nice, LGTM.

By `r322377`, I think you mean `r322371`.

We also need to set `CollectorOpts.IndexMainFiles` to `false` in  
`FileIndex.cpp::indexAST` -- we don't need dynamic index to catch the symbols 
in current main file since sema does that for us now :)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41996



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


[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value

2018-01-12 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

High Integrity C++ has the rule `17.5.1 Do not ignore the result of 
std::remove, std::remove_if or std::unique`. Do we want to add those to the 
preconfigured list?


https://reviews.llvm.org/D41655



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


[PATCH] D41809: Clang counterpart change for fuzzer FreeBSD support

2018-01-12 Thread David CARLIER via Phabricator via cfe-commits
devnexen added a comment.

In https://reviews.llvm.org/D41809#969475, @kimgr wrote:

> Typo in the commit title: buzzer :)


Changed ... just to follow-up the now accepted change of this one 
https://reviews.llvm.org/D41642


https://reviews.llvm.org/D41809



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


[clang-tools-extra] r322379 - [clangd] Include debugging tags for both static and dynamic index. NFC

2018-01-12 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Jan 12 09:09:49 2018
New Revision: 322379

URL: http://llvm.org/viewvc/llvm-project?rev=322379=rev
Log:
[clangd] Include debugging tags for both static and dynamic index. NFC

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=322379=322378=322379=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Jan 12 09:09:49 2018
@@ -671,10 +671,10 @@ CompletionList codeComplete(const Contex
 // engine).
 if (Opts.Index)
   completeWithIndex(Ctx, *Opts.Index, Contents, *CompletedName.SSInfo,
-CompletedName.Filter, );
+CompletedName.Filter, , 
/*DebuggingLabel=*/"D");
 if (Opts.StaticIndex)
   completeWithIndex(Ctx, *Opts.StaticIndex, Contents, 
*CompletedName.SSInfo,
-CompletedName.Filter, , 
/*DebuggingLabel=*/"G");
+CompletedName.Filter, , 
/*DebuggingLabel=*/"S");
   }
   return Results;
 }

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=322379=322378=322379=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri Jan 12 
09:09:49 2018
@@ -526,8 +526,8 @@ TEST(CompletionTest, StaticAndDynamicInd
   void f() { ::ns::^ }
   )cpp",
  Opts);
-  EXPECT_THAT(Results.items, Contains(Labeled("[G]XYZ")));
-  EXPECT_THAT(Results.items, Contains(Labeled("foo")));
+  EXPECT_THAT(Results.items, Contains(Labeled("[S]XYZ")));
+  EXPECT_THAT(Results.items, Contains(Labeled("[D]foo")));
 }
 
 TEST(CompletionTest, SimpleIndexBased) {


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


  1   2   >