r339456 - Allow relockable scopes with thread safety attributes.

2018-08-10 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Aug 10 10:33:47 2018
New Revision: 339456

URL: http://llvm.org/viewvc/llvm-project?rev=339456&view=rev
Log:
Allow relockable scopes with thread safety attributes.

Patch by Aaron Puchert

Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=339456&r1=339455&r2=339456&view=diff
==
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Fri Aug 10 10:33:47 2018
@@ -86,8 +86,8 @@ static void warnInvalidLock(ThreadSafety
 
 namespace {
 
-/// A set of CapabilityInfo objects, which are compiled from the
-/// requires attributes on a function.
+/// A set of CapabilityExpr objects, which are compiled from thread safety
+/// attributes on a function.
 class CapExprSet : public SmallVector {
 public:
   /// Push M onto list, but discard duplicates.
@@ -944,6 +944,23 @@ public:
 if (FullyRemove)
   FSet.removeLock(FactMan, Cp);
   }
+
+  void Relock(FactSet &FSet, FactManager &FactMan, LockKind LK,
+  SourceLocation RelockLoc, ThreadSafetyHandler &Handler,
+  StringRef DiagKind) const {
+for (const auto *UnderlyingMutex : UnderlyingMutexes) {
+  CapabilityExpr UnderCp(UnderlyingMutex, false);
+
+  // We're relocking the underlying mutexes. Warn on double locking.
+  if (FSet.findLock(FactMan, UnderCp))
+Handler.handleDoubleLock(DiagKind, UnderCp.toString(), RelockLoc);
+  else {
+FSet.removeLock(FactMan, !UnderCp);
+FSet.addLock(FactMan, llvm::make_unique(UnderCp, LK,
+   RelockLoc));
+  }
+}
+  }
 };
 
 /// Class which implements the core thread safety analysis routines.
@@ -974,6 +991,9 @@ public:
   void removeLock(FactSet &FSet, const CapabilityExpr &CapE,
   SourceLocation UnlockLoc, bool FullyRemove, LockKind Kind,
   StringRef DiagKind);
+  void relockScopedLock(FactSet &FSet, const CapabilityExpr &CapE,
+SourceLocation RelockLoc, LockKind Kind,
+StringRef DiagKind);
 
   template 
   void getMutexIDs(CapExprSet &Mtxs, AttrType *Attr, Expr *Exp,
@@ -1285,6 +1305,27 @@ void ThreadSafetyAnalyzer::removeLock(Fa
  DiagKind);
 }
 
+void ThreadSafetyAnalyzer::relockScopedLock(FactSet &FSet,
+const CapabilityExpr &Cp,
+SourceLocation RelockLoc,
+LockKind Kind, StringRef DiagKind) 
{
+  if (Cp.shouldIgnore())
+return;
+
+  const FactEntry *LDat = FSet.findLock(FactMan, Cp);
+  if (!LDat) {
+// FIXME: It's possible to manually destruct the scope and then relock it.
+// Should that be a separate warning? For now we pretend nothing happened.
+// It's undefined behavior, so not related to thread safety.
+return;
+  }
+
+  // We should only land here if Cp is a scoped capability, so if we have any
+  // fact, it must be a ScopedLockableFactEntry.
+  const auto *SLDat = static_cast(LDat);
+  SLDat->Relock(FSet, FactMan, Kind, RelockLoc, Handler, DiagKind);
+}
+
 /// Extract the list of mutexIDs from the attribute on an expression,
 /// and push them onto Mtxs, discarding any duplicates.
 template 
@@ -1726,14 +1767,19 @@ void BuildLockset::handleCall(Expr *Exp,
   StringRef CapDiagKind = "mutex";
 
   // Figure out if we're constructing an object of scoped lockable class
-  bool isScopedVar = false;
+  bool isScopedConstructor = false, isScopedMemberCall = false;
   if (VD) {
 if (const auto *CD = dyn_cast(D)) {
   const CXXRecordDecl* PD = CD->getParent();
   if (PD && PD->hasAttr())
-isScopedVar = true;
+isScopedConstructor = true;
 }
   }
+  if (const auto *MCD = dyn_cast(Exp)) {
+const CXXRecordDecl *PD = MCD->getRecordDecl();
+if (PD && PD->hasAttr())
+  isScopedMemberCall = true;
+  }
 
   for(const Attr *At : D->attrs()) {
 switch (At->getKind()) {
@@ -1813,7 +1859,7 @@ void BuildLockset::handleCall(Expr *Exp,
  POK_FunctionCall, ClassifyDiagnostic(A),
  Exp->getExprLoc());
   // use for adopting a lock
-  if (isScopedVar) {
+  if (isScopedConstructor) {
 Analyzer->getMutexIDs(A->isShared() ? ScopedSharedReqs
 : ScopedExclusiveReqs,
   A, Exp, D, VD);
@@ -1846,16 +1892,24 @@ void BuildLockset::handleCall(Expr *Exp,
 Analyzer->removeLock(FSet, M, Loc, Dtor, LK_Generic, CapDiagKind);
 
   // Add locks.
-  for (const auto &M : ExclusiveLocksToAdd)
-Analyzer->add

[clang-tools-extra] r339516 - Add a new check to the readability module that flags uses of "magic numbers" (both floating-point and integral).

2018-08-12 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Aug 12 07:35:13 2018
New Revision: 339516

URL: http://llvm.org/viewvc/llvm-project?rev=339516&view=rev
Log:
Add a new check to the readability module that flags uses of "magic numbers" 
(both floating-point and integral).

Patch by Florin Iucha 

Added:
clang-tools-extra/trunk/clang-tidy/readability/MagicNumbersCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/MagicNumbersCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-avoid-magic-numbers.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/readability-magic-numbers.rst
clang-tools-extra/trunk/test/clang-tidy/readability-magic-numbers.cpp
Modified:

clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=339516&r1=339515&r2=339516&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 Sun Aug 12 07:35:13 2018
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
+#include "../readability/MagicNumbersCheck.h"
 #include "AvoidGotoCheck.h"
 #include "InterfacesGlobalInitCheck.h"
 #include "NarrowingConversionsCheck.h"
@@ -41,6 +42,8 @@ public:
 "cppcoreguidelines-avoid-goto");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
+CheckFactories.registerCheck(
+"cppcoreguidelines-avoid-magic-numbers");
 CheckFactories.registerCheck(
 "cppcoreguidelines-narrowing-conversions");
 CheckFactories.registerCheck("cppcoreguidelines-no-malloc");

Modified: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt?rev=339516&r1=339515&r2=339516&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt Sun Aug 12 
07:35:13 2018
@@ -11,6 +11,7 @@ add_clang_library(clangTidyReadabilityMo
   IdentifierNamingCheck.cpp
   ImplicitBoolConversionCheck.cpp
   InconsistentDeclarationParameterNameCheck.cpp
+  MagicNumbersCheck.cpp
   MisleadingIndentationCheck.cpp
   MisplacedArrayIndexCheck.cpp
   NamedParameterCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/readability/MagicNumbersCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/MagicNumbersCheck.cpp?rev=339516&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/readability/MagicNumbersCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/readability/MagicNumbersCheck.cpp Sun 
Aug 12 07:35:13 2018
@@ -0,0 +1,171 @@
+//===--- MagicNumbersCheck.cpp - clang-tidy---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// A checker for magic numbers: integer or floating point literals embedded
+// in the code, outside the definition of a constant or an enumeration.
+//
+//===--===//
+
+#include "MagicNumbersCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/STLExtras.h"
+#include 
+
+using namespace clang::ast_matchers;
+using namespace clang::ast_type_traits;
+
+namespace {
+
+bool isUsedToInitializeAConstant(const MatchFinder::MatchResult &Result,
+ const DynTypedNode &Node) {
+
+  const auto *AsDecl = Node.get();
+  if (AsDecl) {
+if (AsDecl->getType().isConstQualified())
+  return true;
+
+return AsDecl->isImplicit();
+  }
+
+  if (Node.get() != nullptr)
+return true;
+
+  return llvm::any_of(Result.Context->getParents(Node),
+  [&Result](const DynTypedNode &Parent) {
+return isUsedToInitializeAConstant(Result, Parent);
+  });
+}
+

[clang-tools-extra] r339517 - Adding the readability module to the list of dependencies for the C++ Core Guidelines module. Amends r339516 for a failing bot.

2018-08-12 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Aug 12 07:47:16 2018
New Revision: 339517

URL: http://llvm.org/viewvc/llvm-project?rev=339517&view=rev
Log:
Adding the readability module to the list of dependencies for the C++ Core 
Guidelines module. Amends r339516 for a failing bot.

Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt?rev=339517&r1=339516&r2=339517&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CMakeLists.txt Sun Aug 
12 07:47:16 2018
@@ -27,6 +27,7 @@ add_clang_library(clangTidyCppCoreGuidel
   clangLex
   clangTidy
   clangTidyMiscModule
+  clangTidyReadabilityModule
   clangTidyUtils
   clangTooling
   )


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


r339527 - Renaming arg_const_range to const_arg_range; NFC.

2018-08-12 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Aug 12 14:19:22 2018
New Revision: 339527

URL: http://llvm.org/viewvc/llvm-project?rev=339527&view=rev
Log:
Renaming arg_const_range to const_arg_range; NFC.

This form makes more sense (it is a range over constant arguments) and is most 
consistent with const_arg_iterator (there are zero instances of 
arg_const_iterator).

Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=339527&r1=339526&r2=339527&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Aug 12 14:19:22 2018
@@ -2495,11 +2495,11 @@ public:
   typedef ExprIterator arg_iterator;
   typedef ConstExprIterator const_arg_iterator;
   typedef llvm::iterator_range arg_range;
-  typedef llvm::iterator_range arg_const_range;
+  typedef llvm::iterator_range const_arg_range;
 
   arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
-  arg_const_range arguments() const {
-return arg_const_range(arg_begin(), arg_end());
+  const_arg_range arguments() const {
+return const_arg_range(arg_begin(), arg_end());
   }
 
   arg_iterator arg_begin() { return SubExprs+PREARGS_START+getNumPreArgs(); }

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=339527&r1=339526&r2=339527&view=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Sun Aug 12 14:19:22 2018
@@ -1486,11 +1486,11 @@ public:
   using arg_iterator = ExprIterator;
   using const_arg_iterator = ConstExprIterator;
   using arg_range = llvm::iterator_range;
-  using arg_const_range = llvm::iterator_range;
+  using const_arg_range = llvm::iterator_range;
 
   arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
-  arg_const_range arguments() const {
-return arg_const_range(arg_begin(), arg_end());
+  const_arg_range arguments() const {
+return const_arg_range(arg_begin(), arg_end());
   }
 
   arg_iterator arg_begin() { return Args; }

Modified: cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h?rev=339527&r1=339526&r2=339527&view=diff
==
--- cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h (original)
+++ cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h Sun Aug 12 14:19:22 2018
@@ -581,11 +581,11 @@ public:
   typedef ArgInfo *arg_iterator;
 
   typedef llvm::iterator_range arg_range;
-  typedef llvm::iterator_range arg_const_range;
+  typedef llvm::iterator_range const_arg_range;
 
   arg_range arguments() { return arg_range(arg_begin(), arg_end()); }
-  arg_const_range arguments() const {
-return arg_const_range(arg_begin(), arg_end());
+  const_arg_range arguments() const {
+return const_arg_range(arg_begin(), arg_end());
   }
 
   const_arg_iterator arg_begin() const { return getArgsBuffer() + 1; }


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


Re: [PATCH] D50647: [Sema] fix -Wfloat-conversion test case.

2018-08-13 Thread Aaron Ballman via cfe-commits
On Mon, Aug 13, 2018 at 1:08 PM, Nick Desaulniers via Phabricator
 wrote:
> nickdesaulniers created this revision.
> nickdesaulniers added reviewers: aaron.ballman, gkistanova.
> Herald added a subscriber: cfe-commits.
>
> Fixes commit 6bbde717f7fb ("[SEMA] add more -Wfloat-conversion to
> compound assigment analysis").

Thank you for fixing this, but in the future, can you please put the
SVN revision number into the commit message rather than a git hash
(for code archaeology purposes)? Not everyone is on git yet. :-)

r339581 is the amended revision in this case.

~Aaron

>
> This test case was caught in postsubmit testing.
>
>
> Repository:
>   rC Clang
>
> https://reviews.llvm.org/D50647
>
> Files:
>   test/Sema/conversion.c
>
>
> Index: test/Sema/conversion.c
> ===
> --- test/Sema/conversion.c
> +++ test/Sema/conversion.c
> @@ -359,7 +359,7 @@
>  void test_7676608(void) {
>float q = 0.7f;
>char c = 5;
> -  f7676608(c *= q);
> +  f7676608(c *= q); // expected-warning {{conversion}}
>  }
>
>  // 
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r332519 - Add a new check, readability-simplify-subscript-expr, that diagnoses array subscript expressions that can be simplified.

2018-05-16 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed May 16 13:12:06 2018
New Revision: 332519

URL: http://llvm.org/viewvc/llvm-project?rev=332519&view=rev
Log:
Add a new check, readability-simplify-subscript-expr, that diagnoses array 
subscript expressions that can be simplified.

Currently, diagnoses code that calls container.data()[some_index] when the 
container exposes a suitable operator[]() method that can be used directly.

Patch by Shuai Wang.

Added:

clang-tools-extra/trunk/clang-tidy/readability/SimplifySubscriptExprCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/SimplifySubscriptExprCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simplify-subscript-expr.rst

clang-tools-extra/trunk/test/clang-tidy/readability-simplify-subscript-expr.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt?rev=332519&r1=332518&r2=332519&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt Wed May 16 
13:12:06 2018
@@ -25,6 +25,7 @@ add_clang_library(clangTidyReadabilityMo
   RedundantSmartptrGetCheck.cpp
   RedundantStringInitCheck.cpp
   SimplifyBooleanExprCheck.cpp
+  SimplifySubscriptExprCheck.cpp
   StaticAccessedThroughInstanceCheck.cpp
   StaticDefinitionInAnonymousNamespaceCheck.cpp
   StringCompareCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp?rev=332519&r1=332518&r2=332519&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp 
Wed May 16 13:12:06 2018
@@ -32,6 +32,7 @@
 #include "RedundantStringCStrCheck.h"
 #include "RedundantStringInitCheck.h"
 #include "SimplifyBooleanExprCheck.h"
+#include "SimplifySubscriptExprCheck.h"
 #include "StaticAccessedThroughInstanceCheck.h"
 #include "StaticDefinitionInAnonymousNamespaceCheck.h"
 #include "StringCompareCheck.h"
@@ -72,6 +73,8 @@ public:
 "readability-redundant-function-ptr-dereference");
 CheckFactories.registerCheck(
 "readability-redundant-member-init");
+CheckFactories.registerCheck(
+"readability-simplify-subscript-expr");
 CheckFactories.registerCheck(
 "readability-static-accessed-through-instance");
 CheckFactories.registerCheck(

Added: 
clang-tools-extra/trunk/clang-tidy/readability/SimplifySubscriptExprCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SimplifySubscriptExprCheck.cpp?rev=332519&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/SimplifySubscriptExprCheck.cpp 
(added)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/SimplifySubscriptExprCheck.cpp 
Wed May 16 13:12:06 2018
@@ -0,0 +1,76 @@
+//===--- SimplifySubscriptExprCheck.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 "SimplifySubscriptExprCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+static const char kDefaultTypes[] =
+"::std::basic_string;::std::basic_string_view;::std::vector;::std::array";
+
+SimplifySubscriptExprCheck::SimplifySubscriptExprCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), Types(utils::options::parseStringList(
+ Options.get("Types", kDefaultTypes))) 
{
+}
+
+void SimplifySubscriptExprCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  const auto TypesMatcher = hasUnqualifiedDesugaredType(
+  recordType(hasDeclaration(cxxRecordDecl(hasAnyName(
+  llvm::SmallVector(Types.begin(), Types.end()));
+
+  Finder->addMatcher(
+  arraySubscriptExpr(hasBase(ignoringParenImpCasts(
+  cxxMemberCallExpr(
+  has(memberEx

[clang-tools-extra] r332716 - Silence a truncation warning; NFC.

2018-05-18 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri May 18 06:18:41 2018
New Revision: 332716

URL: http://llvm.org/viewvc/llvm-project?rev=332716&view=rev
Log:
Silence a truncation warning; NFC.

Modified:
clang-tools-extra/trunk/clangd/Quality.cpp

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=332716&r1=332715&r2=332716&view=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Fri May 18 06:18:41 2018
@@ -42,7 +42,7 @@ float SymbolQualitySignals::evaluate() c
 Score *= 2 - std::min(80, SemaCCPriority) / 40;
 
   if (Deprecated)
-Score *= 0.1;
+Score *= 0.1f;
 
   return Score;
 }


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


[clang-tools-extra] r332723 - Silence more truncation warnings; NFC.

2018-05-18 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri May 18 07:53:32 2018
New Revision: 332723

URL: http://llvm.org/viewvc/llvm-project?rev=332723&view=rev
Log:
Silence more truncation warnings; NFC.

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

Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=332723&r1=332722&r2=332723&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Fri May 18 
07:53:32 2018
@@ -102,15 +102,15 @@ TEST(QualityTests, SymbolRelevanceSignal
   EXPECT_LT(Forbidden.evaluate(), Default.evaluate());
 
   SymbolRelevanceSignals PoorNameMatch;
-  PoorNameMatch.NameMatch = 0.2;
+  PoorNameMatch.NameMatch = 0.2f;
   EXPECT_LT(PoorNameMatch.evaluate(), Default.evaluate());
 }
 
 TEST(QualityTests, SortText) {
-  EXPECT_LT(sortText(std::numeric_limits::infinity()), 
sortText(1000.2));
-  EXPECT_LT(sortText(1000.2), sortText(1));
-  EXPECT_LT(sortText(1), sortText(0.3));
-  EXPECT_LT(sortText(0.3), sortText(0));
+  EXPECT_LT(sortText(std::numeric_limits::infinity()), 
sortText(1000.2f));
+  EXPECT_LT(sortText(1000.2f), sortText(1));
+  EXPECT_LT(sortText(1), sortText(0.3f));
+  EXPECT_LT(sortText(0.3f), sortText(0));
   EXPECT_LT(sortText(0), sortText(-10));
   EXPECT_LT(sortText(-10), sortText(-std::numeric_limits::infinity()));
 


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


r314463 - Properly parse a postfix expression following a Boolean literal. Fixes PR34273.

2017-09-28 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Sep 28 14:29:18 2017
New Revision: 314463

URL: http://llvm.org/viewvc/llvm-project?rev=314463&view=rev
Log:
Properly parse a postfix expression following a Boolean literal. Fixes PR34273.

Patch by Nicolas Lesser.

Modified:
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/test/Parser/cxx-bool.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=314463&r1=314462&r2=314463&view=diff
==
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Thu Sep 28 14:29:18 2017
@@ -798,7 +798,8 @@ ExprResult Parser::ParseCastExpression(b
 
   case tok::kw_true:
   case tok::kw_false:
-return ParseCXXBoolLiteral();
+Res = ParseCXXBoolLiteral();
+break;
   
   case tok::kw___objc_yes:
   case tok::kw___objc_no:

Modified: cfe/trunk/test/Parser/cxx-bool.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-bool.cpp?rev=314463&r1=314462&r2=314463&view=diff
==
--- cfe/trunk/test/Parser/cxx-bool.cpp (original)
+++ cfe/trunk/test/Parser/cxx-bool.cpp Thu Sep 28 14:29:18 2017
@@ -1,4 +1,11 @@
-// RUN: %clang_cc1 -fsyntax-only %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
 
 bool a = true;
 bool b = false;
+
+namespace pr34273 {
+  char c = "clang"[true];
+  char d = true["clang"];
+}
+


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


[clang-tools-extra] r315057 - Fix nested namespaces in google-readability-nested-namespace-comments.

2017-10-06 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Oct  6 05:57:28 2017
New Revision: 315057

URL: http://llvm.org/viewvc/llvm-project?rev=315057&view=rev
Log:
Fix nested namespaces in google-readability-nested-namespace-comments.

Fixes PR34701.

Patch by Alexandru Octavian Buțiu.

Added:

clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.h

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp?rev=315057&r1=315056&r2=315057&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp 
Fri Oct  6 05:57:28 2017
@@ -23,7 +23,7 @@ NamespaceCommentCheck::NamespaceCommentC
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
-  "namespace( +([a-zA-Z0-9_]+))?\\.? *(\\*/)?$",
+  "namespace( +([a-zA-Z0-9_:]+))?\\.? *(\\*/)?$",
   llvm::Regex::IgnoreCase),
   ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
   SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
@@ -56,6 +56,15 @@ static std::string getNamespaceComment(c
   return Fix;
 }
 
+static std::string getNamespaceComment(const std::string &NameSpaceName,
+   bool InsertLineBreak) {
+  std::string Fix = "// namespace ";
+  Fix.append(NameSpaceName);
+  if (InsertLineBreak)
+Fix.append("\n");
+  return Fix;
+}
+
 void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *ND = Result.Nodes.getNodeAs("namespace");
   const SourceManager &Sources = *Result.SourceManager;
@@ -74,11 +83,38 @@ void NamespaceCommentCheck::check(const
   SourceLocation AfterRBrace = ND->getRBraceLoc().getLocWithOffset(1);
   SourceLocation Loc = AfterRBrace;
   Token Tok;
+  SourceLocation LBracketLocation = ND->getLocation();
+  SourceLocation NestedNamespaceBegin = LBracketLocation;
+
+  // Currently for nested namepsace (n1::n2::...) the AST matcher will match 
foo
+  // then bar instead of a single match. So if we got a nested namespace we 
have
+  // to skip the next ones.
+  for (const auto &EndOfNameLocation : Ends) {
+if (Sources.isBeforeInTranslationUnit(NestedNamespaceBegin,
+  EndOfNameLocation))
+  return;
+  }
+  while (Lexer::getRawToken(LBracketLocation, Tok, Sources, getLangOpts()) ||
+ !Tok.is(tok::l_brace)) {
+LBracketLocation = LBracketLocation.getLocWithOffset(1);
+  }
+
+  auto TextRange =
+  Lexer::getAsCharRange(SourceRange(NestedNamespaceBegin, 
LBracketLocation),
+Sources, getLangOpts());
+  auto NestedNamespaceName =
+  Lexer::getSourceText(TextRange, Sources, getLangOpts()).rtrim();
+  bool IsNested = NestedNamespaceName.contains(':');
+
+  if (IsNested)
+Ends.push_back(LBracketLocation);
+
   // Skip whitespace until we find the next token.
   while (Lexer::getRawToken(Loc, Tok, Sources, getLangOpts()) ||
  Tok.is(tok::semi)) {
 Loc = Loc.getLocWithOffset(1);
   }
+
   if (!locationsInSameFile(Sources, ND->getRBraceLoc(), Loc))
 return;
 
@@ -98,10 +134,14 @@ void NamespaceCommentCheck::check(const
   StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5] : "";
   StringRef Anonymous = Groups.size() > 3 ? Groups[3] : "";
 
-  // Check if the namespace in the comment is the same.
-  if ((ND->isAnonymousNamespace() && NamespaceNameInComment.empty()) ||
-  (ND->getNameAsString() == NamespaceNameInComment &&
-   Anonymous.empty())) {
+  if (IsNested && NestedNamespaceName == NamespaceNameInComment) {
+// C++17 nested namespace.
+return;
+  } else if ((ND->isAnonymousNamespace() &&
+  NamespaceNameInComment.empty()) ||
+ (ND->getNameAsString() == NamespaceNameInComment &&
+  Anonymous.empty())) {
+// Check if the namespace in the comment is the same.
 // FIXME: Maybe we need a strict mode, where we always fix namespace
 // comments with different format.
 return;
@@ -131,13 +171,16 @@ void NamespaceCommentCheck::check(const
   std::string NamespaceName =
   ND->isAnonymousNamespace()
   ? "anonymous namespace"
-  : ("namespace '" + ND->getNameAsString() + "'");
+  : ("namespace '" + NestedNamespaceName.str() + "'");
 
   diag(AfterRBrace, Messa

[clang-tools-extra] r315059 - Fixing the command line for a test and switching from tabs to spaces.

2017-10-06 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Oct  6 06:14:28 2017
New Revision: 315059

URL: http://llvm.org/viewvc/llvm-project?rev=315059&view=rev
Log:
Fixing the command line for a test and switching from tabs to spaces.

Modified:

clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp?rev=315059&r1=315058&r2=315059&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
 Fri Oct  6 06:14:28 2017
@@ -1,12 +1,10 @@
-// RUN: %check_clang_tidy %s google-readability-namespace-comments %t -- 
-std=c++17
+// RUN: %check_clang_tidy %s google-readability-namespace-comments %t -- -- 
-std=c++17
 
 namespace n1::n2 {
 namespace n3 {
-   
-   // So that namespace is not empty.
-   void f();
-   
-   
+  // So that namespace is not empty.
+  void f();
+
 // CHECK-MESSAGES: :[[@LINE+4]]:2: warning: namespace 'n3' not terminated with
 // CHECK-MESSAGES: :[[@LINE-7]]:11: note: namespace 'n3' starts here
 // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: namespace 'n1::n2' not terminated 
with a closing comment [google-readability-namespace-comments]


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


[clang-tools-extra] r315060 - Renaming a test to start with the name of the check based on post-commit review feedback; NFC.

2017-10-06 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Oct  6 06:27:59 2017
New Revision: 315060

URL: http://llvm.org/viewvc/llvm-project?rev=315060&view=rev
Log:
Renaming a test to start with the name of the check based on post-commit review 
feedback; NFC.

Added:

clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17
  - copied unchanged from r315059, 
clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
Removed:

clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp

Removed: 
clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp?rev=315059&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
 (removed)
@@ -1,15 +0,0 @@
-// RUN: %check_clang_tidy %s google-readability-namespace-comments %t -- -- 
-std=c++17
-
-namespace n1::n2 {
-namespace n3 {
-  // So that namespace is not empty.
-  void f();
-
-// CHECK-MESSAGES: :[[@LINE+4]]:2: warning: namespace 'n3' not terminated with
-// CHECK-MESSAGES: :[[@LINE-7]]:11: note: namespace 'n3' starts here
-// CHECK-MESSAGES: :[[@LINE+2]]:3: warning: namespace 'n1::n2' not terminated 
with a closing comment [google-readability-namespace-comments]
-// CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'n1::n2' starts here
-}}
-// CHECK-FIXES: }  // namespace n3
-// CHECK-FIXES: }  // namespace n1::n2
-


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


Re: [clang-tools-extra] r315057 - Fix nested namespaces in google-readability-nested-namespace-comments.

2017-10-06 Thread Aaron Ballman via cfe-commits
On Fri, Oct 6, 2017 at 9:27 AM, Alexander Kornienko  wrote:
>
>
> On 6 Oct 2017 14:59, "Aaron Ballman via cfe-commits"
>  wrote:
>
> Author: aaronballman
> Date: Fri Oct  6 05:57:28 2017
> New Revision: 315057
>
> URL: http://llvm.org/viewvc/llvm-project?rev=315057&view=rev
> Log:
> Fix nested namespaces in google-readability-nested-namespace-comments.
>
> Fixes PR34701.
>
> Patch by Alexandru Octavian Buțiu.
>
> Added:
>
> clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
>
>
> Can we rename the test so it starts with the check name? E.g.
> "google-readability-namespace-comments-cxx17" or something else that makes
> sense?

Sure! I've commit in r315060.

~Aaron

>
> Modified:
> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.h
>
> Modified:
> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp?rev=315057&r1=315056&r2=315057&view=diff
> ==
> --- clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
> Fri Oct  6 05:57:28 2017
> @@ -23,7 +23,7 @@ NamespaceCommentCheck::NamespaceCommentC
>   ClangTidyContext *Context)
>  : ClangTidyCheck(Name, Context),
>NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)?
> *"
> -  "namespace( +([a-zA-Z0-9_]+))?\\.?
> *(\\*/)?$",
> +  "namespace( +([a-zA-Z0-9_:]+))?\\.?
> *(\\*/)?$",
>llvm::Regex::IgnoreCase),
>ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
>SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
> @@ -56,6 +56,15 @@ static std::string getNamespaceComment(c
>return Fix;
>  }
>
> +static std::string getNamespaceComment(const std::string &NameSpaceName,
> +   bool InsertLineBreak) {
> +  std::string Fix = "// namespace ";
> +  Fix.append(NameSpaceName);
> +  if (InsertLineBreak)
> +Fix.append("\n");
> +  return Fix;
> +}
> +
>  void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
>const auto *ND = Result.Nodes.getNodeAs("namespace");
>const SourceManager &Sources = *Result.SourceManager;
> @@ -74,11 +83,38 @@ void NamespaceCommentCheck::check(const
>SourceLocation AfterRBrace = ND->getRBraceLoc().getLocWithOffset(1);
>SourceLocation Loc = AfterRBrace;
>Token Tok;
> +  SourceLocation LBracketLocation = ND->getLocation();
> +  SourceLocation NestedNamespaceBegin = LBracketLocation;
> +
> +  // Currently for nested namepsace (n1::n2::...) the AST matcher will
> match foo
> +  // then bar instead of a single match. So if we got a nested namespace we
> have
> +  // to skip the next ones.
> +  for (const auto &EndOfNameLocation : Ends) {
> +if (Sources.isBeforeInTranslationUnit(NestedNamespaceBegin,
> +  EndOfNameLocation))
> +  return;
> +  }
> +  while (Lexer::getRawToken(LBracketLocation, Tok, Sources, getLangOpts())
> ||
> + !Tok.is(tok::l_brace)) {
> +LBracketLocation = LBracketLocation.getLocWithOffset(1);
> +  }
> +
> +  auto TextRange =
> +  Lexer::getAsCharRange(SourceRange(NestedNamespaceBegin,
> LBracketLocation),
> +Sources, getLangOpts());
> +  auto NestedNamespaceName =
> +  Lexer::getSourceText(TextRange, Sources, getLangOpts()).rtrim();
> +  bool IsNested = NestedNamespaceName.contains(':');
> +
> +  if (IsNested)
> +Ends.push_back(LBracketLocation);
> +
>// Skip whitespace until we find the next token.
>while (Lexer::getRawToken(Loc, Tok, Sources, getLangOpts()) ||
>   Tok.is(tok::semi)) {
>  Loc = Loc.getLocWithOffset(1);
>}
> +
>if (!locationsInSameFile(Sources, ND->getRBraceLoc(), Loc))
>  return;
>
> @@ -98,10 +134,14 @@ void NamespaceCommentCheck::check(const
>StringRef NamespaceNameInComment = Groups.size() > 5 ? Groups[5] :
> "";
>StringRef Anonymous = Groups.size() > 3 ? Groups[3] : "";
>
> -  // Check i

Re: [clang-tools-extra] r315060 - Renaming a test to start with the name of the check based on post-commit review feedback; NFC.

2017-10-11 Thread Aaron Ballman via cfe-commits
On Wed, Oct 11, 2017 at 3:29 PM, Alexander Kornienko  wrote:
> On Fri, Oct 6, 2017 at 3:27 PM, Aaron Ballman via cfe-commits
>  wrote:
>>
>> Author: aaronballman
>> Date: Fri Oct  6 06:27:59 2017
>> New Revision: 315060
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=315060&view=rev
>> Log:
>> Renaming a test to start with the name of the check based on post-commit
>> review feedback; NFC.
>>
>> Added:
>>
>> clang-tools-extra/trunk/test/clang-tidy/google-readability-namespace-comments-cxx17
>
>
> Sorry for not being clear. I didn't mean the `.cpp` extension should be
> removed. This effectively disables the test, since lit only runs tests in
> files with certain extensions (under clang-tools-extra/test these are '.c',
> '.cpp', '.hpp', '.m', '.mm', '.cu', '.ll', '.cl', '.s', '.modularize',
> '.module-map-checker', '.test').

That's entirely my fault -- I should have recognized that. Sorry for
the trouble!

> I've just renamed the file to *.cpp and the test fails for me:
>
> [0/1] Running the Clang extra tools' regression tests
> FAIL: Clang Tools ::
> clang-tidy/google-readability-namespace-comments-cxx17.cpp (102 of 674)
>  TEST 'Clang Tools ::
> clang-tidy/google-readability-namespace-comments-cxx17.cpp' FAILED
> 
> Script:
> --
> /usr/bin/python2.7
> /src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py
> /src/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp
> google-readability-namespace-comments
> /build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp
> -- -- -std=c++17
> --
> Exit Code: 1
>
> Command Output (stdout):
> --
> Running ['clang-tidy',
> '/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp',
> '-fix', '--checks=-*,google-readability-namespace-comments', '--',
> '-std=c++17', '-nostdinc++']...
>  clang-tidy output ---
>
> --
> -- Fixes -
>
> --
> FileCheck failed:
> /src/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp:13:17:
> error: expected string not found in input
> // CHECK-FIXES: }  // namespace n3
> ^
> /build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp:1:1:
> note: scanning from here
> // RUN: %check_clang_tidy %s google-readability-namespace-comments %t -- --
> -std=c++17
> ^
> /build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp:5:7:
> note: possible intended match here
>   // So that namespace is not empty.
>   ^
>
>
> --
> Command Output (stderr):
> --
> Traceback (most recent call last):
>   File
> "/src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py",
> line 140, in 
> main()
>   File
> "/src/tools/clang/tools/extra/test/../test/clang-tidy/check_clang_tidy.py",
> line 121, in main
> stderr=subprocess.STDOUT)
>   File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
> raise CalledProcessError(retcode, cmd, output=output)
> subprocess.CalledProcessError: Command '['FileCheck',
> '-input-file=/build/tools/clang/tools/extra/test/clang-tidy/Output/google-readability-namespace-comments-cxx17.cpp.tmp.cpp',
> '/src/tools/clang/tools/extra/test/clang-tidy/google-readability-namespace-comments-cxx17.cpp',
> '-check-prefix=CHECK-FIXES', '-strict-whitespace']' returned non-zero exit
> status 1
>
> --
>
> 
> Testing Time: 13.07s
> 
> Failing Tests (1):
> Clang Tools ::
> clang-tidy/google-readability-namespace-comments-cxx17.cpp
>
>   Expected Passes: 673
>   Unexpected Failures: 1
> FAILED: tools/clang/tools/extra/test/CMakeFiles/check-clang-tools
>
>
> Did you experience anything similar? Any ideas?

I now get the same behavior that you're seeing. I'm not certain what's
going on there (and don't have the time to look into it at the
moment), but perhaps Jonas has ideas.

~Aaron

>
>>   - copied unchanged fr

Re: [clang-tools-extra] r315057 - Fix nested namespaces in google-readability-nested-namespace-comments.

2017-10-12 Thread Aaron Ballman via cfe-commits
On Thu, Oct 12, 2017 at 10:01 AM, Alexander Kornienko  wrote:
>
> On Fri, Oct 6, 2017 at 2:57 PM, Aaron Ballman via cfe-commits
>  wrote:
>>
>> Author: aaronballman
>> Date: Fri Oct  6 05:57:28 2017
>> New Revision: 315057
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=315057&view=rev
>> Log:
>> Fix nested namespaces in google-readability-nested-namespace-comments.
>>
>> Fixes PR34701.
>>
>> Patch by Alexandru Octavian Buțiu.
>>
>> Added:
>>
>> clang-tools-extra/trunk/test/clang-tidy/google-readability-nested-namespace-comments.cpp
>> Modified:
>>
>> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.h
>>
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp?rev=315057&r1=315056&r2=315057&view=diff
>>
>> ==
>> ---
>> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp
>> (original)
>> +++
>> clang-tools-extra/trunk/clang-tidy/readability/NamespaceCommentCheck.cpp Fri
>> Oct  6 05:57:28 2017
>> @@ -23,7 +23,7 @@ NamespaceCommentCheck::NamespaceCommentC
>>   ClangTidyContext *Context)
>>  : ClangTidyCheck(Name, Context),
>>NamespaceCommentPattern("^/[/*] *(end (of )?)?
>> *(anonymous|unnamed)? *"
>> -  "namespace( +([a-zA-Z0-9_]+))?\\.?
>> *(\\*/)?$",
>> +  "namespace( +([a-zA-Z0-9_:]+))?\\.?
>> *(\\*/)?$",
>>llvm::Regex::IgnoreCase),
>>ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
>>SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
>> @@ -56,6 +56,15 @@ static std::string getNamespaceComment(c
>>return Fix;
>>  }
>>
>> +static std::string getNamespaceComment(const std::string &NameSpaceName,
>> +   bool InsertLineBreak) {
>> +  std::string Fix = "// namespace ";
>> +  Fix.append(NameSpaceName);
>> +  if (InsertLineBreak)
>> +Fix.append("\n");
>> +  return Fix;
>> +}
>> +
>>  void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result)
>> {
>>const auto *ND = Result.Nodes.getNodeAs("namespace");
>>const SourceManager &Sources = *Result.SourceManager;
>> @@ -74,11 +83,38 @@ void NamespaceCommentCheck::check(const
>>SourceLocation AfterRBrace = ND->getRBraceLoc().getLocWithOffset(1);
>>SourceLocation Loc = AfterRBrace;
>>Token Tok;
>> +  SourceLocation LBracketLocation = ND->getLocation();
>> +  SourceLocation NestedNamespaceBegin = LBracketLocation;
>> +
>> +  // Currently for nested namepsace (n1::n2::...) the AST matcher will
>> match foo
>> +  // then bar instead of a single match. So if we got a nested namespace
>> we have
>> +  // to skip the next ones.
>> +  for (const auto &EndOfNameLocation : Ends) {
>> +if (Sources.isBeforeInTranslationUnit(NestedNamespaceBegin,
>> +  EndOfNameLocation))
>> +  return;
>> +  }
>> +  while (Lexer::getRawToken(LBracketLocation, Tok, Sources,
>> getLangOpts()) ||
>> + !Tok.is(tok::l_brace)) {
>
>
> Now another issue with this revision: the check started triggering an
> assertion failure and incredible slowness (infinite loops?) on some real
> files. I've not yet come up with an isolated test case, but all this seems
> to be happening around this loop.
>
> I'm going to revert this revision.

I think that's the right call. The original review thread is
https://reviews.llvm.org/D38284 if you want to alert the author.

~Aaron

>
>>
>> +LBracketLocation = LBracketLocation.getLocWithOffset(1);
>> +  }
>> +
>> +  auto TextRange =
>> +  Lexer::getAsCharRange(SourceRange(NestedNamespaceBegin,
>> LBracketLocation),
>> +Sources, getLangOpts());
>> +  auto NestedNamespaceName =
>> +  Lexer::getSourceText(TextRange, Sources, getLangOpts()).rtrim();
>> +  bool IsNested = NestedNamespaceName.contains(':');
>> +
>> +  if (IsN

r315856 - Add -f[no-]double-square-bracket-attributes as new driver options to control use of [[]] attributes in all language modes. This is the initial implementation of WG14 N2165, which is a propos

2017-10-15 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Oct 15 08:01:42 2017
New Revision: 315856

URL: http://llvm.org/viewvc/llvm-project?rev=315856&view=rev
Log:
Add -f[no-]double-square-bracket-attributes as new driver options to control 
use of [[]] attributes in all language modes. This is the initial 
implementation of WG14 N2165, which is a proposal to add [[]] attributes to 
C2x, but also allows you to enable these attributes in C++98, or disable them 
in C++11 or later.

Added:
cfe/trunk/test/Misc/ast-dump-c-attr.c
cfe/trunk/test/Parser/c2x-attributes.c
cfe/trunk/test/Parser/c2x-attributes.m
cfe/trunk/test/Sema/attr-deprecated-c2x.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/Attributes.h
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/AttributeList.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=315856&r1=315855&r2=315856&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Oct 15 08:01:42 2017
@@ -210,6 +210,10 @@ class CXX11 : Spelling {
+  string Namespace = namespace;
+}
+
 class Keyword : Spelling;
 class Pragma : Spelling {
   string Namespace = namespace;
@@ -958,7 +962,7 @@ def RenderScriptKernel : Attr {
 
 def Deprecated : InheritableAttr {
   let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
-   CXX11<"","deprecated", 201309>];
+   CXX11<"","deprecated", 201309>, C2x<"", "deprecated">];
   let Args = [StringArgument<"Message", 1>,
   // An optional string argument that enables us to provide a
   // Fix-It.

Modified: cfe/trunk/include/clang/Basic/Attributes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attributes.h?rev=315856&r1=315855&r2=315856&view=diff
==
--- cfe/trunk/include/clang/Basic/Attributes.h (original)
+++ cfe/trunk/include/clang/Basic/Attributes.h Sun Oct 15 08:01:42 2017
@@ -26,6 +26,8 @@ enum class AttrSyntax {
   Microsoft,
   // Is the identifier known as a C++-style attribute?
   CXX,
+  // Is the identifier known as a C-style attribute?
+  C,
   // Is the identifier known as a pragma attribute?
   Pragma
 };

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=315856&r1=315855&r2=315856&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Sun Oct 15 08:01:42 2017
@@ -137,6 +137,8 @@ LANGOPT(GNUAsm, 1, 1, "GNU-s
 LANGOPT(CoroutinesTS  , 1, 0, "C++ coroutines TS")
 LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template 
template arguments")
 
+LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
+
 BENIGN_LANGOPT(ThreadsafeStatics , 1, 1, "thread-safe static initializers")
 LANGOPT(POSIXThreads  , 1, 0, "POSIX thread support")
 LANGOPT(Blocks, 1, 0, "blocks extension to C")

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=315856&r1=315855&r2=315856&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Sun Oct 15 08:01:42 2017
@@ -606,6 +606,13 @@ def fastf : Flag<["-"], "fastf">, Group<
 def fast : Flag<["-"], "fast">, Group;
 def fasynchronous_unwind_tables : Flag<["-"], "fasynchronous-unwind-tables">, 
Group;
 
+def fdouble_square_bracket_attributes : Flag<[ "-" ], 
"fdouble-square-bracket-attributes">,
+  Group, Flags<[DriverOption, CC1Option]>,
+  HelpText<"Enable '[[]]' attributes in all C and C++ language modes">;
+def fno_double_square_bracket_attributes : Flag<[ "-" ], 
"fno-fdouble-square-bracket-attributes">,
+  Group, Flags<[DriverOption]>,
+  HelpText<"Disable '[[]]' attributes in all C and C++ language modes">;
+
 def fautolink : Flag <["-"], "fautolink">, Group;
 def fno_autolink : Flag <["-"], "fno-autolink">, Group,
   Flags<[DriverOption, CC1Option]>,

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=315856&

Re: r315856 - Add -f[no-]double-square-bracket-attributes as new driver options to control use of [[]] attributes in all language modes. This is the initial implementation of WG14 N2165, which is a pr

2017-10-15 Thread Aaron Ballman via cfe-commits
On Sun, Oct 15, 2017 at 12:52 PM, Saleem Abdulrasool
 wrote:
>
>
> On Sun, Oct 15, 2017 at 8:01 AM, Aaron Ballman via cfe-commits
>  wrote:
>>
>> Author: aaronballman
>> Date: Sun Oct 15 08:01:42 2017
>> New Revision: 315856
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=315856&view=rev
>> Log:
>> Add -f[no-]double-square-bracket-attributes as new driver options to
>> control use of [[]] attributes in all language modes. This is the initial
>> implementation of WG14 N2165, which is a proposal to add [[]] attributes to
>> C2x, but also allows you to enable these attributes in C++98, or disable
>> them in C++11 or later.
>
>
> Since this is a new option and one that GCC doesn't have ... it seems pretty
> cumbersome to write.  Would you be open to renaming this?  Perhaps something
> like `-fgeneralized-attributes` which IIRC was the name for the C++11
> specification.

I have no problems renaming it, but I'm not keen on "generalized". The
name used in the WG21 proposal papers was "general attributes" (sort
of, the term was used once in the paper, and not in the title), but I
don't think I've seen any community consensus on calling them that.
While the current name is a mouthful, it's at least descriptive as to
which of the four attribute syntaxes we're talking about.

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


r316026 - Enable support for the [[nodiscard]] attribute from WG14 N2050 when enabling double square bracket attributes in C code.

2017-10-17 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Oct 17 13:33:35 2017
New Revision: 316026

URL: http://llvm.org/viewvc/llvm-project?rev=316026&view=rev
Log:
Enable support for the [[nodiscard]] attribute from WG14 N2050 when enabling 
double square bracket attributes in C code.

Added:
cfe/trunk/test/Sema/c2x-nodiscard.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/AST/Decl.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=316026&r1=316025&r2=316026&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Oct 17 13:33:35 2017
@@ -2004,10 +2004,10 @@ def WarnUnused : InheritableAttr {
 }
 
 def WarnUnusedResult : InheritableAttr {
-  let Spellings = [CXX11<"", "nodiscard", 201603>,
+  let Spellings = [CXX11<"", "nodiscard", 201603>, C2x<"", "nodiscard">,
CXX11<"clang", "warn_unused_result">,
GCC<"warn_unused_result">];
-  let Subjects = SubjectList<[ObjCMethod, Enum, CXXRecord, FunctionLike],
+  let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike],
  WarnDiag, "ExpectedFunctionMethodEnumOrClass">;
   let Documentation = [WarnUnusedResultsDocs];
 }

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=316026&r1=316025&r2=316026&view=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Oct 17 13:33:35 2017
@@ -3056,7 +3056,8 @@ SourceRange FunctionDecl::getExceptionSp
 const Attr *FunctionDecl::getUnusedResultAttr() const {
   QualType RetType = getReturnType();
   if (RetType->isRecordType()) {
-if (const CXXRecordDecl *Ret = RetType->getAsCXXRecordDecl()) {
+if (const auto *Ret =
+dyn_cast_or_null(RetType->getAsTagDecl())) {
   if (const auto *R = Ret->getAttr())
 return R;
 }

Added: cfe/trunk/test/Sema/c2x-nodiscard.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c2x-nodiscard.c?rev=316026&view=auto
==
--- cfe/trunk/test/Sema/c2x-nodiscard.c (added)
+++ cfe/trunk/test/Sema/c2x-nodiscard.c Tue Oct 17 13:33:35 2017
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
+
+struct [[nodiscard]] S1 { // ok
+  int i;
+};
+struct [[nodiscard nodiscard]] S2 { // expected-error {{attribute 'nodiscard' 
cannot appear multiple times in an attribute specifier}}
+  int i;
+};
+struct [[nodiscard("Wrong")]] S3 { // expected-error {{'nodiscard' cannot have 
an argument list}}
+  int i;
+};
+
+[[nodiscard]] int f1(void);
+enum [[nodiscard]] E1 { One };
+
+[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only applies 
to functions, methods, enums, and classes}}
+
+struct [[nodiscard]] S4 {
+  int i;
+};
+struct S4 get_s(void);
+
+enum [[nodiscard]] E2 { Two };
+enum E2 get_e(void);
+
+[[nodiscard]] int get_i();
+
+void f2(void) {
+  get_s(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
+  get_i(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
+  get_e(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
+
+  // Okay, warnings are not encouraged
+  (void)get_s();
+  (void)get_i();
+  (void)get_e();
+}
+
+struct [[nodiscard]] error_info{
+  int i;
+};
+
+struct error_info enable_missile_safety_mode(void);
+void launch_missiles(void);
+void test_missiles(void) {
+  enable_missile_safety_mode(); // expected-warning {{ignoring return value of 
function declared with 'nodiscard'}}
+  launch_missiles();
+}
+


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


Re: r316026 - Enable support for the [[nodiscard]] attribute from WG14 N2050 when enabling double square bracket attributes in C code.

2017-10-17 Thread Aaron Ballman via cfe-commits
I said WG14 N2050 when I meant N2051. My fat fingers and I apologize
for the confusion with the commit log.

~Aaron

On Tue, Oct 17, 2017 at 4:33 PM, Aaron Ballman via cfe-commits
 wrote:
> Author: aaronballman
> Date: Tue Oct 17 13:33:35 2017
> New Revision: 316026
>
> URL: http://llvm.org/viewvc/llvm-project?rev=316026&view=rev
> Log:
> Enable support for the [[nodiscard]] attribute from WG14 N2050 when enabling 
> double square bracket attributes in C code.
>
> Added:
> cfe/trunk/test/Sema/c2x-nodiscard.c
> Modified:
> cfe/trunk/include/clang/Basic/Attr.td
> cfe/trunk/lib/AST/Decl.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=316026&r1=316025&r2=316026&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Tue Oct 17 13:33:35 2017
> @@ -2004,10 +2004,10 @@ def WarnUnused : InheritableAttr {
>  }
>
>  def WarnUnusedResult : InheritableAttr {
> -  let Spellings = [CXX11<"", "nodiscard", 201603>,
> +  let Spellings = [CXX11<"", "nodiscard", 201603>, C2x<"", "nodiscard">,
> CXX11<"clang", "warn_unused_result">,
> GCC<"warn_unused_result">];
> -  let Subjects = SubjectList<[ObjCMethod, Enum, CXXRecord, FunctionLike],
> +  let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike],
>   WarnDiag, "ExpectedFunctionMethodEnumOrClass">;
>let Documentation = [WarnUnusedResultsDocs];
>  }
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=316026&r1=316025&r2=316026&view=diff
> ==
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Tue Oct 17 13:33:35 2017
> @@ -3056,7 +3056,8 @@ SourceRange FunctionDecl::getExceptionSp
>  const Attr *FunctionDecl::getUnusedResultAttr() const {
>QualType RetType = getReturnType();
>if (RetType->isRecordType()) {
> -if (const CXXRecordDecl *Ret = RetType->getAsCXXRecordDecl()) {
> +if (const auto *Ret =
> +dyn_cast_or_null(RetType->getAsTagDecl())) {
>if (const auto *R = Ret->getAttr())
>  return R;
>  }
>
> Added: cfe/trunk/test/Sema/c2x-nodiscard.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c2x-nodiscard.c?rev=316026&view=auto
> ==
> --- cfe/trunk/test/Sema/c2x-nodiscard.c (added)
> +++ cfe/trunk/test/Sema/c2x-nodiscard.c Tue Oct 17 13:33:35 2017
> @@ -0,0 +1,49 @@
> +// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify 
> %s
> +
> +struct [[nodiscard]] S1 { // ok
> +  int i;
> +};
> +struct [[nodiscard nodiscard]] S2 { // expected-error {{attribute 
> 'nodiscard' cannot appear multiple times in an attribute specifier}}
> +  int i;
> +};
> +struct [[nodiscard("Wrong")]] S3 { // expected-error {{'nodiscard' cannot 
> have an argument list}}
> +  int i;
> +};
> +
> +[[nodiscard]] int f1(void);
> +enum [[nodiscard]] E1 { One };
> +
> +[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only 
> applies to functions, methods, enums, and classes}}
> +
> +struct [[nodiscard]] S4 {
> +  int i;
> +};
> +struct S4 get_s(void);
> +
> +enum [[nodiscard]] E2 { Two };
> +enum E2 get_e(void);
> +
> +[[nodiscard]] int get_i();
> +
> +void f2(void) {
> +  get_s(); // expected-warning {{ignoring return value of function declared 
> with 'nodiscard' attribute}}
> +  get_i(); // expected-warning {{ignoring return value of function declared 
> with 'nodiscard' attribute}}
> +  get_e(); // expected-warning {{ignoring return value of function declared 
> with 'nodiscard' attribute}}
> +
> +  // Okay, warnings are not encouraged
> +  (void)get_s();
> +  (void)get_i();
> +  (void)get_e();
> +}
> +
> +struct [[nodiscard]] error_info{
> +  int i;
> +};
> +
> +struct error_info enable_missile_safety_mode(void);
> +void launch_missiles(void);
> +void test_missiles(void) {
> +  enable_missile_safety_mode(); // expected-warning {{ignoring return value 
> of function declared with 'nodiscard'}}
> +  launch_missiles();
> +}
> +
>
>
> ___
> 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


r316028 - This test case was missing -fsyntax-only, so I've added it. NFC to the actual test contents, just how the test is executed.

2017-10-17 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Oct 17 13:49:30 2017
New Revision: 316028

URL: http://llvm.org/viewvc/llvm-project?rev=316028&view=rev
Log:
This test case was missing -fsyntax-only, so I've added it. NFC to the actual 
test contents, just how the test is executed.

Modified:
cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp?rev=316028&r1=316027&r2=316028&view=diff
==
--- cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp Tue Oct 17 
13:49:30 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++1z -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++1z -verify %s
 
 void f(int n) {
   switch (n) {


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


Re: r315856 - Add -f[no-]double-square-bracket-attributes as new driver options to control use of [[]] attributes in all language modes. This is the initial implementation of WG14 N2165, which is a pr

2017-10-18 Thread Aaron Ballman via cfe-commits
I'll take a look, thank you for pointing it out (and sorry for the trouble)!

~Aaron

On Tue, Oct 17, 2017 at 9:56 PM, Galina Kistanova  wrote:
> Hello Aaron,
>
> This commit broke one our builders:
>
> http://lab.llvm.org:8011/builders/ubuntu-gcc7.1-werror/builds/2272
>
> . . .
> FAILED: /usr/local/gcc-7.1/bin/g++-7.1   -DGTEST_HAS_RTTI=0 -D_DEBUG
> -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
> -D__STDC_LIMIT_MACROS -Itools/clang/lib/Basic
> -I/home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/lib/Basic
> -I/home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/include
> -Itools/clang/include -Iinclude
> -I/home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/include
> -Wno-noexcept-type -fPIC -fvisibility-inlines-hidden -Werror
> -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings
> -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long
> -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment
> -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual
> -fno-strict-aliasing -O3  -fPIC   -UNDEBUG  -fno-exceptions -fno-rtti -MD
> -MT tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/Attributes.cpp.o -MF
> tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/Attributes.cpp.o.d -o
> tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/Attributes.cpp.o -c
> /home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/lib/Basic/Attributes.cpp
> In file included from
> /home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/lib/Basic/Attributes.cpp:15:0:
> tools/clang/include/clang/Basic/AttrHasAttributeImpl.inc: In function ‘int
> clang::hasAttribute(clang::AttrSyntax, const clang::IdentifierInfo*, const
> clang::IdentifierInfo*, const clang::TargetInfo&, const
> clang::LangOptions&)’:
> tools/clang/include/clang/Basic/AttrHasAttributeImpl.inc:526:8: error: this
> statement may fall through [-Werror=implicit-fallthrough=]
>  } else if (Scope->getName() == "gsl") {
> ^~
> tools/clang/include/clang/Basic/AttrHasAttributeImpl.inc:532:1: note: here
>  case AttrSyntax::C: {
>  ^~~~
> cc1plus: all warnings being treated as errors
>
> Please have a look?
>
> Thanks
>
> Galina
>
> On Sun, Oct 15, 2017 at 8:01 AM, Aaron Ballman via cfe-commits
>  wrote:
>>
>> Author: aaronballman
>> Date: Sun Oct 15 08:01:42 2017
>> New Revision: 315856
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=315856&view=rev
>> Log:
>> Add -f[no-]double-square-bracket-attributes as new driver options to
>> control use of [[]] attributes in all language modes. This is the initial
>> implementation of WG14 N2165, which is a proposal to add [[]] attributes to
>> C2x, but also allows you to enable these attributes in C++98, or disable
>> them in C++11 or later.
>>
>> Added:
>> cfe/trunk/test/Misc/ast-dump-c-attr.c
>> cfe/trunk/test/Parser/c2x-attributes.c
>> cfe/trunk/test/Parser/c2x-attributes.m
>> cfe/trunk/test/Sema/attr-deprecated-c2x.c
>> Modified:
>> cfe/trunk/include/clang/Basic/Attr.td
>> cfe/trunk/include/clang/Basic/Attributes.h
>> cfe/trunk/include/clang/Basic/LangOptions.def
>> cfe/trunk/include/clang/Driver/Options.td
>> cfe/trunk/include/clang/Parse/Parser.h
>> cfe/trunk/include/clang/Sema/AttributeList.h
>> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>> cfe/trunk/lib/Lex/Lexer.cpp
>> cfe/trunk/lib/Parse/ParseDecl.cpp
>> cfe/trunk/lib/Parse/ParseDeclCXX.cpp
>> cfe/trunk/lib/Sema/AttributeList.cpp
>> cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/Attr.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=315856&r1=315855&r2=315856&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Basic/Attr.td (original)
>> +++ cfe/trunk/include/clang/Basic/Attr.td Sun Oct 15 08:01:42 2017
>> @@ -210,6 +210,10 @@ class CXX11>string Namespace = namespace;
>>int Version = version;
>>  }
>> +class C2x : Spelling {
>> +  string Namespace = namespace;
>> +}
>> +
>>  class Keyword : Spelling;
>>  class Pragma : Spelling {
>>string Namespace = namespace;
>> @@ -958,7 +962,7 @@ def RenderScriptKernel : Attr {
>>
>>  def Deprecated : InheritableAttr {
>>let Spellings = [GCC<"deprecated">, Declspec<"deprecated">,
>> -   CXX11<"","deprecated&

r316075 - Silence -Wimplicit-fallthrough warnings with the generated code; NFC.

2017-10-18 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Oct 18 05:11:58 2017
New Revision: 316075

URL: http://llvm.org/viewvc/llvm-project?rev=316075&view=rev
Log:
Silence -Wimplicit-fallthrough warnings with the generated code; NFC.

Modified:
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=316075&r1=316074&r2=316075&view=diff
==
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Wed Oct 18 05:11:58 2017
@@ -2794,7 +2794,7 @@ void EmitClangAttrHasAttrImpl(RecordKeep
   GenerateHasAttrSpellingStringSwitch(I->second, OS, Spelling, I->first);
   OS << "}";
 }
-OS << "\n}\n";
+OS << "\n} break;\n";
   };
   fn("CXX11", "CXX", CXX);
   fn("C2x", "C", C2x);


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


r316083 - Enable support for the [[fallthrough]] attribute from WG14 N2052 when enabling double square bracket attributes in C code.

2017-10-18 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Oct 18 07:33:27 2017
New Revision: 316083

URL: http://llvm.org/viewvc/llvm-project?rev=316083&view=rev
Log:
Enable support for the [[fallthrough]] attribute from WG14 N2052 when enabling 
double square bracket attributes in C code.

Added:
cfe/trunk/test/Sema/c2x-fallthrough.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=316083&r1=316082&r2=316083&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Oct 18 07:33:27 2017
@@ -1009,7 +1009,7 @@ def ExtVectorType : Attr {
 }
 
 def FallThrough : StmtAttr {
-  let Spellings = [CXX11<"", "fallthrough", 201603>,
+  let Spellings = [CXX11<"", "fallthrough", 201603>, C2x<"", "fallthrough">,
CXX11<"clang", "fallthrough">];
 //  let Subjects = [NullStmt];
   let Documentation = [FallthroughDocs];

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=316083&r1=316082&r2=316083&view=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Wed Oct 18 07:33:27 2017
@@ -1291,16 +1291,15 @@ static StringRef getFallthroughAttrSpell
 
 static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC,
 bool PerFunction) {
-  // Only perform this analysis when using C++11.  There is no good workflow
-  // for this warning when not using C++11.  There is no good way to silence
-  // the warning (no attribute is available) unless we are using C++11's 
support
-  // for generalized attributes.  Once could use pragmas to silence the 
warning,
-  // but as a general solution that is gross and not in the spirit of this
-  // warning.
+  // Only perform this analysis when using [[]] attributes. There is no good
+  // workflow for this warning when not using C++11. There is no good way to
+  // silence the warning (no attribute is available) unless we are using 
+  // [[]] attributes. One could use pragmas to silence the warning, but as a
+  // general solution that is gross and not in the spirit of this warning.
   //
-  // NOTE: This an intermediate solution.  There are on-going discussions on
+  // NOTE: This an intermediate solution. There are on-going discussions on
   // how to properly support this warning outside of C++11 with an annotation.
-  if (!AC.getASTContext().getLangOpts().CPlusPlus11)
+  if (!AC.getASTContext().getLangOpts().DoubleSquareBracketAttributes)
 return;
 
   FallthroughMapper FM(S);

Added: cfe/trunk/test/Sema/c2x-fallthrough.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c2x-fallthrough.c?rev=316083&view=auto
==
--- cfe/trunk/test/Sema/c2x-fallthrough.c (added)
+++ cfe/trunk/test/Sema/c2x-fallthrough.c Wed Oct 18 07:33:27 2017
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
+
+void f(int n) {
+  switch (n) {
+  case 0:
+n += 1;
+[[fallthrough]]; // ok
+  case 1:
+if (n) {
+  [[fallthrough]]; // ok
+} else {
+  return;
+}
+  case 2:
+for (int n = 0; n != 10; ++n)
+  [[fallthrough]]; // expected-error {{does not directly precede switch 
label}}
+  case 3:
+while (1)
+  [[fallthrough]]; // expected-error {{does not directly precede switch 
label}}
+  case 4:
+while (0)
+  [[fallthrough]]; // expected-error {{does not directly precede switch 
label}}
+  case 5:
+do [[fallthrough]]; while (1); // expected-error {{does not directly 
precede switch label}}
+  case 6:
+do [[fallthrough]]; while (0); // expected-error {{does not directly 
precede switch label}}
+  case 7:
+switch (n) {
+case 0:
+  // FIXME: This should be an error, even though the next thing we do is to
+  // fall through in an outer switch statement.
+  [[fallthrough]];
+}
+  case 8:
+[[fallthrough]]; // expected-error {{does not directly precede switch 
label}}
+goto label;
+  label:
+  case 9:
+n += 1;
+  case 10: // no warning, -Wimplicit-fallthrough is not enabled in this test, 
and does not need to
+   // be enabled for these diagnostics to be produced.
+break;
+  }
+}
+
+[[fallthrough]] typedef int n; // expected-error {{'fallthrough' attribute 
cannot be applied to a declaration}}
+typedef int [[fallthrough]] n; // expected-error {{'fallthrough' attribute 
cannot be applied to types}}
+typedef int n [[fallthrough]]; // expected-error {{'fallthrough' attribute 
cannot be applied to a decla

Re: r315856 - Add -f[no-]double-square-bracket-attributes as new driver options to control use of [[]] attributes in all language modes. This is the initial implementation of WG14 N2165, which is a pr

2017-10-18 Thread Aaron Ballman via cfe-commits
Thanks for pointing the breakage out -- it should be fixed with r316075.

~Aaron

On Wed, Oct 18, 2017 at 7:50 AM, Aaron Ballman  wrote:
> I'll take a look, thank you for pointing it out (and sorry for the trouble)!
>
> ~Aaron
>
> On Tue, Oct 17, 2017 at 9:56 PM, Galina Kistanova  
> wrote:
>> Hello Aaron,
>>
>> This commit broke one our builders:
>>
>> http://lab.llvm.org:8011/builders/ubuntu-gcc7.1-werror/builds/2272
>>
>> . . .
>> FAILED: /usr/local/gcc-7.1/bin/g++-7.1   -DGTEST_HAS_RTTI=0 -D_DEBUG
>> -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS
>> -D__STDC_LIMIT_MACROS -Itools/clang/lib/Basic
>> -I/home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/lib/Basic
>> -I/home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/include
>> -Itools/clang/include -Iinclude
>> -I/home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/include
>> -Wno-noexcept-type -fPIC -fvisibility-inlines-hidden -Werror
>> -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings
>> -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long
>> -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment
>> -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual
>> -fno-strict-aliasing -O3  -fPIC   -UNDEBUG  -fno-exceptions -fno-rtti -MD
>> -MT tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/Attributes.cpp.o -MF
>> tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/Attributes.cpp.o.d -o
>> tools/clang/lib/Basic/CMakeFiles/clangBasic.dir/Attributes.cpp.o -c
>> /home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/lib/Basic/Attributes.cpp
>> In file included from
>> /home/buildslave/am1i-slv2/ubuntu-gcc7.1-werror/llvm/tools/clang/lib/Basic/Attributes.cpp:15:0:
>> tools/clang/include/clang/Basic/AttrHasAttributeImpl.inc: In function ‘int
>> clang::hasAttribute(clang::AttrSyntax, const clang::IdentifierInfo*, const
>> clang::IdentifierInfo*, const clang::TargetInfo&, const
>> clang::LangOptions&)’:
>> tools/clang/include/clang/Basic/AttrHasAttributeImpl.inc:526:8: error: this
>> statement may fall through [-Werror=implicit-fallthrough=]
>>  } else if (Scope->getName() == "gsl") {
>> ^~
>> tools/clang/include/clang/Basic/AttrHasAttributeImpl.inc:532:1: note: here
>>  case AttrSyntax::C: {
>>  ^~~~
>> cc1plus: all warnings being treated as errors
>>
>> Please have a look?
>>
>> Thanks
>>
>> Galina
>>
>> On Sun, Oct 15, 2017 at 8:01 AM, Aaron Ballman via cfe-commits
>>  wrote:
>>>
>>> Author: aaronballman
>>> Date: Sun Oct 15 08:01:42 2017
>>> New Revision: 315856
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=315856&view=rev
>>> Log:
>>> Add -f[no-]double-square-bracket-attributes as new driver options to
>>> control use of [[]] attributes in all language modes. This is the initial
>>> implementation of WG14 N2165, which is a proposal to add [[]] attributes to
>>> C2x, but also allows you to enable these attributes in C++98, or disable
>>> them in C++11 or later.
>>>
>>> Added:
>>> cfe/trunk/test/Misc/ast-dump-c-attr.c
>>> cfe/trunk/test/Parser/c2x-attributes.c
>>> cfe/trunk/test/Parser/c2x-attributes.m
>>> cfe/trunk/test/Sema/attr-deprecated-c2x.c
>>> Modified:
>>> cfe/trunk/include/clang/Basic/Attr.td
>>> cfe/trunk/include/clang/Basic/Attributes.h
>>> cfe/trunk/include/clang/Basic/LangOptions.def
>>> cfe/trunk/include/clang/Driver/Options.td
>>> cfe/trunk/include/clang/Parse/Parser.h
>>> cfe/trunk/include/clang/Sema/AttributeList.h
>>> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>>> cfe/trunk/lib/Lex/Lexer.cpp
>>> cfe/trunk/lib/Parse/ParseDecl.cpp
>>> cfe/trunk/lib/Parse/ParseDeclCXX.cpp
>>> cfe/trunk/lib/Sema/AttributeList.cpp
>>> cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
>>>
>>> Modified: cfe/trunk/include/clang/Basic/Attr.td
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=315856&r1=315855&r2=315856&view=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/Basic/Attr.td (original)
>>> +++ cfe/trunk/include/clang/Basic/Attr.td Sun Oct 15 08:01:42 2017
>>> @@ -210,6 +210,10 @@ class CXX11>>string Namespace = namespace;
>>>int Version = ve

r316086 - Silencing a redefinition warning that was not germane to the test.

2017-10-18 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Oct 18 07:48:33 2017
New Revision: 316086

URL: http://llvm.org/viewvc/llvm-project?rev=316086&view=rev
Log:
Silencing a redefinition warning that was not germane to the test.

Modified:
cfe/trunk/test/Sema/c2x-fallthrough.c

Modified: cfe/trunk/test/Sema/c2x-fallthrough.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c2x-fallthrough.c?rev=316086&r1=316085&r2=316086&view=diff
==
--- cfe/trunk/test/Sema/c2x-fallthrough.c (original)
+++ cfe/trunk/test/Sema/c2x-fallthrough.c Wed Oct 18 07:48:33 2017
@@ -43,9 +43,9 @@ void f(int n) {
   }
 }
 
-[[fallthrough]] typedef int n; // expected-error {{'fallthrough' attribute 
cannot be applied to a declaration}}
-typedef int [[fallthrough]] n; // expected-error {{'fallthrough' attribute 
cannot be applied to types}}
-typedef int n [[fallthrough]]; // expected-error {{'fallthrough' attribute 
cannot be applied to a declaration}}
+[[fallthrough]] typedef int n1; // expected-error {{'fallthrough' attribute 
cannot be applied to a declaration}}
+typedef int [[fallthrough]] n2; // expected-error {{'fallthrough' attribute 
cannot be applied to types}}
+typedef int n3 [[fallthrough]]; // expected-error {{'fallthrough' attribute 
cannot be applied to a declaration}}
 
 enum [[fallthrough]] E { // expected-error {{'fallthrough' attribute cannot be 
applied to a declaration}}
   One


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


r316096 - Enable support for the [[maybe_unused]] attribute from WG14 N2053 when enabling double square bracket attributes in C code.

2017-10-18 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Oct 18 09:59:27 2017
New Revision: 316096

URL: http://llvm.org/viewvc/llvm-project?rev=316096&view=rev
Log:
Enable support for the [[maybe_unused]] attribute from WG14 N2053 when enabling 
double square bracket attributes in C code.

Added:
cfe/trunk/test/Sema/c2x-maybe_unused-errors.c
cfe/trunk/test/Sema/c2x-maybe_unused.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=316096&r1=316095&r2=316096&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Oct 18 09:59:27 2017
@@ -1936,7 +1936,8 @@ def ObjCRequiresPropertyDefs : Inheritab
 }
 
 def Unused : InheritableAttr {
-  let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">];
+  let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">,
+   C2x<"", "maybe_unused">];
   let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
   Field, ObjCMethod, FunctionLike], WarnDiag,
  "ExpectedForMaybeUnused">;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=316096&r1=316095&r2=316096&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Oct 18 09:59:27 2017
@@ -79,7 +79,8 @@ static void DiagnoseUnusedOfDecl(Sema &S
   if (const auto *A = D->getAttr()) {
 // [[maybe_unused]] should not diagnose uses, but __attribute__((unused))
 // should diagnose them.
-if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused) {
+if (A->getSemanticSpelling() != UnusedAttr::CXX11_maybe_unused &&
+A->getSemanticSpelling() != UnusedAttr::C2x_maybe_unused) {
   const Decl *DC = cast_or_null(S.getCurObjCLexicalContext());
   if (DC && !DC->hasAttr())
 S.Diag(Loc, diag::warn_used_but_marked_unused) << D->getDeclName();

Added: cfe/trunk/test/Sema/c2x-maybe_unused-errors.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c2x-maybe_unused-errors.c?rev=316096&view=auto
==
--- cfe/trunk/test/Sema/c2x-maybe_unused-errors.c (added)
+++ cfe/trunk/test/Sema/c2x-maybe_unused-errors.c Wed Oct 18 09:59:27 2017
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused -fdouble-square-bracket-attributes 
-verify %s
+
+struct [[maybe_unused]] S1 { // ok
+  int a [[maybe_unused]];
+};
+struct [[maybe_unused maybe_unused]] S2 { // expected-error {{attribute 
'maybe_unused' cannot appear multiple times in an attribute specifier}}
+  int a;
+};
+struct [[maybe_unused("Wrong")]] S3 { // expected-error {{'maybe_unused' 
cannot have an argument list}}
+  int a;
+};
+

Added: cfe/trunk/test/Sema/c2x-maybe_unused.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c2x-maybe_unused.c?rev=316096&view=auto
==
--- cfe/trunk/test/Sema/c2x-maybe_unused.c (added)
+++ cfe/trunk/test/Sema/c2x-maybe_unused.c Wed Oct 18 09:59:27 2017
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused -fdouble-square-bracket-attributes 
-verify %s
+
+struct [[maybe_unused]] S1 { // ok
+  int a [[maybe_unused]];
+};
+
+enum [[maybe_unused]] E1 {
+  EnumVal [[maybe_unused]]
+};
+
+[[maybe_unused]] void unused_func([[maybe_unused]] int parm) {
+  typedef int maybe_unused_int [[maybe_unused]];
+  [[maybe_unused]] int I;
+}
+
+void f1(void) {
+  int x; // expected-warning {{unused variable}}
+  typedef int I; // expected-warning {{unused typedef 'I'}}
+
+  // Should not warn about these due to not being used.
+  [[maybe_unused]] int y;
+  typedef int maybe_unused_int [[maybe_unused]];
+
+  // Should not warn about these uses.
+  struct S1 s;
+  maybe_unused_int test;
+  y = 12;
+}
+
+void f2(void);
+[[maybe_unused]] void f2(void);
+
+void f2(void) {
+}
+


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


r316184 - These attributes are supported by GCC with the gnu vendor namespace for C++11-style attributes. Enabling the gnu namespace by switching to the GCC spelling.

2017-10-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Oct 19 14:09:39 2017
New Revision: 316184

URL: http://llvm.org/viewvc/llvm-project?rev=316184&view=rev
Log:
These attributes are supported by GCC with the gnu vendor namespace for 
C++11-style attributes. Enabling the gnu namespace by switching to the GCC 
spelling.

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

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=316184&r1=316183&r2=316184&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Oct 19 14:09:39 2017
@@ -611,7 +611,7 @@ def Annotate : InheritableParamAttr {
 def ARMInterrupt : InheritableAttr, TargetSpecificAttr {
   // NOTE: If you add any additional spellings, MSP430Interrupt's,
   // MipsInterrupt's and AnyX86Interrupt's spellings must match.
-  let Spellings = [GNU<"interrupt">];
+  let Spellings = [GCC<"interrupt">];
   let Args = [EnumArgument<"Interrupt", "InterruptType",
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", ""],
["IRQ", "FIQ", "SWI", "ABORT", "UNDEF", "Generic"],
@@ -622,14 +622,14 @@ def ARMInterrupt : InheritableAttr, Targ
 }
 
 def AVRInterrupt : InheritableAttr, TargetSpecificAttr {
-  let Spellings = [GNU<"interrupt">];
+  let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
   let ParseKind = "Interrupt";
   let Documentation = [AVRInterruptDocs];
 }
 
 def AVRSignal : InheritableAttr, TargetSpecificAttr {
-  let Spellings = [GNU<"signal">];
+  let Spellings = [GCC<"signal">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [AVRSignalDocs];
 }
@@ -1158,7 +1158,7 @@ def MSABI : InheritableAttr {
 def MSP430Interrupt : InheritableAttr, TargetSpecificAttr {
   // NOTE: If you add any additional spellings, ARMInterrupt's, MipsInterrupt's
   // and AnyX86Interrupt's spellings must match.
-  let Spellings = [GNU<"interrupt">];
+  let Spellings = [GCC<"interrupt">];
   let Args = [UnsignedArgument<"Number">];
   let ParseKind = "Interrupt";
   let HasCustomParsing = 1;
@@ -1174,7 +1174,7 @@ def Mips16 : InheritableAttr, TargetSpec
 def MipsInterrupt : InheritableAttr, TargetSpecificAttr {
   // NOTE: If you add any additional spellings, ARMInterrupt's,
   // MSP430Interrupt's and AnyX86Interrupt's spellings must match.
-  let Spellings = [GNU<"interrupt">];
+  let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[Function]>;
   let Args = [EnumArgument<"Interrupt", "InterruptType",
["vector=sw0", "vector=sw1", "vector=hw0",
@@ -1692,7 +1692,7 @@ def WorkGroupSizeHint :  InheritableAttr
 }
 
 def InitPriority : InheritableAttr {
-  let Spellings = [GNU<"init_priority">];
+  let Spellings = [GCC<"init_priority">];
   let Args = [UnsignedArgument<"Priority">];
   let Subjects = SubjectList<[Var], ErrorDiag>;
   let Documentation = [Undocumented];
@@ -1999,7 +1999,7 @@ def VecReturn : InheritableAttr {
 }
 
 def WarnUnused : InheritableAttr {
-  let Spellings = [GNU<"warn_unused">];
+  let Spellings = [GCC<"warn_unused">];
   let Subjects = SubjectList<[Record]>;
   let Documentation = [Undocumented];
 }
@@ -2041,7 +2041,7 @@ def LTOVisibilityPublic : InheritableAtt
 def AnyX86Interrupt : InheritableAttr, TargetSpecificAttr {
   // NOTE: If you add any additional spellings, ARMInterrupt's,
   // MSP430Interrupt's and MipsInterrupt's spellings must match.
-  let Spellings = [GNU<"interrupt">];
+  let Spellings = [GCC<"interrupt">];
   let Subjects = SubjectList<[HasFunctionProto]>;
   let ParseKind = "Interrupt";
   let HasCustomParsing = 1;


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


r316186 - These attributes are not supported by GCC and should not be in the gnu namespace. Switching from the GCC spelling to the GNU spelling so that they are only supported with __attribute__(()).

2017-10-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Oct 19 14:20:28 2017
New Revision: 316186

URL: http://llvm.org/viewvc/llvm-project?rev=316186&view=rev
Log:
These attributes are not supported by GCC and should not be in the gnu 
namespace. Switching from the GCC spelling to the GNU spelling so that they are 
only supported with __attribute__(()).

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

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=316186&r1=316185&r2=316186&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Oct 19 14:20:28 2017
@@ -1758,23 +1758,23 @@ def StdCall : InheritableAttr {
 }
 
 def SwiftCall : InheritableAttr {
-  let Spellings = [GCC<"swiftcall">];
+  let Spellings = [GNU<"swiftcall">];
 //  let Subjects = SubjectList<[Function]>;
   let Documentation = [SwiftCallDocs];
 }
 
 def SwiftContext : ParameterABIAttr {
-  let Spellings = [GCC<"swift_context">];
+  let Spellings = [GNU<"swift_context">];
   let Documentation = [SwiftContextDocs];
 }
 
 def SwiftErrorResult : ParameterABIAttr {
-  let Spellings = [GCC<"swift_error_result">];
+  let Spellings = [GNU<"swift_error_result">];
   let Documentation = [SwiftErrorResultDocs];
 }
 
 def SwiftIndirectResult : ParameterABIAttr {
-  let Spellings = [GCC<"swift_indirect_result">];
+  let Spellings = [GNU<"swift_indirect_result">];
   let Documentation = [SwiftIndirectResultDocs];
 }
 


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


Attribute spelling policy

2017-10-21 Thread Aaron Ballman via cfe-commits
Attributes come with multiple spelling flavors, but when it comes to
adding new attributes that are not present in other compiler tools
such as GCC or MSVC, we have done a poor job of being consistent with
which spelling flavors we adopt the attributes under. Some of our
attributes are specified with only an __attribute__ spelling (about
100), while others are specified with both __attribute__ and
[[clang::XXX]] (about 30), and still others are specified as only
[[clang::XXX]] attributes (only 1). This puts additional burden on
developers to remember which attributes are spelled with what syntax
and the various rules surrounding how to write attributes with that
spelling.

I am proposing that we take a more principled approach when adding new
attributes so that we provide a better user experience. Specifically,
when adding an attribute that other vendors do not support, the
attribute should be given an __attribute__ and [[clang::]] spelling
unless there's good reason not to. This is not a novel proposal -- GCC
supports all of their documented __attribute__ spellings under a
[[gnu::XXX]] spelling, and I am proposing we do the same with our
vendor namespace.

Assuming this approach is reasonable to the community, I will add a
CLANG spelling that behaves similar to the GCC spelling in that it
automatically provides both the GNU and CXX11 spellings as
appropriate. There are some attributes for which a [[clang::XXX]]
spelling is not appropriate:
  * attributes that appertain to function declarations but require
accessing the function parameters, such as disable_if or
requires_capability
  * attributes with GNU spellings whose use is discouraged or
deprecated, such as no_sanitize_memory
  * attributes that are part of other vendor specifications, like CUDA or OpenCL
These deviations are reasonable, but should be documented in Attr.td
near the Spelling definition for the attribute so that it's explicitly
understood why the spelling differs.

Additionally, I intend for the proposed CLANG spelling to be extended
in the future to more easily expose [[clang::XXX]] spellings for
attributes intended to be used in C (with
-fdouble-square-bracket-attributes) as well as C++.

As always, feedback is welcome!

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


r316267 - Fixing broken attribute documentation for __attribute__((noescape)); a code block was missing and the existing code block was missing a mandatory newline.

2017-10-21 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sat Oct 21 09:43:01 2017
New Revision: 316267

URL: http://llvm.org/viewvc/llvm-project?rev=316267&view=rev
Log:
Fixing broken attribute documentation for __attribute__((noescape)); a code 
block was missing and the existing code block was missing a mandatory newline.

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

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=316267&r1=316266&r2=316267&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Sat Oct 21 09:43:01 2017
@@ -142,6 +142,7 @@ annotated with ``noescape`` do not actua
 For example:
 
 .. code-block:: c
+
   int *gp;
 
   void nonescapingFunc(__attribute__((noescape)) int *p) {
@@ -156,6 +157,8 @@ Additionally, when the parameter is a `b
 `, the same restriction
 applies to copies of the block. For example:
 
+.. code-block:: c
+
   typedef void (^BlockTy)();
   BlockTy g0, g1;
 


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


r316269 - Add release notes for the recent -fdouble-square-bracket-attributes and -fno-double-square-bracket-attributes compiler flags.

2017-10-21 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sat Oct 21 09:45:08 2017
New Revision: 316269

URL: http://llvm.org/viewvc/llvm-project?rev=316269&view=rev
Log:
Add release notes for the recent -fdouble-square-bracket-attributes and 
-fno-double-square-bracket-attributes compiler flags.

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=316269&r1=316268&r2=316269&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Sat Oct 21 09:45:08 2017
@@ -103,6 +103,13 @@ New Compiler Flags
 
 - --autocomplete was implemented to obtain a list of flags and its arguments. 
This is used for shell autocompletion.
 
+- The ``-fdouble-square-bracket-attributes`` and corresponding
+  ``-fno-double-square-bracket-attributes`` flags were added to enable or
+  disable [[]] attributes in any language mode. Currently, only a limited
+  number of attributes are supported outside of C++ mode. See the Clang
+  attribute documentation for more information about which attributes are
+  supported for each syntax.
+
 Deprecated Compiler Flags
 -
 


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


r316275 - Fix a typo with -fno-double-square-bracket-attributes and add a test to demonstrate that it works as expected in C++11 mode. Additionally corrected the handling of -fdouble-square-bracket-at

2017-10-21 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sat Oct 21 13:28:58 2017
New Revision: 316275

URL: http://llvm.org/viewvc/llvm-project?rev=316275&view=rev
Log:
Fix a typo with -fno-double-square-bracket-attributes and add a test to 
demonstrate that it works as expected in C++11 mode. Additionally corrected the 
handling of -fdouble-square-bracket-attributes to be properly passed down to 
the cc1 option.

Added:
cfe/trunk/test/SemaCXX/attr-cxx-disabled.cpp
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=316275&r1=316274&r2=316275&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Sat Oct 21 13:28:58 2017
@@ -613,8 +613,8 @@ def fasynchronous_unwind_tables : Flag<[
 def fdouble_square_bracket_attributes : Flag<[ "-" ], 
"fdouble-square-bracket-attributes">,
   Group, Flags<[DriverOption, CC1Option]>,
   HelpText<"Enable '[[]]' attributes in all C and C++ language modes">;
-def fno_double_square_bracket_attributes : Flag<[ "-" ], 
"fno-fdouble-square-bracket-attributes">,
-  Group, Flags<[DriverOption]>,
+def fno_double_square_bracket_attributes : Flag<[ "-" ], 
"fno-double-square-bracket-attributes">,
+  Group, Flags<[DriverOption, CC1Option]>,
   HelpText<"Disable '[[]]' attributes in all C and C++ language modes">;
 
 def fautolink : Flag <["-"], "fautolink">, Group;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=316275&r1=316274&r2=316275&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Sat Oct 21 13:28:58 2017
@@ -4010,6 +4010,9 @@ void Clang::ConstructJob(Compilation &C,
 CmdArgs.push_back("-fcoroutines-ts");
   }
 
+  Args.AddLastArg(CmdArgs, options::OPT_fdouble_square_bracket_attributes,
+  options::OPT_fno_double_square_bracket_attributes);
+
   bool HaveModules = false;
   RenderModulesOptions(C, D, Args, Input, Output, CmdArgs, HaveModules);
 

Added: cfe/trunk/test/SemaCXX/attr-cxx-disabled.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-cxx-disabled.cpp?rev=316275&view=auto
==
--- cfe/trunk/test/SemaCXX/attr-cxx-disabled.cpp (added)
+++ cfe/trunk/test/SemaCXX/attr-cxx-disabled.cpp Sat Oct 21 13:28:58 2017
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -fno-double-square-bracket-attributes -verify 
-pedantic -std=c++11 -DERRORS %s
+// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify 
-pedantic -std=c++11 %s
+
+struct [[]] S {};
+
+#ifdef ERRORS
+// expected-error@-3 {{declaration of anonymous struct must be a definition}}
+// expected-warning@-4 {{declaration does not declare anything}}
+#else
+// expected-no-diagnostics
+#endif
+


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


Re: r316278 - [libclang, bindings]: add spelling location

2017-10-21 Thread Aaron Ballman via cfe-commits
This commit appears to have broken several bots. Can you revert or
quickly fix the issue?

http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/11896
http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/12380

Thanks!

~Aaron

On Sat, Oct 21, 2017 at 4:53 PM, Masud Rahman via cfe-commits
 wrote:
> Author: frutiger
> Date: Sat Oct 21 13:53:49 2017
> New Revision: 316278
>
> URL: http://llvm.org/viewvc/llvm-project?rev=316278&view=rev
> Log:
> [libclang, bindings]: add spelling location
>
>  o) Add a 'Location' class that represents the four properties of a
> physical location
>
>  o) Enhance 'SourceLocation' to provide 'expansion' and 'spelling'
> locations, maintaining backwards compatibility with existing code by
> forwarding the four properties to 'expansion'.
>
>  o) Update the implementation to use 'clang_getExpansionLocation'
> instead of the deprecated 'clang_getInstantiationLocation', which
> has been present since 2011.
>
>  o) Update the implementation of 'clang_getSpellingLocation' to actually
> obtain spelling location instead of file location.
>
> Modified:
> cfe/trunk/bindings/python/clang/cindex.py
> cfe/trunk/bindings/python/tests/cindex/test_location.py
> cfe/trunk/tools/libclang/CXSourceLocation.cpp
>
> Modified: cfe/trunk/bindings/python/clang/cindex.py
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=316278&r1=316277&r2=316278&view=diff
> ==
> --- cfe/trunk/bindings/python/clang/cindex.py (original)
> +++ cfe/trunk/bindings/python/clang/cindex.py Sat Oct 21 13:53:49 2017
> @@ -214,25 +214,45 @@ class _CXString(Structure):
>  assert isinstance(res, _CXString)
>  return conf.lib.clang_getCString(res)
>
> +class Location(object):
> +"""A Location is a specific kind of source location.  A SourceLocation
> +refers to several kinds of locations (e.g.  spelling location vs. 
> expansion
> +location)."""
> +
> +def __init__(self, file, line, column, offset):
> +self._file   = File(file) if file else None
> +self._line   = int(line.value)
> +self._column = int(column.value)
> +self._offset = int(offset.value)
> +
> +
> +@property
> +def file(self):
> +"""Get the file represented by this source location."""
> +return self._file
> +
> +@property
> +def line(self):
> +"""Get the line represented by this source location."""
> +return self._line
> +
> +@property
> +def column(self):
> +"""Get the column represented by this source location."""
> +return self._column
> +
> +@property
> +def offset(self):
> +"""Get the file offset represented by this source location."""
> +return self._offset
>
>  class SourceLocation(Structure):
>  """
>  A SourceLocation represents a particular location within a source file.
>  """
>  _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
> -_data = None
> -
> -def _get_instantiation(self):
> -if self._data is None:
> -f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
> -conf.lib.clang_getInstantiationLocation(self, byref(f), byref(l),
> -byref(c), byref(o))
> -if f:
> -f = File(f)
> -else:
> -f = None
> -self._data = (f, int(l.value), int(c.value), int(o.value))
> -return self._data
> +_expansion = None
> +_spelling = None
>
>  @staticmethod
>  def from_position(tu, file, line, column):
> @@ -253,24 +273,72 @@ class SourceLocation(Structure):
>  return conf.lib.clang_getLocationForOffset(tu, file, offset)
>
>  @property
> +def expansion(self):
> +"""
> +The source location where then entity this object is referring to is
> +expanded.
> +"""
> +if not self._expansion:
> +file   = c_object_p()
> +line   = c_uint()
> +column = c_uint()
> +offset = c_uint()
> +conf.lib.clang_getExpansionLocation(self,
> +byref(file),
> +byref(line),
> +byref(column),
> +byref(offset))
> +
> +self._expansion = Location(file, line, column, offset)
> +return self._expansion
> +
> +@property
> +def spelling(self):
> +"""
> +The source location where then entity this object is referring to is
> +written.
> +"""
> +if not self._spelling:
> +file   = c_object_p()
> +line   = c_uint()
> +column = c_uint()
> +offset = c_uint()
> +conf.lib.clang_getSpellingLocation(self,

r316279 - Reverting r316278 due to failing build bots.

2017-10-21 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sat Oct 21 14:52:48 2017
New Revision: 316279

URL: http://llvm.org/viewvc/llvm-project?rev=316279&view=rev
Log:
Reverting r316278 due to failing build bots.

http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/11896
http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/12380

Modified:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/bindings/python/tests/cindex/test_location.py
cfe/trunk/tools/libclang/CXSourceLocation.cpp

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=316279&r1=316278&r2=316279&view=diff
==
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sat Oct 21 14:52:48 2017
@@ -214,45 +214,25 @@ class _CXString(Structure):
 assert isinstance(res, _CXString)
 return conf.lib.clang_getCString(res)
 
-class Location(object):
-"""A Location is a specific kind of source location.  A SourceLocation
-refers to several kinds of locations (e.g.  spelling location vs. expansion
-location)."""
-
-def __init__(self, file, line, column, offset):
-self._file   = File(file) if file else None
-self._line   = int(line.value)
-self._column = int(column.value)
-self._offset = int(offset.value)
-
-
-@property
-def file(self):
-"""Get the file represented by this source location."""
-return self._file
-
-@property
-def line(self):
-"""Get the line represented by this source location."""
-return self._line
-
-@property
-def column(self):
-"""Get the column represented by this source location."""
-return self._column
-
-@property
-def offset(self):
-"""Get the file offset represented by this source location."""
-return self._offset
 
 class SourceLocation(Structure):
 """
 A SourceLocation represents a particular location within a source file.
 """
 _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
-_expansion = None
-_spelling = None
+_data = None
+
+def _get_instantiation(self):
+if self._data is None:
+f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
+conf.lib.clang_getInstantiationLocation(self, byref(f), byref(l),
+byref(c), byref(o))
+if f:
+f = File(f)
+else:
+f = None
+self._data = (f, int(l.value), int(c.value), int(o.value))
+return self._data
 
 @staticmethod
 def from_position(tu, file, line, column):
@@ -273,72 +253,24 @@ class SourceLocation(Structure):
 return conf.lib.clang_getLocationForOffset(tu, file, offset)
 
 @property
-def expansion(self):
-"""
-The source location where then entity this object is referring to is
-expanded.
-"""
-if not self._expansion:
-file   = c_object_p()
-line   = c_uint()
-column = c_uint()
-offset = c_uint()
-conf.lib.clang_getExpansionLocation(self,
-byref(file),
-byref(line),
-byref(column),
-byref(offset))
-
-self._expansion = Location(file, line, column, offset)
-return self._expansion
-
-@property
-def spelling(self):
-"""
-The source location where then entity this object is referring to is
-written.
-"""
-if not self._spelling:
-file   = c_object_p()
-line   = c_uint()
-column = c_uint()
-offset = c_uint()
-conf.lib.clang_getSpellingLocation(self,
-   byref(file),
-   byref(line),
-   byref(column),
-   byref(offset))
-
-self._spelling = Location(file, line, column, offset)
-return self._spelling
-
-@property
 def file(self):
-"""Get the file represented by this source location.
-
-DEPRECATED: use expansion.file."""
-return self.expansion.file
+"""Get the file represented by this source location."""
+return self._get_instantiation()[0]
 
 @property
 def line(self):
-"""Get the line represented by this source location.
-
-DEPRECATED: use expansion.line."""
-return self.expansion.line
+"""Get the line represented by this source location."""
+return self._get_instantiation()[1]
 
 @property
 def column(self):
-"""Get the colu

Re: r316278 - [libclang, bindings]: add spelling location

2017-10-21 Thread Aaron Ballman via cfe-commits
I've reverted back to green in r316279 due to more bots failing.

~Aaron

On Sat, Oct 21, 2017 at 5:35 PM, Aaron Ballman  wrote:
> This commit appears to have broken several bots. Can you revert or
> quickly fix the issue?
>
> http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/11896
> http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/12380
>
> Thanks!
>
> ~Aaron
>
> On Sat, Oct 21, 2017 at 4:53 PM, Masud Rahman via cfe-commits
>  wrote:
>> Author: frutiger
>> Date: Sat Oct 21 13:53:49 2017
>> New Revision: 316278
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=316278&view=rev
>> Log:
>> [libclang, bindings]: add spelling location
>>
>>  o) Add a 'Location' class that represents the four properties of a
>> physical location
>>
>>  o) Enhance 'SourceLocation' to provide 'expansion' and 'spelling'
>> locations, maintaining backwards compatibility with existing code by
>> forwarding the four properties to 'expansion'.
>>
>>  o) Update the implementation to use 'clang_getExpansionLocation'
>> instead of the deprecated 'clang_getInstantiationLocation', which
>> has been present since 2011.
>>
>>  o) Update the implementation of 'clang_getSpellingLocation' to actually
>> obtain spelling location instead of file location.
>>
>> Modified:
>> cfe/trunk/bindings/python/clang/cindex.py
>> cfe/trunk/bindings/python/tests/cindex/test_location.py
>> cfe/trunk/tools/libclang/CXSourceLocation.cpp
>>
>> Modified: cfe/trunk/bindings/python/clang/cindex.py
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=316278&r1=316277&r2=316278&view=diff
>> ==
>> --- cfe/trunk/bindings/python/clang/cindex.py (original)
>> +++ cfe/trunk/bindings/python/clang/cindex.py Sat Oct 21 13:53:49 2017
>> @@ -214,25 +214,45 @@ class _CXString(Structure):
>>  assert isinstance(res, _CXString)
>>  return conf.lib.clang_getCString(res)
>>
>> +class Location(object):
>> +"""A Location is a specific kind of source location.  A SourceLocation
>> +refers to several kinds of locations (e.g.  spelling location vs. 
>> expansion
>> +location)."""
>> +
>> +def __init__(self, file, line, column, offset):
>> +self._file   = File(file) if file else None
>> +self._line   = int(line.value)
>> +self._column = int(column.value)
>> +self._offset = int(offset.value)
>> +
>> +
>> +@property
>> +def file(self):
>> +"""Get the file represented by this source location."""
>> +return self._file
>> +
>> +@property
>> +def line(self):
>> +"""Get the line represented by this source location."""
>> +return self._line
>> +
>> +@property
>> +def column(self):
>> +"""Get the column represented by this source location."""
>> +return self._column
>> +
>> +@property
>> +def offset(self):
>> +"""Get the file offset represented by this source location."""
>> +return self._offset
>>
>>  class SourceLocation(Structure):
>>  """
>>  A SourceLocation represents a particular location within a source file.
>>  """
>>  _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
>> -_data = None
>> -
>> -def _get_instantiation(self):
>> -if self._data is None:
>> -f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
>> -conf.lib.clang_getInstantiationLocation(self, byref(f), 
>> byref(l),
>> -byref(c), byref(o))
>> -if f:
>> -f = File(f)
>> -else:
>> -f = None
>> -self._data = (f, int(l.value), int(c.value), int(o.value))
>> -return self._data
>> +_expansion = None
>> +_spelling = None
>>
>>  @staticmethod
>>  def from_position(tu, file, line, column):
>> @@ -253,24 +273,72 @@ class SourceLocation(Structure):
>>  return conf.lib.clang_getLocationForOffset(tu, file, offset)
>>
>>  @property
>> +def expansion(self):
>> +"""
>> +The source location where then entity this object is referring to is
>> +expanded.
>> +"""
>> +if not self._expansion:
>> +file   = c_object_p()
>> +line   = c_uint()
>> +column = c_uint()
>> +offset = c_uint()
>> +conf.lib.clang_getExpansionLocation(self,
>> +byref(file),
>> +byref(line),
>> +byref(column),
>> +byref(offset))
>> +
>> +self._expansion = Location(file, line, column, offset)
>> +return self._expansion
>> +
>> +@property
>> +def spelling(self):
>> +"""
>> +The source location where then entity this object is ref

Re: Attribute spelling policy

2017-10-23 Thread Aaron Ballman via cfe-commits
On Mon, Oct 23, 2017 at 9:48 AM, Hal Finkel  wrote:
>
> On 10/21/2017 10:14 AM, Aaron Ballman via cfe-commits wrote:
>>
>> Attributes come with multiple spelling flavors, but when it comes to
>> adding new attributes that are not present in other compiler tools
>> such as GCC or MSVC, we have done a poor job of being consistent with
>> which spelling flavors we adopt the attributes under. Some of our
>> attributes are specified with only an __attribute__ spelling (about
>> 100), while others are specified with both __attribute__ and
>> [[clang::XXX]] (about 30), and still others are specified as only
>> [[clang::XXX]] attributes (only 1). This puts additional burden on
>> developers to remember which attributes are spelled with what syntax
>> and the various rules surrounding how to write attributes with that
>> spelling.
>>
>> I am proposing that we take a more principled approach when adding new
>> attributes so that we provide a better user experience. Specifically,
>> when adding an attribute that other vendors do not support, the
>> attribute should be given an __attribute__ and [[clang::]] spelling
>> unless there's good reason not to. This is not a novel proposal -- GCC
>> supports all of their documented __attribute__ spellings under a
>> [[gnu::XXX]] spelling, and I am proposing we do the same with our
>> vendor namespace.
>
>
> For attributes that both Clang and GCC support, where GCC provides a
> [[gnu::X]] syntax, do you propose that our policy will be to support the
> same?

Yes; we should use the [[gnu::X]] spelling instead of adding the same
attribute under [[clang::X]] unless we think our semantics need to
significantly differ from GCC's.

>> Assuming this approach is reasonable to the community,
>>   I will add a
>> CLANG spelling that behaves similar to the GCC spelling in that it
>> automatically provides both the GNU and CXX11 spellings as
>> appropriate. There are some attributes for which a [[clang::XXX]]
>> spelling is not appropriate:
>>* attributes that appertain to function declarations but require
>> accessing the function parameters, such as disable_if or
>> requires_capability
>
>
> Is this restriction related to the change that p0542 proposes to make to the
> interpretation of attributes that appear after functions as part of the
> contracts proposal?

Of sorts. P0542 describes the same problem we're running into with
disable_if and others, but its solution is highly concerning because
it removes the ability to specify any attributes on the function type
and it introduces an irregularity in the way attributes are specified.
I really don't like the direction taken in P0542, but I agree with the
problem and think it needs to be solved.

~Aaron

>
> Thanks again,
> Hal
>
>>* attributes with GNU spellings whose use is discouraged or
>> deprecated, such as no_sanitize_memory
>>* attributes that are part of other vendor specifications, like CUDA or
>> OpenCL
>> These deviations are reasonable, but should be documented in Attr.td
>> near the Spelling definition for the attribute so that it's explicitly
>> understood why the spelling differs.
>>
>> Additionally, I intend for the proposed CLANG spelling to be extended
>> in the future to more easily expose [[clang::XXX]] spellings for
>> attributes intended to be used in C (with
>> -fdouble-square-bracket-attributes) as well as C++.
>>
>> As always, feedback is welcome!
>>
>> ~Aaron
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
> --
> Hal Finkel
> Lead, Compiler Technology and Programming Languages
> Leadership Computing Facility
> Argonne National Laboratory
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Attribute spelling policy

2017-10-23 Thread Aaron Ballman via cfe-commits
On Mon, Oct 23, 2017 at 11:16 AM, Arthur O'Dwyer
 wrote:
> On Mon, Oct 23, 2017 at 7:33 AM, Aaron Ballman via cfe-commits
>  wrote:
>>
>> On Mon, Oct 23, 2017 at 9:48 AM, Hal Finkel  wrote:
>> > On 10/21/2017 10:14 AM, Aaron Ballman via cfe-commits wrote:
>> >>
>> >> Attributes come with multiple spelling flavors, but when it comes to
>> >> adding new attributes that are not present in other compiler tools
>> >> such as GCC or MSVC, we have done a poor job of being consistent with
>> >> which spelling flavors we adopt the attributes under. Some of our
>> >> attributes are specified with only an __attribute__ spelling (about
>> >> 100), while others are specified with both __attribute__ and
>> >> [[clang::XXX]] (about 30), and still others are specified as only
>> >> [[clang::XXX]] attributes (only 1). This puts additional burden on
>> >> developers to remember which attributes are spelled with what syntax
>> >> and the various rules surrounding how to write attributes with that
>> >> spelling.
>> >>
>> >> I am proposing that we take a more principled approach when adding new
>> >> attributes so that we provide a better user experience. Specifically,
>> >> when adding an attribute that other vendors do not support, the
>> >> attribute should be given an __attribute__ and [[clang::]] spelling
>> >> unless there's good reason not to. This is not a novel proposal -- GCC
>> >> supports all of their documented __attribute__ spellings under a
>> >> [[gnu::XXX]] spelling, and I am proposing we do the same with our
>> >> vendor namespace.
>> >
>> > For attributes that both Clang and GCC support, where GCC provides a
>> > [[gnu::X]] syntax, do you propose that our policy will be to support the
>> > same?
>>
>> Yes; we should use the [[gnu::X]] spelling instead of adding the same
>> attribute under [[clang::X]] unless we think our semantics need to
>> significantly differ from GCC's.
>
>
> This seems like a departure from what you wrote originally, unless you just
> misspoke or I misinterpreted.
> You originally said, "[New attributes] should be given an __attribute__ and
> [[clang::]] spelling unless there's good reason not to."  I would 100% agree
> with that policy, from a user's point of view. It would be awesome to know
> exactly how an attribute is spelled without having to look it up in the
> manual.

Agreed.

> But when you used the word "instead" just now, you implied that the policy
> would be more like "New attributes should be given an __attribute__ and
> [[clang::]] spelling unless there's good reason not to, or unless Clang is
> copying work originally done by the GNU project, in which case the new
> attribute should be given __attribute__ and [[gnu::]] spellings but not a
> [[clang::]] spelling." Is that really what you meant, or was your original
> statement closer to what you meant?

That is really what I meant, but to be extra-double-clear:

* If we're adding a new attribute that has never existed under a
previous [[vendor::attr]] spelling, it should be __attribute__ and
[[clang::attr]].
* If we're adding a new-to-clang attribute that has existed under a
previous [[vendor::attr]] spelling:
  * if we intend for the attribute semantics to match the other
vendor, it should be [[vendor::attr]].
  * if we intend for the attribute semantics to differ from the other
vendor, it should be [[clang::attr]].
  * whether it's also __attribute__ may depend on the attribute being
added; for instance, we may or may not want to add an __attribute__
spelling for a [[gsl::attr]].

> As a user, I would strongly prefer to write all my attributes in a
> consistent way. If that way has to be __attribute__((foo)), then okay. But
> in C++11-and-later, it would be nice to write all my attributes as
> [[clang::foo]], and not have to keep consulting the manual to find out which
> of [[foo]], [[clang::foo]], and [[gnu::foo]] is the proper spelling for this
> particular attribute.

You will always have to figure out whether it's [[foo]] or
[[vendor::foo]] because [[foo]] is provided by the standard. However,
the point still stands of it being difficult to remember [[gnu::foo]]
vs [[clang::foo]]. However, I think that's a momentary bit of
confusion compared to the confusion of "where do I write this
attribute so that it works" that you get with __attribute__.

> Of course the worst possible outcome would be where [[clang::foo]] and
> [[gnu::foo]] both exist and have different semantics. I hope that doesn't
> happen!  Bu

Re: [PATCH] D49885: Thread safety analysis: Allow relockable scopes

2018-08-23 Thread Aaron Ballman via cfe-commits
On Wed, Aug 22, 2018 at 6:35 PM, Aaron Puchert via Phabricator
 wrote:
> aaronpuchert added inline comments.
>
>
> 
> Comment at: lib/Analysis/ThreadSafety.cpp:932
> +  // We're relocking the underlying mutexes. Warn on double locking.
> +  if (FSet.findLock(FactMan, UnderCp))
> +Handler.handleDoubleLock(DiagKind, UnderCp.toString(), entry.loc());
> 
> delesley wrote:
>> Minor nit.  Use curly braces on the if, to match the else.
> Removing the braces [was 
> suggested](https://reviews.llvm.org/D49885?id=157599#inline-439256) by 
> @aaron.ballman in an earlier patch set, but I can just add them in again. I 
> slightly favor having them, but I don't feel strongly either way.

My own opinions aren't strong here either, but I'm fine adding them
back in. We don't have clear guidance on what to do with braces for
if/else where one has braces and the other doesn't require them, but
I'm now starting to favor leaving the braces in rather than removing
them.

~Aaron

>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D49885
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r340636 - Thread safety analysis no longer hands when analyzing a self-referencing initializer.

2018-08-24 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Aug 24 11:48:35 2018
New Revision: 340636

URL: http://llvm.org/viewvc/llvm-project?rev=340636&view=rev
Log:
Thread safety analysis no longer hands when analyzing a self-referencing 
initializer.

This fixes PR38640.

Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=340636&r1=340635&r2=340636&view=diff
==
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Fri Aug 24 11:48:35 2018
@@ -1656,6 +1656,9 @@ void BuildLockset::checkAccess(const Exp
 const auto *VD = dyn_cast(DRE->getDecl()->getCanonicalDecl());
 if (VD && VD->isLocalVarDecl() && VD->getType()->isReferenceType()) {
   if (const auto *E = VD->getInit()) {
+// Guard against self-initialization. e.g., int &i = i;
+if (E == Exp)
+  break;
 Exp = E;
 continue;
   }

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=340636&r1=340635&r2=340636&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Fri Aug 24 11:48:35 
2018
@@ -5503,3 +5503,11 @@ namespace ReturnScopedLockable {
 return ptr->f();
   }
 }
+
+namespace PR38640 {
+void f() {
+  // Self-referencing assignment previously caused an infinite loop when thread
+  // safety analysis was enabled.
+  int &i = i; // expected-warning {{reference 'i' is not yet bound to a value 
when used within its own initialization}}
+}
+}


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


[clang-tools-extra] r340915 - Introduce the abseil-str-cat-append check.

2018-08-29 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Aug 29 04:17:31 2018
New Revision: 340915

URL: http://llvm.org/viewvc/llvm-project?rev=340915&view=rev
Log:
Introduce the abseil-str-cat-append check.

This flags uses of absl::StrCat when absl::StrAppend should be used instead. 
Patch by Hugo Gonzalez and Benjamin Kramer.

Added:
clang-tools-extra/trunk/clang-tidy/abseil/StrCatAppendCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/StrCatAppendCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-str-cat-append.rst
clang-tools-extra/trunk/test/clang-tidy/abseil-str-cat-append.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=340915&r1=340914&r2=340915&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Wed Aug 29 
04:17:31 2018
@@ -14,6 +14,7 @@
 #include "FasterStrsplitDelimiterCheck.h"
 #include "NoNamespaceCheck.h"
 #include "StringFindStartswithCheck.h"
+#include "StrCatAppendCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -29,6 +30,8 @@ public:
 CheckFactories.registerCheck("abseil-no-namespace");
 CheckFactories.registerCheck(
 "abseil-string-find-startswith");
+CheckFactories.registerCheck(
+"abseil-str-cat-append");
   }
 };
 

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=340915&r1=340914&r2=340915&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Wed Aug 29 
04:17:31 2018
@@ -6,6 +6,7 @@ add_clang_library(clangTidyAbseilModule
   FasterStrsplitDelimiterCheck.cpp
   NoNamespaceCheck.cpp
   StringFindStartswithCheck.cpp
+  StrCatAppendCheck.cpp
 
   LINK_LIBS
   clangAST

Added: clang-tools-extra/trunk/clang-tidy/abseil/StrCatAppendCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/StrCatAppendCheck.cpp?rev=340915&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/StrCatAppendCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/StrCatAppendCheck.cpp Wed Aug 29 
04:17:31 2018
@@ -0,0 +1,102 @@
+//===--- StrCatAppendCheck.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 "StrCatAppendCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace abseil {
+
+namespace {
+// Skips any combination of temporary materialization, temporary binding and
+// implicit casting.
+AST_MATCHER_P(Stmt, IgnoringTemporaries, ast_matchers::internal::Matcher,
+  InnerMatcher) {
+  const Stmt *E = &Node;
+  while (true) {
+if (const auto *MTE = dyn_cast(E))
+  E = MTE->getTemporary();
+if (const auto *BTE = dyn_cast(E))
+  E = BTE->getSubExpr();
+if (const auto *ICE = dyn_cast(E))
+  E = ICE->getSubExpr();
+else
+  break;
+  }
+
+  return InnerMatcher.matches(*E, Finder, Builder);
+}
+
+}  // namespace
+
+// TODO: str += StrCat(...)
+//   str.append(StrCat(...))
+
+void StrCatAppendCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+   return;
+  const auto StrCat = functionDecl(hasName("::absl::StrCat"));
+  // The arguments of absl::StrCat are implicitly converted to AlphaNum. This 
+  // matches to the arguments because of that behavior. 
+  const auto AlphaNum = IgnoringTemporaries(cxxConstructExpr(
+  argumentCountIs(1), hasType(cxxRecordDecl(hasName("::absl::AlphaNum"))),
+  hasArgument(0, ignoringImpCasts(declRefExpr(to(equalsBoundNode("LHS")),
+  expr().bind("Arg0"));
+
+  const auto HasAnotherReferenceToLhs =
+  callExpr(hasAnyArgument(expr(hasDescendant(declRefExpr(
+  to(equalsBoundNode("LHS")), unless(equalsBoundNode("Arg0")));
+
+  // Now look for calls to operator= with an object on the LHS and a call to
+  // StrCat on the RHS. The first

[clang-tools-extra] r340918 - Introduce the abseil-redundant-strcat-calls check.

2018-08-29 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Aug 29 04:29:07 2018
New Revision: 340918

URL: http://llvm.org/viewvc/llvm-project?rev=340918&view=rev
Log:
Introduce the abseil-redundant-strcat-calls check.

This flags redundant calls to absl::StrCat where the result is being passed to 
another call to absl::StrCat or absl::StrAppend. Patch by Hugo Gonzalez and 
Samuel Benzaquen.

Added:
clang-tools-extra/trunk/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/RedundantStrcatCallsCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/abseil-redundant-strcat-calls.rst
clang-tools-extra/trunk/test/clang-tidy/abseil-redundant-strcat-calls.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp?rev=340918&r1=340917&r2=340918&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/AbseilTidyModule.cpp Wed Aug 29 
04:29:07 2018
@@ -13,6 +13,7 @@
 #include "DurationDivisionCheck.h"
 #include "FasterStrsplitDelimiterCheck.h"
 #include "NoNamespaceCheck.h"
+#include "RedundantStrcatCallsCheck.h"
 #include "StringFindStartswithCheck.h"
 #include "StrCatAppendCheck.h"
 
@@ -28,6 +29,8 @@ public:
 CheckFactories.registerCheck(
 "abseil-faster-strsplit-delimiter");
 CheckFactories.registerCheck("abseil-no-namespace");
+CheckFactories.registerCheck(
+"abseil-redundant-strcat-calls");
 CheckFactories.registerCheck(
 "abseil-string-find-startswith");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt?rev=340918&r1=340917&r2=340918&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/CMakeLists.txt Wed Aug 29 
04:29:07 2018
@@ -5,6 +5,7 @@ add_clang_library(clangTidyAbseilModule
   DurationDivisionCheck.cpp
   FasterStrsplitDelimiterCheck.cpp
   NoNamespaceCheck.cpp
+  RedundantStrcatCallsCheck.cpp
   StringFindStartswithCheck.cpp
   StrCatAppendCheck.cpp
 

Added: clang-tools-extra/trunk/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp?rev=340918&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/abseil/RedundantStrcatCallsCheck.cpp Wed 
Aug 29 04:29:07 2018
@@ -0,0 +1,140 @@
+//===--- RedundantStrcatCallsCheck.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 "RedundantStrcatCallsCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace abseil {
+
+// TODO: Features to add to the check:
+//  - Make it work if num_args > 26.
+//  - Remove empty literal string arguments.
+//  - Collapse consecutive literal string arguments into one (remove the ,).
+//  - Replace StrCat(a + b)  ->  StrCat(a, b)  if a or b are strings.
+//  - Make it work in macros if the outer and inner StrCats are both in the
+//argument.
+
+void RedundantStrcatCallsCheck::registerMatchers(MatchFinder* Finder) {
+  if (!getLangOpts().CPlusPlus) 
+   return;
+  const auto CallToStrcat =
+  callExpr(callee(functionDecl(hasName("::absl::StrCat";
+  const auto CallToStrappend =
+  callExpr(callee(functionDecl(hasName("::absl::StrAppend";
+  // Do not match StrCat() calls that are descendants of other StrCat calls.
+  // Those are handled on the ancestor call.
+  const auto CallToEither = callExpr(
+  callee(functionDecl(hasAnyName("::absl::StrCat", "::absl::StrAppend";
+  Finder->addMatcher(
+  callExpr(CallToStrcat, unless(hasAncestor(CallToEither))).bind("StrCat"),
+  this);
+  Finder->addMatcher(CallToStrappend.bind("StrAppend"), this);
+}
+
+namespace {
+
+struct StrCatCheckResult {
+  int NumCalls = 0;
+  std::vector Hints;
+};
+
+void RemoveCallLeaveArgs

Re: r341009 - Adjust Attr representation so that changes to documentation don't affect

2018-08-30 Thread Aaron Ballman via cfe-commits
On Wed, Aug 29, 2018 at 9:01 PM, Richard Smith via cfe-commits
 wrote:
> Author: rsmith
> Date: Wed Aug 29 18:01:07 2018
> New Revision: 341009
>
> URL: http://llvm.org/viewvc/llvm-project?rev=341009&view=rev
> Log:
> Adjust Attr representation so that changes to documentation don't affect
> how we parse source code.
>
> Instead of implicitly opting all undocumented attributes out of '#pragma
> clang attribute' support, explicitly opt them all out and remove the
> documentation check from TableGen.
>
> (No new attributes should be added without documentation, so this has
> little chance of backsliding. We already support the pragma on one
> undocumented attribute, so we don't even want to enforce our old
> "rule".)
>
> No functionality change intended.

Thank you for this, Richard. I think this is a good change.

~Aaron

>
> Modified:
> cfe/trunk/include/clang/Basic/Attr.td
> cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=341009&r1=341008&r2=341009&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Wed Aug 29 18:01:07 2018
> @@ -473,13 +473,12 @@ class Attr {
>// in a class template definition.
>bit MeaningfulToClassTemplateDefinition = 0;
>// Set to true if this attribute can be used with '#pragma clang 
> attribute'.
> -  // By default, when this value is false, an attribute is supported by the
> -  // '#pragma clang attribute' only when:
> -  // - It has documentation.
> +  // By default, an attribute is supported by the '#pragma clang attribute'
> +  // only when:
>// - It has a subject list whose subjects can be represented using subject
>//   match rules.
>// - It has GNU/CXX11 spelling and doesn't require delayed parsing.
> -  bit ForcePragmaAttributeSupport = 0;
> +  bit PragmaAttributeSupport;
>// Lists language options, one of which is required to be true for the
>// attribute to be applicable. If empty, no language options are required.
>list LangOpts = [];
> @@ -546,6 +545,7 @@ class IgnoredAttr : Attr {
>let ASTNode = 0;
>let SemaHandler = 0;
>let Documentation = [Undocumented];
> +  let PragmaAttributeSupport = 0;
>  }
>
>  //
> @@ -564,6 +564,7 @@ def AddressSpace : TypeAttr {
>let Spellings = [Clang<"address_space">];
>let Args = [IntArgument<"AddressSpace">];
>let Documentation = [Undocumented];
> +  let PragmaAttributeSupport = 0;
>  }
>
>  def Alias : Attr {
> @@ -571,6 +572,7 @@ def Alias : Attr {
>let Args = [StringArgument<"Aliasee">];
>let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag>;
>let Documentation = [Undocumented];
> +  let PragmaAttributeSupport = 0;
>  }
>
>  def Aligned : InheritableAttr {
> @@ -583,6 +585,7 @@ def Aligned : InheritableAttr {
>Keyword<"_Alignas">]>,
> Accessor<"isDeclspec",[Declspec<"align">]>];
>let Documentation = [Undocumented];
> +  let PragmaAttributeSupport = 0;
>  }
>
>  def AlignValue : Attr {
> @@ -610,12 +613,14 @@ def AlignMac68k : InheritableAttr {
>let Spellings = [];
>let SemaHandler = 0;
>let Documentation = [Undocumented];
> +  let PragmaAttributeSupport = 0;
>  }
>
>  def AlwaysInline : InheritableAttr {
>let Spellings = [GCC<"always_inline">, Keyword<"__forceinline">];
>let Subjects = SubjectList<[Function]>;
>let Documentation = [Undocumented];
> +  let PragmaAttributeSupport = 0;
>  }
>
>  def Artificial : InheritableAttr {
> @@ -661,6 +666,7 @@ def AnalyzerNoReturn : InheritableAttr {
>// analyzer?
>let Spellings = [GNU<"analyzer_noreturn">];
>let Documentation = [Undocumented];
> +  let PragmaAttributeSupport = 0;
>  }
>
>  def Annotate : InheritableParamAttr {
> @@ -668,7 +674,7 @@ def Annotate : InheritableParamAttr {
>let Args = [StringArgument<"Annotation">];
>// Ensure that the annotate attribute can be used with
>// '#pragma clang attribute' even though it has no subject list.
> -  let ForcePragmaAttributeSupport = 1;
> +  let PragmaAttributeSupport = 1;
>let Documentation = [Undocumented];
>  }
>
> @@ -703,6 +709,7 @@ def AsmLabel : InheritableAttr {
>let Args = [StringArgument<"Label">];
>let SemaHandler = 0;
>let Documentation = [Undocumented];
> +  let PragmaAttributeSupport = 0;
>  }
>
>  def Availability : InheritableAttr {
> @@ -769,6 +776,7 @@ def Blocks : InheritableAttr {
>let Spellings = [Clang<"blocks">];
>let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
>let Documentation = [Undocumented];
> +  let PragmaAttributeSupport = 0;
>  }
>
>  def Bounded : IgnoredAttr {
> @@ -787,6 +795,7 @@ def CDecl : DeclOrTypeAttr {
>let Spellings = [GCC<"cdecl">, Keyword<"__cdecl">, Keyword<"_cdecl">];
>  //

Re: [PATCH] D30009: Add support for '#pragma clang attribute'

2018-08-30 Thread Aaron Ballman via cfe-commits
On Wed, Aug 29, 2018 at 8:41 PM, Richard Smith - zygoloid via
Phabricator  wrote:
> rsmith added a comment.
> Herald added a subscriber: llvm-commits.
>
> One consequence of this patch (see https://reviews.llvm.org/rL341002) is that 
> adding documentation to an existing attribute //changes the behavior of 
> Clang//. That does not seem acceptable to me: documentation improvements 
> should not change which attributes we allow this pragma to appertain to.
>
> If we really want an "only documented attribtues can use this feature" rule 
> (and I'm really not convinced that is a useful rule to enforce), I think the 
> best way to do that is to add another flag on the Attr instance in the .td 
> file to opt the attribute out of `#pragma clang` support, opt out all the 
> undocumented attributes, and add an error to TableGen if we find that an 
> undocumented attribute has `#pragma clang` support enabled.

I think this is a reasonable approach, but I'm also not as convinced
we need the attributes to be documented in order to use this pragma
any more. The thought process behind why it was implemented this way
(from memory, so forgive me if I'm fuzzy) was because a blanket
application of an attribute through a pragma makes for hard to
maintain code when the attributes are undocumented because the user
has no way of knowing what will actually receive that attribute. They
also don't know which attributes are unsupported in this form (like
late parsed attributes, or ones with only a __declspec spelling, etc),
but that seems like less of a concern as we err if the attribute is
not supported.

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


Re: [PATCH] D51473: Improve attribute documentation to list which spellings are used in which syntaxes.

2018-08-30 Thread Aaron Ballman via cfe-commits
On Thu, Aug 30, 2018 at 3:21 PM, Richard Smith - zygoloid via
Phabricator  wrote:
> rsmith marked an inline comment as done.
> rsmith added inline comments.
>
>
> 
> Comment at: utils/TableGen/ClangAttrEmitter.cpp:3881
> +SpellingKind K = (SpellingKind)Kind;
> +// FIXME: Why are Microsoft spellings not listed?
> +if (K == SpellingKind::Microsoft)
> 
> aaron.ballman wrote:
>> We don't actually support Microsoft's attribute spellings currently and have 
>> no attributes there to document. I think the fixme should probably read 
>> "TODO: support documenting Microsoft spellings" or something more concrete.
> Done. (I accidentally pushed the old version, so this is done in r341100.)
>
> For what it's worth, we have one `Microsoft` spelling listed in the .td file 
> already (but I assume this has no effect):
>
> ```
> def Uuid : InheritableAttr {
>   let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
> ```

Hmm, I take it back, we do support a Microsoft attribute, only to warn
about it being deprecated and telling users to use __declspec instead:
https://godbolt.org/z/_0ZxWq

I remember when we tried to add more support for parsing Microsoft
attributes, but I had the impression we didn't support them beyond the
very basics of parsing. Perhaps we do want to document them though,
since there's at least one?

~Aaron

>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D51473
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D51473: Improve attribute documentation to list which spellings are used in which syntaxes.

2018-08-31 Thread Aaron Ballman via cfe-commits
On Thu, Aug 30, 2018 at 4:12 PM, Richard Smith  wrote:
> On Thu, 30 Aug 2018 at 12:27, Aaron Ballman via cfe-commits
>  wrote:
>>
>> On Thu, Aug 30, 2018 at 3:21 PM, Richard Smith - zygoloid via
>> Phabricator  wrote:
>> > rsmith marked an inline comment as done.
>> > rsmith added inline comments.
>> >
>> >
>> > 
>> > Comment at: utils/TableGen/ClangAttrEmitter.cpp:3881
>> > +SpellingKind K = (SpellingKind)Kind;
>> > +// FIXME: Why are Microsoft spellings not listed?
>> > +if (K == SpellingKind::Microsoft)
>> > 
>> > aaron.ballman wrote:
>> >> We don't actually support Microsoft's attribute spellings currently and
>> >> have no attributes there to document. I think the fixme should probably 
>> >> read
>> >> "TODO: support documenting Microsoft spellings" or something more 
>> >> concrete.
>> > Done. (I accidentally pushed the old version, so this is done in
>> > r341100.)
>> >
>> > For what it's worth, we have one `Microsoft` spelling listed in the .td
>> > file already (but I assume this has no effect):
>> >
>> > ```
>> > def Uuid : InheritableAttr {
>> >   let Spellings = [Declspec<"uuid">, Microsoft<"uuid">];
>> > ```
>>
>> Hmm, I take it back, we do support a Microsoft attribute, only to warn
>> about it being deprecated and telling users to use __declspec instead:
>> https://godbolt.org/z/_0ZxWq
>>
>> I remember when we tried to add more support for parsing Microsoft
>> attributes, but I had the impression we didn't support them beyond the
>> very basics of parsing. Perhaps we do want to document them though,
>> since there's at least one?
>
>
> Given that doing so will make the "supported syntaxes" table wider for all
> attributes, and it's already about as wide as seems reasonable, and we
> consider all attributes of this form to be deprecated, I don't think it's
> worth it. Maybe if we only included non-empty columns in the syntax table?

I think for right now I'd prefer to keep a consistent syntax table
layout. It makes it easier to visually scan for information when all
the columns roughly line up vertically, and we only support this one
spelling just to tell users not to use it anyway. We can try out the
column approach later if we find need.

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


Re: [PATCH] D51507: Allow all supportable attributes to be used with #pragma clang attribute.

2018-08-31 Thread Aaron Ballman via cfe-commits
On Fri, Aug 31, 2018 at 9:23 AM, Duncan P. N. Exon Smith via
Phabricator  wrote:
> dexonsmith added inline comments.
>
>
> 
> Comment at: test/Misc/pragma-attribute-supported-attributes-list.test:50
>  // CHECK-NEXT: EnumExtensibility (SubjectMatchRule_enum)
> +// CHECK-NEXT: ExtVectorType (SubjectMatchRule_type_alias)
>  // CHECK-NEXT: ExternalSourceSymbol ((SubjectMatchRule_record, 
> SubjectMatchRule_enum, SubjectMatchRule_enum_constant, 
> SubjectMatchRule_field, SubjectMatchRule_function, 
> SubjectMatchRule_namespace, SubjectMatchRule_objc_category, 
> SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, 
> SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, 
> SubjectMatchRule_record, SubjectMatchRule_type_alias, 
> SubjectMatchRule_variable))
> 
> aaron.ballman wrote:
>> dexonsmith wrote:
>> > rsmith wrote:
>> > > I think `__attribute__((ext_vector_type))` is a good candidate to *not* 
>> > > have `#pragma clang attribute` support. A type modifier like this really 
>> > > should only be declared as part of declaring the type. Opinions?
>> > The same argument might hold for most type attributes.  I have trouble 
>> > imagining someone using this, but it's also hard to see how supporting it 
>> > would lead to bugs in user code.  It seems a bit simpler to support 
>> > everything.
>> >
>> > I don't have a strong opinion though.
>> I don't think `#pragma clang attribute` should apply to types -- types show 
>> up in far too many places and attributes on types changes the fundamental 
>> meaning of types a bit too much for my tastes. I'd prefer users annotate the 
>> type directly.
>> types show up in far too many places and attributes on types changes the 
>> fundamental meaning of types a bit too much for my tastes
>
> I don't see how region-based attributes on type aliases is really any 
> different from region-based annotations on variables.

My reasoning is because type attributes have more impact than variable
attributes and types appear more frequently. Consider using
address_space where the region includes function definitions. Should
that apply to the parameters and return types of the function as well
as the code within the function? Will that be intuitive for users?
What about using a calling convention before defining a structure --
will users expect the calling convention to apply to the member
function types? (The latter is a bit confused though since calling
conventions are declaration *and* type attributes at the same time.)

> Moreover, I'm strongly against disallowing use of this pragma on type aliases 
> in general: as a vendor, we've already shipped that support for a number of 
> attributes.  Most critically, ExternalSourceSymbol applies to type aliases, 
> and handling ExternalSourceSymbol was our primary motivation for adding this 
> feature (the alternative was to add yet-another-attribute-specific-`#pragma`).

ExternalSourceSymbol appertains to named declarations, not types, so
I'm a bit confused where the concern is there.

~Aaron

>
>
> 
> Comment at: test/Misc/pragma-attribute-supported-attributes-list.test:100
> +// CHECK-NEXT: ObjCReturnsInnerPointer (SubjectMatchRule_objc_method, 
> SubjectMatchRule_objc_property)
> +// CHECK-NEXT: ObjCRootClass (SubjectMatchRule_objc_interface)
>  // CHECK-NEXT: ObjCRuntimeName (SubjectMatchRule_objc_interface, 
> SubjectMatchRule_objc_protocol)
> 
> kristina wrote:
>> rsmith wrote:
>> > kristina wrote:
>> > > There is only one root class in a given runtime (ie. NSObject for objc4, 
>> > > or Object for older Apple runtimes, ObjFW also has a different root 
>> > > class). Having more than one makes no sense especially in the same 
>> > > lexical context as there are no use cases I can think of where you would 
>> > > have more than one active ObjC runtime within a process.
>> > Thanks. Yes, this attribute probably doesn't make very much sense to use 
>> > in conjunction with the pragma.
>> >
>> > So, do we explicitly disallow it, or do we allow it with the expectation 
>> > that it's likely that no-one will ever want to use it? (That is, do we 
>> > want to disallow cases that are not useful, or merely cases that are not 
>> > meaningful?) I don't have a strong opinion here, but I'm mildly inclined 
>> > towards allowing the pragma on any attribute where it's meaningful, as 
>> > there may be useful uses that we just didn't think of, and it costs 
>> > nothing to permit.
>> Yes in theory it could only be used on a single interface in which case it 
>> would be perfectly valid. Otherwise when used incorrectly it would issue a 
>> diagnostic. As per your inclination of allowing it for all attributes I 
>> would say leave it allowed, as it **can** be used in a correct way. 
>> Diagnostics are sufficient enough to point out when it happens to apply the 
>> attribute to more than one interface.
>>
>> So given your comment, I would say leave it as allowed.
>>

Re: r341539 - [OpenCL] Disallow negative attribute arguments

2018-09-06 Thread Aaron Ballman via cfe-commits
On Thu, Sep 6, 2018 at 7:54 AM, Andrew Savonichev via cfe-commits
 wrote:
> Author: asavonic
> Date: Thu Sep  6 04:54:09 2018
> New Revision: 341539
>
> URL: http://llvm.org/viewvc/llvm-project?rev=341539&view=rev
> Log:
> [OpenCL] Disallow negative attribute arguments
>
> Summary:
> Negative arguments in kernel attributes are silently bitcast'ed to
> unsigned, for example:
>
> __attribute__((reqd_work_group_size(1, -1, 1)))
> __kernel void k() {}
>
> is a complete equivalent of:
>
> __attribute__((reqd_work_group_size(1, 4294967294, 1)))
> __kernel void k() {}
>
> This is likely an error, so the patch forbids negative arguments in
> several OpenCL attributes. Users who really want 4294967294 can still
> use it as an unsigned representation.
>
> Reviewers: Anastasia, yaxunl, bader
>
> Reviewed By: Anastasia, yaxunl, bader
>
> Subscribers: bader, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D50259
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341539&r1=341538&r2=341539&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep  6 04:54:09 
> 2018
> @@ -2529,6 +2529,8 @@ def err_attribute_argument_type : Error<
>"constant|a string|an identifier}1">;
>  def err_attribute_argument_outof_range : Error<
>"%0 attribute requires integer constant between %1 and %2 inclusive">;
> +def err_attribute_argument_negative : Error<
> +  "negative argument is not allowed for %0 attribute">;

I don't think we need a new diagnostic here as we already have
err_attribute_requires_positive_integer.

~Aaron

>  def err_init_priority_object_attr : Error<
>"can only use 'init_priority' attribute on file-scope definitions "
>"of objects of class type">;
>
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=341539&r1=341538&r2=341539&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Sep  6 04:54:09 2018
> @@ -227,9 +227,13 @@ static SourceLocation getAttrLoc(const P
>
>  /// If Expr is a valid integer constant, get the value of the integer
>  /// expression and return success or failure. May output an error.
> +///
> +/// Negative argument is implicitly converted to unsigned, unless
> +/// \p StrictlyUnsigned is true.
>  template 
>  static bool checkUInt32Argument(Sema &S, const AttrInfo &AI, const Expr 
> *Expr,
> -uint32_t &Val, unsigned Idx = UINT_MAX) {
> +uint32_t &Val, unsigned Idx = UINT_MAX,
> +bool StrictlyUnsigned = false) {
>llvm::APSInt I(32);
>if (Expr->isTypeDependent() || Expr->isValueDependent() ||
>!Expr->isIntegerConstantExpr(I, S.Context)) {
> @@ -249,6 +253,11 @@ static bool checkUInt32Argument(Sema &S,
>  return false;
>}
>
> +  if (StrictlyUnsigned && I.isSigned() && I.isNegative()) {
> +S.Diag(getAttrLoc(AI), diag::err_attribute_argument_negative) << AI;
> +return false;
> +  }
> +
>Val = (uint32_t)I.getZExtValue();
>return true;
>  }
> @@ -2766,7 +2775,8 @@ static void handleWorkGroupSize(Sema &S,
>uint32_t WGSize[3];
>for (unsigned i = 0; i < 3; ++i) {
>  const Expr *E = AL.getArgAsExpr(i);
> -if (!checkUInt32Argument(S, AL, E, WGSize[i], i))
> +if (!checkUInt32Argument(S, AL, E, WGSize[i], i,
> + /*StrictlyUnsigned=*/true))
>return;
>  if (WGSize[i] == 0) {
>S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
>
> Modified: cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl?rev=341539&r1=341538&r2=341539&view=diff
> ==
> --- cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl (original)
> +++ cfe/trunk/test/SemaOpenCL/invalid-kernel-attrs.cl Thu Sep  6 04:54:09 2018
> @@ -37,3 +37,10 @@ kernel __attribute__((reqd_work_group_si
>  __attribute__((intel_reqd_sub_group_size(8))) void kernel14(){} // 
> expected-error {{attribute 'intel_reqd_sub_group_size' can only be applied to 
> an OpenCL kernel}}
>  kernel __attribute__((intel_reqd_sub_group_size(0))) void kernel15(){} // 
> expected-error {{'intel_reqd_sub_group_size' attribute must be greater than 
> 0}}
>  kernel __attribute__((intel_reqd_sub_group_size(8))) 
>

Re: r341539 - [OpenCL] Disallow negative attribute arguments

2018-09-06 Thread Aaron Ballman via cfe-commits
On Thu, Sep 6, 2018 at 10:00 AM, Andrew Savonichev
 wrote:
> Hi Aaron,
>
>> On Thu, Sep 6, 2018 at 7:54 AM, Andrew Savonichev via cfe-commits
>>  wrote:
>>> Author: asavonic
>>> Date: Thu Sep  6 04:54:09 2018
>>> New Revision: 341539
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=341539&view=rev
>>> Log:
>>> [OpenCL] Disallow negative attribute arguments
>>>
>>> [...]
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341539&r1=341538&r2=341539&view=diff
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep  6 
>>> 04:54:09 2018
>>> @@ -2529,6 +2529,8 @@ def err_attribute_argument_type : Error<
>>>"constant|a string|an identifier}1">;
>>>  def err_attribute_argument_outof_range : Error<
>>>"%0 attribute requires integer constant between %1 and %2 inclusive">;
>>> +def err_attribute_argument_negative : Error<
>>> +  "negative argument is not allowed for %0 attribute">;
>>
>> I don't think we need a new diagnostic here as we already have
>> err_attribute_requires_positive_integer.
>
> `err_attribute_requires_positive_integer' implies that a zero argument
> is not allowed, while `err_attribute_argument_negative' should fire only
> on a strictly negative argument.
>
> I can merge these diagnostics into one (using %select), but I'm not sure
> if it is appropriate.

That's a subtle distinction, but a good catch! I think it's fine to
change it to: "%0 attribute requires a %select{positive|non-negative}1
integral compile time constant expression" but if you think of wording
that makes the distinction less subtle, that'd be even better.

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


Re: r337470 - [Sema] Add a new warning, -Wmemset-transposed-args

2018-07-23 Thread Aaron Ballman via cfe-commits
On Sat, Jul 21, 2018 at 4:40 PM, Arthur O'Dwyer via cfe-commits
 wrote:
> In this case Clang is complaining about
>
> memset(complicated-expr, 0, 0);
>
> which means that transposing the last two arguments would not "fix"
> anything. Clang ought to not complain in this case.

+1

~Aaron

> It doesn't have anything to do with coming from a macro; it's just that both
> arguments are zero.
> (I would also expect that `memset(complicated-expr, (unsigned char)fill,
> (size_t)0)` shouldn't warn, either. But we had some disagreement that casts
> to `(unsigned char)` resp. `(size_t)` should be the right way to shut up the
> warning in the first place...)
> Basically Clang should only be suggesting a swap (and thus complaining at
> all) in the case that swapping the arguments would actually improve the
> situation.
>
> –Arthur
>
> On Sat, Jul 21, 2018 at 1:33 PM, Nico Weber via cfe-commits
>  wrote:
>>
>> This has a false positive on ffmpeg:
>>
>> ../../third_party/ffmpeg/libavcodec/options.c:273:64: error: 'size'
>> argument to memset is '0'; did you mean to transpose the last two arguments?
>> [-Werror,-Wmemset-transposed-args]
>> alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0);
>>
>> With:
>>
>> #define alloc_and_copy_or_fail(obj, size, pad) \
>> if (src->obj && size > 0) { \
>> dest->obj = av_malloc(size + pad); \
>> if (!dest->obj) \
>> goto fail; \
>> memcpy(dest->obj, src->obj, size); \
>> if (pad) \
>> memset(((uint8_t *) dest->obj) + size, 0, pad); \
>> }
>>
>>
>> (https://cs.chromium.org/chromium/src/third_party/ffmpeg/libavcodec/options.c?q=alloc_and_copy_or_fail&sq=package:chromium&g=0&l=261
>> ; https://bugs.chromium.org/p/chromium/issues/detail?id=866202)
>>
>> Maybe the warning shouldn't fire if the memset is from a macro?
>>
>> On Thu, Jul 19, 2018 at 12:51 PM Erik Pilkington via cfe-commits
>>  wrote:
>>>
>>> Author: epilk
>>> Date: Thu Jul 19 09:46:15 2018
>>> New Revision: 337470
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=337470&view=rev
>>> Log:
>>> [Sema] Add a new warning, -Wmemset-transposed-args
>>>
>>> This diagnoses calls to memset that have the second and third arguments
>>> transposed, for example:
>>>
>>>   memset(buf, sizeof(buf), 0);
>>>
>>> This is done by checking if the third argument is a literal 0, or if the
>>> second
>>> is a sizeof expression (and the third isn't). The first check is also
>>> done for
>>> calls to bzero.
>>>
>>> Differential revision: https://reviews.llvm.org/D49112
>>>
>>> Added:
>>> cfe/trunk/test/Sema/transpose-memset.c
>>> Modified:
>>> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> cfe/trunk/lib/Sema/SemaChecking.cpp
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=337470&r1=337469&r2=337470&view=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Jul 19 09:46:15
>>> 2018
>>> @@ -443,6 +443,13 @@ def : DiagGroup<"synth">;
>>>  def SizeofArrayArgument : DiagGroup<"sizeof-array-argument">;
>>>  def SizeofArrayDecay : DiagGroup<"sizeof-array-decay">;
>>>  def SizeofPointerMemaccess : DiagGroup<"sizeof-pointer-memaccess">;
>>> +def MemsetTransposedArgs : DiagGroup<"memset-transposed-args">;
>>> +def DynamicClassMemaccess : DiagGroup<"dynamic-class-memaccess">;
>>> +def NonTrivialMemaccess : DiagGroup<"nontrivial-memaccess">;
>>> +def SuspiciousBzero : DiagGroup<"suspicious-bzero">;
>>> +def SuspiciousMemaccess : DiagGroup<"suspicious-memaccess",
>>> +  [SizeofPointerMemaccess, DynamicClassMemaccess,
>>> +   NonTrivialMemaccess, MemsetTransposedArgs, SuspiciousBzero]>;
>>>  def StaticInInline : DiagGroup<"static-in-inline">;
>>>  def StaticLocalInInline : DiagGroup<"static-local-in-inline">;
>>>  def GNUStaticFloatInit : DiagGroup<"gnu-static-float-init">;
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=337470&r1=337469&r2=337470&view=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jul 19
>>> 09:46:15 2018
>>> @@ -619,14 +619,14 @@ def warn_cstruct_memaccess : Warning<
>>>"%select{destination for|source of|first operand of|second operand
>>> of}0 this "
>>>"%1 call is a pointer to record %2 that is not trivial to "
>>>"%select{primitive-default-initialize|primitive-copy}3">,
>>> -  InGroup>;
>>> +  InGroup;
>>>  def note_nontrivial_field : Note<
>>>"field is non-trivial to %select{cop

r338024 - Allow thread safety annotation lock upgrading and downgrading.

2018-07-26 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Jul 26 06:03:16 2018
New Revision: 338024

URL: http://llvm.org/viewvc/llvm-project?rev=338024&view=rev
Log:
Allow thread safety annotation lock upgrading and downgrading.

Patch thanks to Aaron Puchert!

Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=338024&r1=338023&r2=338024&view=diff
==
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Thu Jul 26 06:03:16 2018
@@ -109,9 +109,7 @@ class FactSet;
 /// along with additional information, such as where it was acquired, whether
 /// it is exclusive or shared, etc.
 ///
-/// FIXME: this analysis does not currently support either re-entrant
-/// locking or lock "upgrading" and "downgrading" between exclusive and
-/// shared.
+/// FIXME: this analysis does not currently support re-entrant locking.
 class FactEntry : public CapabilityExpr {
 private:
   /// Exclusive or shared.
@@ -1737,8 +1735,7 @@ void BuildLockset::handleCall(Expr *Exp,
 }
   }
 
-  for(Attr *Atconst : D->attrs()) {
-auto *At = const_cast(Atconst);
+  for(const Attr *At : D->attrs()) {
 switch (At->getKind()) {
   // When we encounter a lock function, we need to add the lock to our
   // lockset.
@@ -1838,6 +1835,16 @@ void BuildLockset::handleCall(Expr *Exp,
 }
   }
 
+  // Remove locks first to allow lock upgrading/downgrading.
+  // FIXME -- should only fully remove if the attribute refers to 'this'.
+  bool Dtor = isa(D);
+  for (const auto &M : ExclusiveLocksToRemove)
+Analyzer->removeLock(FSet, M, Loc, Dtor, LK_Exclusive, CapDiagKind);
+  for (const auto &M : SharedLocksToRemove)
+Analyzer->removeLock(FSet, M, Loc, Dtor, LK_Shared, CapDiagKind);
+  for (const auto &M : GenericLocksToRemove)
+Analyzer->removeLock(FSet, M, Loc, Dtor, LK_Generic, CapDiagKind);
+
   // Add locks.
   for (const auto &M : ExclusiveLocksToAdd)
 Analyzer->addLock(FSet, llvm::make_unique(
@@ -1864,16 +1871,6 @@ void BuildLockset::handleCall(Expr *Exp,
   Scp, MLoc, ExclusiveLocksToAdd, SharedLocksToAdd),
   CapDiagKind);
   }
-
-  // Remove locks.
-  // FIXME -- should only fully remove if the attribute refers to 'this'.
-  bool Dtor = isa(D);
-  for (const auto &M : ExclusiveLocksToRemove)
-Analyzer->removeLock(FSet, M, Loc, Dtor, LK_Exclusive, CapDiagKind);
-  for (const auto &M : SharedLocksToRemove)
-Analyzer->removeLock(FSet, M, Loc, Dtor, LK_Shared, CapDiagKind);
-  for (const auto &M : GenericLocksToRemove)
-Analyzer->removeLock(FSet, M, Loc, Dtor, LK_Generic, CapDiagKind);
 }
 
 /// For unary operations which read and write a variable, we need to

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=338024&r1=338023&r2=338024&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Thu Jul 26 06:03:16 
2018
@@ -22,8 +22,6 @@
 #define SHARED_LOCK_FUNCTION(...)   
__attribute__((acquire_shared_capability(__VA_ARGS__)))
 #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 
__attribute__((try_acquire_capability(__VA_ARGS__)))
 #define SHARED_TRYLOCK_FUNCTION(...)
__attribute__((try_acquire_shared_capability(__VA_ARGS__)))
-#define EXCLUSIVE_UNLOCK_FUNCTION(...)  
__attribute__((release_capability(__VA_ARGS__)))
-#define SHARED_UNLOCK_FUNCTION(...) 
__attribute__((release_shared_capability(__VA_ARGS__)))
 #define EXCLUSIVE_LOCKS_REQUIRED(...)   
__attribute__((requires_capability(__VA_ARGS__)))
 #define SHARED_LOCKS_REQUIRED(...)  
__attribute__((requires_shared_capability(__VA_ARGS__)))
 #else
@@ -34,11 +32,11 @@
 #define SHARED_LOCK_FUNCTION(...)   
__attribute__((shared_lock_function(__VA_ARGS__)))
 #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 
__attribute__((exclusive_trylock_function(__VA_ARGS__)))
 #define SHARED_TRYLOCK_FUNCTION(...)
__attribute__((shared_trylock_function(__VA_ARGS__)))
-#define EXCLUSIVE_UNLOCK_FUNCTION(...)  
__attribute__((unlock_function(__VA_ARGS__)))
-#define SHARED_UNLOCK_FUNCTION(...) 
__attribute__((unlock_function(__VA_ARGS__)))
 #define EXCLUSIVE_LOCKS_REQUIRED(...)   
__attribute__((exclusive_locks_required(__VA_ARGS__)))
 #define SHARED_LOCKS_REQUIRED(...)  
__attribute__((shared_locks_required(__VA_ARGS__)))
 #endif
+#define EXCLUSIVE_UNLOCK_FUNCTION(...)  
__attribute__((release_capability(__VA_ARGS__)))
+#define SHARED_UNLOCK_FUNCTION(...) 
__attribute__((release_shared_capability(__VA_ARGS__)))
 #define UNLOCK_FUNCTION(...)

Re: r338291 - Remove trailing space

2018-07-30 Thread Aaron Ballman via cfe-commits
On Mon, Jul 30, 2018 at 3:52 PM, Fāng-ruì Sòng  wrote:
> Oops.. sorry but now they have been committed..

The commits can still be reverted and I think they should be.

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


Re: r338291 - Remove trailing space

2018-07-30 Thread Aaron Ballman via cfe-commits
On Mon, Jul 30, 2018 at 4:24 PM, Michael Kruse
 wrote:
> I think removing trailing space is a good thing. Some editors remove
> any trailing space when saving a file. This shows up in diffs that I
> then have to undo manually.

I've also run into the same issues on occasion. However, this isn't
about whether we dislike trailing spaces or not; it's about NFC churn
for out of tree users who have to try to keep their local patches
clean against upstream. This kind of churn makes for merge conflicts
and this is a the reason the community has traditionally rejected
these large-scale commits in the past. If we want to change that
policy, it should come after community discussion and agreement.

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


Re: r338291 - Remove trailing space

2018-07-30 Thread Aaron Ballman via cfe-commits
On Mon, Jul 30, 2018 at 4:43 PM, Fāng-ruì Sòng  wrote:
> Does this apply to only public headers (include/llvm include/llvm-c
> include/clang ...) or everything? (lib/**/*.{cpp,h})?

I've understood it applies to "everything" in that you should not
commit large-scale NFC changes that don't have considerable benefit
(for some definition of considerable benefit). e.g., if you're fixing
a typo in an API and it hits a lot of files, that's fine because a
typo in an API is pretty egregious, but don't clang-format a bunch of
files and commit that because formatting isn't super critical and
instead we migrate it more slowly as the code gets touched.

On Mon, Jul 30, 2018 at 4:49 PM, Fāng-ruì Sòng  wrote:
> Maybe not too terrible for out-of-tree projects. If they use git
> mirror, `git rebase` is smart enough to ignore changing lines with
> trailing whitespace (if not, there is git rebase
> -Xignore-space-at-eol). Some editors are configured with highlighting
> trailing spaces and these spaces will turn to eyesore...

Not everyone uses git; svn is still the official repository for the project.

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


Re: r338291 - Remove trailing space

2018-07-30 Thread Aaron Ballman via cfe-commits
On Mon, Jul 30, 2018 at 5:36 PM, Michael Kruse
 wrote:
> Can you point me to such a discussion about trailing whitespace?

I don't know of one, which is why I am concerned with these commits.

> It seems to contradict the conclusion in another current thread to not
> consider churn for out-of-tree users (for C++ API in this case)
>
> https://lists.llvm.org/pipermail/cfe-dev/2018-July/058579.html

This is discussing an API refactoring, which is an entirely different
beast than removing trailing whitespace across hundreds of files. I
see trailing whitespace as being similar to other code formatting and
style issues; it isn't problematic to leave in and it can be fixed up
as the code gets touched.

~Aaron

>
>> We have historically taken the position that the churn caused for
>> out-of-tree users of the C++ API are not a consideration when performing an
>> API refactoring. (For two reasons: one is that we explicitly do not have a
>> stable C++ API; the other is that this is the mechanism by which we
>> encourage people to upstream changes.) This actually seems like a
>> relatively easy change in that regard: client code can be largely updated
>> by a regular expression.
>
>
> Michael
>
>
>
> 2018-07-30 15:36 GMT-05:00 Aaron Ballman :
>> On Mon, Jul 30, 2018 at 4:24 PM, Michael Kruse
>>  wrote:
>>> I think removing trailing space is a good thing. Some editors remove
>>> any trailing space when saving a file. This shows up in diffs that I
>>> then have to undo manually.
>>
>> I've also run into the same issues on occasion. However, this isn't
>> about whether we dislike trailing spaces or not; it's about NFC churn
>> for out of tree users who have to try to keep their local patches
>> clean against upstream. This kind of churn makes for merge conflicts
>> and this is a the reason the community has traditionally rejected
>> these large-scale commits in the past. If we want to change that
>> policy, it should come after community discussion and agreement.
>>
>> ~Aaron
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r338291 - Remove trailing space

2018-07-30 Thread Aaron Ballman via cfe-commits
On Mon, Jul 30, 2018 at 6:17 PM, Fāng-ruì Sòng  wrote:

> On 2018-07-30, Aaron Ballman wrote:
>
>> On Mon, Jul 30, 2018 at 4:43 PM, Fāng-ruì Sòng 
>> wrote:
>>
>>> Does this apply to only public headers (include/llvm include/llvm-c
>>> include/clang ...) or everything? (lib/**/*.{cpp,h})?
>>>
>>
>> I've understood it applies to "everything" in that you should not
>> commit large-scale NFC changes that don't have considerable benefit
>> (for some definition of considerable benefit).
>>
>
> The benefits I can think of are:
>
> * Some editors are configured to highlight trailing whitespace. Before
>  the two cleanup commits, they will interfere reading.
> * Some editors are configured to remove whitespace (as Michael pointed
>  out). The removal will show up in diffs where revision authors have to
> undo
>  manually. For some out-of-tree users, if they have local patches but do
> not
>  strip trailing whitespace, related to settings of their code review
> system,
>  this could turn to whitespace errors.
>
> e.g., if you're fixing
>> a typo in an API and it hits a lot of files, that's fine because a
>> typo in an API is pretty egregious, but don't clang-format a bunch of
>> files and commit that because formatting isn't super critical and
>> instead we migrate it more slowly as the code gets touched.
>>
>
> Thank you for raising these. I learned from your examples☺
>
> On Mon, Jul 30, 2018 at 4:49 PM, Fāng-ruì Sòng  wrote:
>>
>>> Maybe not too terrible for out-of-tree projects. If they use git
>>> mirror, `git rebase` is smart enough to ignore changing lines with
>>> trailing whitespace (if not, there is git rebase
>>> -Xignore-space-at-eol). Some editors are configured with highlighting
>>> trailing spaces and these spaces will turn to eyesore...
>>>
>>
>> Not everyone uses git; svn is still the official repository for the
>> project.
>>
>
> I am not familiar with svn but stackoverflow tells me there is svn diff -x
> "--ignore-eol-style".
> This should also be available to other svn functionality.
>

I don't disagree that there are pros and cons in the discussion and that we
should consider them carefully, but I think there should be a discussion
that happens with the community *before* landing this patch, even though
it's a NFC patch. Please revert these patches and start a discussion thread
on whether this is something the community would like to see committed or
not.

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


Re: [PATCH] D48100: Append new attributes to the end of an AttributeList.

2018-08-03 Thread Aaron Ballman via cfe-commits
On Fri, Aug 3, 2018 at 8:53 AM, Erich Keane via Phabricator
 wrote:
> erichkeane added a comment.
>
> In https://reviews.llvm.org/D48100#1186654, @Meinersbur wrote:
>
>> I have two approaches to tackle the wrong marker order: 
>> https://reviews.llvm.org/D50215 and https://reviews.llvm.org/D50216. IMHO 
>> both are too invasive to be justified for the small issue.
>
>
> I think you're right here.  I despise https://reviews.llvm.org/D50215, and 
> only mostly hate https://reviews.llvm.org/D50216.  I think I'd prefer leaving 
> this as a "FIXME" somewhere.

Oye, I'm in agreement that this should be fixed but that neither of
these approaches leaves me feeling warm and fuzzy.

As a possible idea (that may or may not work): the Attr object itself
has a SourceRange on it; perhaps a solution is to keep the attributes
in sorted order within DeclBase::addAttr() based on the SourceRanges
passed in?

~Aaron

>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D48100
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D48100: Append new attributes to the end of an AttributeList.

2018-08-03 Thread Aaron Ballman via cfe-commits
On Fri, Aug 3, 2018 at 10:09 AM, Keane, Erich  wrote:
>> As a possible idea (that may or may not work): the Attr object itself has a 
>> SourceRange on it; perhaps a solution is to keep the > attributes in sorted 
>> order within DeclBase::addAttr() based on the SourceRanges passed in?
>
> Interestingly, I think I came up with that idea in a comment on D50214.  I 
> think that we should either keep the attributes sorted, or make the iterator 
> give a sorted version.

Oh, hey, so you did! I think keeping them in a sorted order is
preferable to having the iterator return a sorted version; I believe
we iterate attribute more often than we add them because things like
hasAttr<>() and getAttr<>() both rely on iterating through the
attributes.

~Aaron

>
>
>
> -Original Message-
> From: Aaron Ballman [mailto:aaron.ball...@gmail.com]
> Sent: Friday, August 3, 2018 7:02 AM
> To: reviews+d48100+public+bdf72fdc7f8c9...@reviews.llvm.org
> Cc: Michael Kruse ; Hal Finkel ; Tyler 
> Nowicki ; Alexey Bataev ; John 
> McCall ; George Burgess IV ; 
> Nick Lewycky ; Nick Lewycky ; 
> d...@google.com; sammcc...@google.com; david.gr...@arm.com; llvm-commits 
> ; jrt...@jrtc27.com; Richard Smith 
> ; Keane, Erich ; Eric 
> Christopher ; zhaos...@codeaurora.org; Simon Atanasyan 
> ; cfe-commits ; 
> junb...@codeaurora.org; florian.h...@arm.com
> Subject: Re: [PATCH] D48100: Append new attributes to the end of an 
> AttributeList.
>
> On Fri, Aug 3, 2018 at 8:53 AM, Erich Keane via Phabricator 
>  wrote:
>> erichkeane added a comment.
>>
>> In https://reviews.llvm.org/D48100#1186654, @Meinersbur wrote:
>>
>>> I have two approaches to tackle the wrong marker order: 
>>> https://reviews.llvm.org/D50215 and https://reviews.llvm.org/D50216. IMHO 
>>> both are too invasive to be justified for the small issue.
>>
>>
>> I think you're right here.  I despise https://reviews.llvm.org/D50215, and 
>> only mostly hate https://reviews.llvm.org/D50216.  I think I'd prefer 
>> leaving this as a "FIXME" somewhere.
>
> Oye, I'm in agreement that this should be fixed but that neither of these 
> approaches leaves me feeling warm and fuzzy.
>
> As a possible idea (that may or may not work): the Attr object itself has a 
> SourceRange on it; perhaps a solution is to keep the attributes in sorted 
> order within DeclBase::addAttr() based on the SourceRanges passed in?
>
> ~Aaron
>
>>
>>
>> Repository:
>>   rL LLVM
>>
>> https://reviews.llvm.org/D48100
>>
>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r338912 - Properly add shared locks to the initial list of locks being tracked, instead of assuming unlock functions always use exclusive locks.

2018-08-03 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Aug  3 12:37:45 2018
New Revision: 338912

URL: http://llvm.org/viewvc/llvm-project?rev=338912&view=rev
Log:
Properly add shared locks to the initial list of locks being tracked, instead 
of assuming unlock functions always use exclusive locks.

Patch by Aaron Puchert.

Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=338912&r1=338911&r2=338912&view=diff
==
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Fri Aug  3 12:37:45 2018
@@ -2242,8 +2242,8 @@ void ThreadSafetyAnalyzer::runAnalysis(A
 // We must ignore such methods.
 if (A->args_size() == 0)
   return;
-// FIXME -- deal with exclusive vs. shared unlock functions?
-getMutexIDs(ExclusiveLocksToAdd, A, nullptr, D);
+getMutexIDs(A->isShared() ? SharedLocksToAdd : ExclusiveLocksToAdd, A,
+nullptr, D);
 getMutexIDs(LocksReleased, A, nullptr, D);
 CapDiagKind = ClassifyDiagnostic(A);
   } else if (const auto *A = dyn_cast(Attr)) {

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=338912&r1=338911&r2=338912&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Fri Aug  3 12:37:45 
2018
@@ -4078,6 +4078,14 @@ public:
 mu_.Unlock();
   }
 
+  void unlockExclusive() EXCLUSIVE_UNLOCK_FUNCTION(mu_) {
+mu_.Unlock();
+  }
+
+  void unlockShared() SHARED_UNLOCK_FUNCTION(mu_) {
+mu_.ReaderUnlock();
+  }
+
   // Check failure to lock.
   void lockBad() EXCLUSIVE_LOCK_FUNCTION(mu_) {// expected-note {{mutex 
acquired here}}
 mu2_.Lock();


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


r324890 - Allow the NS, CF, and ObjC attributes to be used with -fdouble-square-bracket-attributes. The syntactic locations for such attributes on ObjC constructs have been specifically chosen to foll

2018-02-12 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Mon Feb 12 05:38:25 2018
New Revision: 324890

URL: http://llvm.org/viewvc/llvm-project?rev=324890&view=rev
Log:
Allow the NS, CF, and ObjC attributes to be used with 
-fdouble-square-bracket-attributes. The syntactic locations for such attributes 
on ObjC constructs have been specifically chosen to follow the GNU attribute 
syntactic locations.

Added:
cfe/trunk/test/Misc/ast-dump-attr.m
cfe/trunk/test/Parser/objc-attr.m
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/Parser.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=324890&r1=324889&r2=324890&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Feb 12 05:38:25 2018
@@ -754,7 +754,7 @@ def CDecl : InheritableAttr {
 // cf_returns_retained attributes.  It is generally applied by
 // '#pragma clang arc_cf_code_audited' rather than explicitly.
 def CFAuditedTransfer : InheritableAttr {
-  let Spellings = [Clang<"cf_audited_transfer">];
+  let Spellings = [Clang<"cf_audited_transfer", 1>];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [Undocumented];
 }
@@ -763,25 +763,25 @@ def CFAuditedTransfer : InheritableAttr
 // It indicates that the function has unknown or unautomatable
 // transfer semantics.
 def CFUnknownTransfer : InheritableAttr {
-  let Spellings = [Clang<"cf_unknown_transfer">];
+  let Spellings = [Clang<"cf_unknown_transfer", 1>];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [Undocumented];
 }
 
 def CFReturnsRetained : InheritableAttr {
-  let Spellings = [Clang<"cf_returns_retained">];
+  let Spellings = [Clang<"cf_returns_retained", 1>];
 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
   let Documentation = [Undocumented];
 }
 
 def CFReturnsNotRetained : InheritableAttr {
-  let Spellings = [Clang<"cf_returns_not_retained">];
+  let Spellings = [Clang<"cf_returns_not_retained", 1>];
 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
   let Documentation = [Undocumented];
 }
 
 def CFConsumed : InheritableParamAttr {
-  let Spellings = [Clang<"cf_consumed">];
+  let Spellings = [Clang<"cf_consumed", 1>];
   let Subjects = SubjectList<[ParmVar]>;
   let Documentation = [Undocumented];
 }
@@ -1118,7 +1118,7 @@ def Hot : InheritableAttr {
 }
 
 def IBAction : InheritableAttr {
-  let Spellings = [Clang<"ibaction">];
+  let Spellings = [Clang<"ibaction", 1>];
   let Subjects = SubjectList<[ObjCInstanceMethod]>;
   // An AST node is created for this attribute, but is not used by other parts
   // of the compiler. However, this node needs to exist in the AST because
@@ -1127,13 +1127,13 @@ def IBAction : InheritableAttr {
 }
 
 def IBOutlet : InheritableAttr {
-  let Spellings = [Clang<"iboutlet">];
+  let Spellings = [Clang<"iboutlet", 1>];
 //  let Subjects = [ObjCIvar, ObjCProperty];
   let Documentation = [Undocumented];
 }
 
 def IBOutletCollection : InheritableAttr {
-  let Spellings = [Clang<"iboutletcollection">];
+  let Spellings = [Clang<"iboutletcollection", 1>];
   let Args = [TypeArgument<"Interface", 1>];
 //  let Subjects = [ObjCIvar, ObjCProperty];
   let Documentation = [Undocumented];
@@ -1428,7 +1428,7 @@ def ObjCKindOf : TypeAttr {
 }
 
 def NoEscape : Attr {
-  let Spellings = [Clang<"noescape">];
+  let Spellings = [Clang<"noescape", 1>];
   let Subjects = SubjectList<[ParmVar]>;
   let Documentation = [NoEscapeDocs];
 }
@@ -1480,14 +1480,14 @@ def NvWeak : IgnoredAttr {
 }
 
 def ObjCBridge : InheritableAttr {
-  let Spellings = [Clang<"objc_bridge">];
+  let Spellings = [Clang<"objc_bridge", 1>];
   let Subjects = SubjectList<[Record, TypedefName], ErrorDiag>;
   let Args = [IdentifierArgument<"BridgedType">];
   let Documentation = [Undocumented];
 }
 
 def ObjCBridgeMutable : InheritableAttr {
-  let Spellings = [Clang<"objc_bridge_mutable">];
+  let Spellings = [Clang<"objc_bridge_mutable", 1>];
   let Subjects = SubjectList<[Record], ErrorDiag>;
   let Args = [IdentifierArgument<"BridgedType">];
   let Documentation = [Undocumented];
@@ -1506,43 +1506,43 @@ def ObjCBridgeRelated : InheritableAttr
 }
 
 def NSReturnsRetained : InheritableAttr {
-  let Spellings = [Clang<"ns_returns_retained">];
+  let Spellings = [Clang<"ns_returns_retained", 1>];
 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
   let Documentation = [Undocumented];
 }
 
 def NSReturnsNotRetained : InheritableAttr {
-  let Spellings = [Clang<"ns_returns_not_retained">];
+  let Spellings = [Clang<"ns_returns_not_retained", 1>];
 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Function]>;
   let Documentation = [Undocumented];
 }
 
 def NSReturnsAutorele

Re: [PATCH] D43120: [clang-tidy] New checker for exceptions that are created but not thrown

2018-02-15 Thread Aaron Ballman via cfe-commits
On Thu, Feb 15, 2018 at 4:11 AM, Phabricator via Phabricator
 wrote:
> This revision was automatically updated to reflect the committed changes.
> Closed by commit rL325222: [clang-tidy] New checker for exceptions that are 
> created but not thrown (authored by xazax, committed by ).

There's nothing wrong with this patch, but it is odd that the
automated text describes the author but not the committer. I wonder if
that's a bug?

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


r325261 - Amend r325256. This change was not properly merged locally before the commit happened.

2018-02-15 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Feb 15 08:28:10 2018
New Revision: 325261

URL: http://llvm.org/viewvc/llvm-project?rev=325261&view=rev
Log:
Amend r325256. This change was not properly merged locally before the commit 
happened.

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

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=325261&r1=325260&r2=325261&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Feb 15 08:28:10 2018
@@ -6029,7 +6029,7 @@ static void ProcessDeclAttribute(Sema &S
 handleAlwaysInlineAttr(S, D, AL);
 break;
   case AttributeList::AT_Artificial:
-handleSimpleAttribute(S, D, Attr);
+handleSimpleAttribute(S, D, AL);
 break;
   case AttributeList::AT_AnalyzerNoReturn:
 handleAnalyzerNoReturnAttr(S, D, AL);


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


r325292 - Silence some -Wunused-variable warnings; NFC.

2018-02-15 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Feb 15 12:56:19 2018
New Revision: 325292

URL: http://llvm.org/viewvc/llvm-project?rev=325292&view=rev
Log:
Silence some -Wunused-variable warnings; NFC.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=325292&r1=325291&r2=325292&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Thu Feb 15 12:56:19 2018
@@ -135,7 +135,7 @@ ExprEngine::getRegionForConstructedObjec
 LValue = makeZeroElementRegion(State, LValue, Ty,
CallOpts.IsArrayCtorOrDtor);
 return LValue.getAsRegion();
-  } else if (auto *RS = dyn_cast(TriggerStmt)) {
+  } else if (isa(TriggerStmt)) {
 // TODO: We should construct into a CXXBindTemporaryExpr or a
 // MaterializeTemporaryExpr around the call-expression on the previous
 // stack frame. Currently we re-bind the temporary to the correct 
region
@@ -146,7 +146,7 @@ ExprEngine::getRegionForConstructedObjec
 // construction context that'd give us the right temporary expression.
 CallOpts.IsTemporaryCtorOrDtor = true;
 return MRMgr.getCXXTempObjectRegion(CE, LCtx);
-  } else if (auto *BTE = dyn_cast(TriggerStmt)) {
+  } else if (isa(TriggerStmt)) {
 CallOpts.IsTemporaryCtorOrDtor = true;
 return MRMgr.getCXXTempObjectRegion(CE, LCtx);
   }


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


r325293 - Silence a -Wparentheses warning; NFC.

2018-02-15 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Feb 15 13:03:39 2018
New Revision: 325293

URL: http://llvm.org/viewvc/llvm-project?rev=325293&view=rev
Log:
Silence a -Wparentheses warning; NFC.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=325293&r1=325292&r2=325293&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Thu Feb 15 13:03:39 2018
@@ -1197,7 +1197,7 @@ CallEventManager::getCaller(const StackF
   // destructors, though this could change in the future.
   const CFGBlock *B = CalleeCtx->getCallSiteBlock();
   CFGElement E = (*B)[CalleeCtx->getIndex()];
-  assert(E.getAs() || E.getAs() &&
+  assert((E.getAs() || E.getAs()) &&
  "All other CFG elements should have exprs");
 
   SValBuilder &SVB = State->getStateManager().getSValBuilder();


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


r325520 - Add several more attributes to be parsed in C with [[]] when -fdouble-square-bracket-attributes is specified.

2018-02-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Mon Feb 19 09:32:07 2018
New Revision: 325520

URL: http://llvm.org/viewvc/llvm-project?rev=325520&view=rev
Log:
Add several more attributes to be parsed in C with [[]] when 
-fdouble-square-bracket-attributes is specified.

Also flags a few attributes that should not be available with the C spelling as 
they only matter in C++.

Added:
cfe/trunk/test/Sema/attr-cx2.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=325520&r1=325519&r2=325520&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Feb 19 09:32:07 2018
@@ -534,7 +534,7 @@ def AbiTag : Attr {
 }
 
 def AddressSpace : TypeAttr {
-  let Spellings = [Clang<"address_space">];
+  let Spellings = [Clang<"address_space", 1>];
   let Args = [IntArgument<"AddressSpace">];
   let Documentation = [Undocumented];
 }
@@ -598,18 +598,18 @@ def Artificial : InheritableAttr {
 }
 
 def XRayInstrument : InheritableAttr {
-  let Spellings = [Clang<"xray_always_instrument">,
-   Clang<"xray_never_instrument">];
+  let Spellings = [Clang<"xray_always_instrument", 1>,
+   Clang<"xray_never_instrument", 1>];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Accessors = [Accessor<"alwaysXRayInstrument",
- [Clang<"xray_always_instrument">]>,
+ [Clang<"xray_always_instrument", 1>]>,
Accessor<"neverXRayInstrument",
- [Clang<"xray_never_instrument">]>];
+ [Clang<"xray_never_instrument", 1>]>];
   let Documentation = [XRayDocs];
 }
 
 def XRayLogArgs : InheritableAttr {
-  let Spellings = [Clang<"xray_log_args">];
+  let Spellings = [Clang<"xray_log_args", 1>];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Args = [UnsignedArgument<"ArgumentCount">];
   let Documentation = [XRayDocs];
@@ -735,7 +735,7 @@ def ExternalSourceSymbol : InheritableAt
 }
 
 def Blocks : InheritableAttr {
-  let Spellings = [Clang<"blocks">];
+  let Spellings = [Clang<"blocks", 1>];
   let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
   let Documentation = [Undocumented];
 }
@@ -1072,19 +1072,19 @@ def Final : InheritableAttr {
 }
 
 def MinSize : InheritableAttr {
-  let Spellings = [Clang<"minsize">];
+  let Spellings = [Clang<"minsize", 1>];
   let Subjects = SubjectList<[Function, ObjCMethod], ErrorDiag>;
   let Documentation = [Undocumented];
 }
 
 def FlagEnum : InheritableAttr {
-  let Spellings = [Clang<"flag_enum">];
+  let Spellings = [Clang<"flag_enum", 1>];
   let Subjects = SubjectList<[Enum]>;
   let Documentation = [FlagEnumDocs];
 }
 
 def EnumExtensibility : InheritableAttr {
-  let Spellings = [Clang<"enum_extensibility">];
+  let Spellings = [Clang<"enum_extensibility", 1>];
   let Subjects = SubjectList<[Enum]>;
   let Args = [EnumArgument<"Extensibility", "Kind",
   ["closed", "open"], ["Closed", "Open"]>];
@@ -1169,6 +1169,8 @@ def LayoutVersion : InheritableAttr, Tar
 }
 
 def TrivialABI : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it requires the
+  // CPlusPlus language option.
   let Spellings = [Clang<"trivial_abi">];
   let Subjects = SubjectList<[CXXRecord]>;
   let Documentation = [TrivialABIDocs];
@@ -1259,13 +1261,13 @@ def Naked : InheritableAttr {
 }
 
 def NeonPolyVectorType : TypeAttr {
-  let Spellings = [Clang<"neon_polyvector_type">];
+  let Spellings = [Clang<"neon_polyvector_type", 1>];
   let Args = [IntArgument<"NumElements">];
   let Documentation = [Undocumented];
 }
 
 def NeonVectorType : TypeAttr {
-  let Spellings = [Clang<"neon_vector_type">];
+  let Spellings = [Clang<"neon_vector_type", 1>];
   let Args = [IntArgument<"NumElements">];
   let Documentation = [Undocumented];
 }
@@ -1277,7 +1279,7 @@ def ReturnsTwice : InheritableAttr {
 }
 
 def DisableTailCalls : InheritableAttr {
-  let Spellings = [Clang<"disable_tail_calls">];
+  let Spellings = [Clang<"disable_tail_calls", 1>];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Documentation = [DisableTailCallsDocs];
 }
@@ -1301,13 +1303,13 @@ def NoDebug : InheritableAttr {
 }
 
 def NoDuplicate : InheritableAttr {
-  let Spellings = [Clang<"noduplicate">];
+  let Spellings = [Clang<"noduplicate", 1>];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NoDuplicateDocs];
 }
 
 def Convergent : InheritableAttr {
-  let Spellings = [Clang<"convergent">];
+  let Spellings = [Clang<"convergent", 1>];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [ConvergentDocs];
 }
@@ -1409,7 +1411,7 @@ def ReturnsNonNull : InheritableAttr {
 // pass_object_size(N) indicates that the parameter should have
 // __builtin_object_size with Type=N eval

Re: r325678 - [ASTMatchers] isTemplateInstantiation: also match explicit instantiation declaration.

2018-02-21 Thread Aaron Ballman via cfe-commits
On Wed, Feb 21, 2018 at 8:51 AM, Eric Liu via cfe-commits
 wrote:
> Author: ioeric
> Date: Wed Feb 21 05:51:27 2018
> New Revision: 325678
>
> URL: http://llvm.org/viewvc/llvm-project?rev=325678&view=rev
> Log:
> [ASTMatchers] isTemplateInstantiation: also match explicit instantiation 
> declaration.
>
> Summary:
> Example:
> template  class X {}; class A {};
> // Explicit instantiation declaration.
> extern template class X;
>
> Reviewers: bkramer
>
> Subscribers: klimek, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D43567
>
> Modified:
> cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Please regenerate the AST matcher documentation as well.

~Aaron

>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=325678&r1=325677&r2=325678&view=diff
> ==
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Feb 21 05:51:27 2018
> @@ -4649,6 +4649,10 @@ AST_MATCHER_P(UsingShadowDecl, hasTarget
>  /// \code
>  ///   template  class X {}; class A {}; template class X;
>  /// \endcode
> +/// or
> +/// \code
> +///   template  class X {}; class A {}; extern template class 
> X;
> +/// \endcode
>  /// cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
>  ///   matches the template instantiation of X.
>  ///
> @@ -4666,7 +4670,9 @@ AST_POLYMORPHIC_MATCHER(isTemplateInstan
>  CXXRecordDecl)) {
>return (Node.getTemplateSpecializationKind() == TSK_ImplicitInstantiation 
> ||
>Node.getTemplateSpecializationKind() ==
> -  TSK_ExplicitInstantiationDefinition);
> +  TSK_ExplicitInstantiationDefinition ||
> +  Node.getTemplateSpecializationKind() ==
> +  TSK_ExplicitInstantiationDeclaration);
>  }
>
>  /// \brief Matches declarations that are template instantiations or are 
> inside
>
> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=325678&r1=325677&r2=325678&view=diff
> ==
> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original)
> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Wed Feb 21 
> 05:51:27 2018
> @@ -1623,6 +1623,14 @@ TEST(IsTemplateInstantiation, MatchesExp
>"template class X;",
>  cxxRecordDecl(isTemplateInstantiation(), hasDescendant(
>fieldDecl(hasType(recordDecl(hasName("A";
> +
> +  // Make sure that we match the instantiation instead of the template
> +  // definition by checking whether the member function is present.
> +  EXPECT_TRUE(
> +  matches("template  class X { void f() { T t; } };"
> +  "extern template class X;",
> +  cxxRecordDecl(isTemplateInstantiation(),
> +unless(hasDescendant(varDecl(hasName("t")));
>  }
>
>  TEST(IsTemplateInstantiation,
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r325678 - [ASTMatchers] isTemplateInstantiation: also match explicit instantiation declaration.

2018-02-21 Thread Aaron Ballman via cfe-commits
On Wed, Feb 21, 2018 at 8:56 AM, Eric Liu  wrote:
> Oops, I only saw this after landing the patch. I'll send another one to
> update the doc. Sorry about that!

No worries! I didn't see the patch until after the commit anyway.
Thanks for taking care of it!

~Aaron

>
> On Wed, Feb 21, 2018 at 2:54 PM Aaron Ballman 
> wrote:
>>
>> On Wed, Feb 21, 2018 at 8:51 AM, Eric Liu via cfe-commits
>>  wrote:
>> > Author: ioeric
>> > Date: Wed Feb 21 05:51:27 2018
>> > New Revision: 325678
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=325678&view=rev
>> > Log:
>> > [ASTMatchers] isTemplateInstantiation: also match explicit instantiation
>> > declaration.
>> >
>> > Summary:
>> > Example:
>> > template  class X {}; class A {};
>> > // Explicit instantiation declaration.
>> > extern template class X;
>> >
>> > Reviewers: bkramer
>> >
>> > Subscribers: klimek, cfe-commits
>> >
>> > Differential Revision: https://reviews.llvm.org/D43567
>> >
>> > Modified:
>> > cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>> > cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
>>
>> Please regenerate the AST matcher documentation as well.
>>
>> ~Aaron
>>
>> >
>> > Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=325678&r1=325677&r2=325678&view=diff
>> >
>> > ==
>> > --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
>> > +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Feb 21
>> > 05:51:27 2018
>> > @@ -4649,6 +4649,10 @@ AST_MATCHER_P(UsingShadowDecl, hasTarget
>> >  /// \code
>> >  ///   template  class X {}; class A {}; template class
>> > X;
>> >  /// \endcode
>> > +/// or
>> > +/// \code
>> > +///   template  class X {}; class A {}; extern template
>> > class X;
>> > +/// \endcode
>> >  /// cxxRecordDecl(hasName("::X"), isTemplateInstantiation())
>> >  ///   matches the template instantiation of X.
>> >  ///
>> > @@ -4666,7 +4670,9 @@ AST_POLYMORPHIC_MATCHER(isTemplateInstan
>> >  CXXRecordDecl))
>> > {
>> >return (Node.getTemplateSpecializationKind() ==
>> > TSK_ImplicitInstantiation ||
>> >Node.getTemplateSpecializationKind() ==
>> > -  TSK_ExplicitInstantiationDefinition);
>> > +  TSK_ExplicitInstantiationDefinition ||
>> > +  Node.getTemplateSpecializationKind() ==
>> > +  TSK_ExplicitInstantiationDeclaration);
>> >  }
>> >
>> >  /// \brief Matches declarations that are template instantiations or are
>> > inside
>> >
>> > Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=325678&r1=325677&r2=325678&view=diff
>> >
>> > ==
>> > --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
>> > (original)
>> > +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Wed Feb
>> > 21 05:51:27 2018
>> > @@ -1623,6 +1623,14 @@ TEST(IsTemplateInstantiation, MatchesExp
>> >"template class X;",
>> >  cxxRecordDecl(isTemplateInstantiation(), hasDescendant(
>> >fieldDecl(hasType(recordDecl(hasName("A";
>> > +
>> > +  // Make sure that we match the instantiation instead of the template
>> > +  // definition by checking whether the member function is present.
>> > +  EXPECT_TRUE(
>> > +  matches("template  class X { void f() { T t; } };"
>> > +  "extern template class X;",
>> > +  cxxRecordDecl(isTemplateInstantiation(),
>> > +
>> > unless(hasDescendant(varDecl(hasName("t")));
>> >  }
>> >
>> >  TEST(IsTemplateInstantiation,
>> >
>> >
>> > ___
>> > 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


r326036 - Add a C++11 and C2x spelling for the availability attribute in the clang vendor namespace.

2018-02-24 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sat Feb 24 09:16:42 2018
New Revision: 326036

URL: http://llvm.org/viewvc/llvm-project?rev=326036&view=rev
Log:
Add a C++11 and C2x spelling for the availability attribute in the clang vendor 
namespace.

This attribute has custom parsing rules that previously prevented it from being 
supported with square bracket notation. Rework the clang attribute argument 
parsing to be more easily extended for other custom-parsed attributes.

Added:
cfe/trunk/test/Sema/attr-availability-square-brackets.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Parse/ParseDecl.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326036&r1=326035&r2=326036&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sat Feb 24 09:16:42 2018
@@ -673,9 +673,7 @@ def AsmLabel : InheritableAttr {
 }
 
 def Availability : InheritableAttr {
-  // TODO: does not have a [[]] spelling because it requires custom parsing
-  // support.
-  let Spellings = [GNU<"availability">];
+  let Spellings = [Clang<"availability", 1>];
   let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=326036&r1=326035&r2=326036&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sat Feb 24 09:16:42 2018
@@ -404,14 +404,20 @@ unsigned Parser::ParseClangAttributeArgs
   AttributeList::Kind AttrKind =
   AttributeList::getKind(AttrName, ScopeName, Syntax);
 
-  if (AttrKind == AttributeList::AT_ExternalSourceSymbol) {
+  switch (AttrKind) {
+  default:
+return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
+ScopeName, ScopeLoc, Syntax);
+  case AttributeList::AT_ExternalSourceSymbol:
 ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
ScopeName, ScopeLoc, Syntax);
-return Attrs.getList() ? Attrs.getList()->getNumArgs() : 0;
+break;
+  case AttributeList::AT_Availability:
+ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, 
ScopeName,
+   ScopeLoc, Syntax);
+break;
   }
-
-  return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc,
-  ScopeName, ScopeLoc, Syntax);
+  return Attrs.getList() ? Attrs.getList()->getNumArgs() : 0;
 }
 
 bool Parser::ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName,

Added: cfe/trunk/test/Sema/attr-availability-square-brackets.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-availability-square-brackets.c?rev=326036&view=auto
==
--- cfe/trunk/test/Sema/attr-availability-square-brackets.c (added)
+++ cfe/trunk/test/Sema/attr-availability-square-brackets.c Sat Feb 24 09:16:42 
2018
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only 
-fdouble-square-bracket-attributes -verify %s
+
+void f0() [[clang::availability(macosx,introduced=10.4,deprecated=10.2)]]; // 
expected-warning{{feature cannot be deprecated in macOS version 10.2 before it 
was introduced in version 10.4; attribute ignored}}
+void f1() [[clang::availability(ios,obsoleted=2.1,deprecated=3.0)]];  // 
expected-warning{{feature cannot be obsoleted in iOS version 2.1 before it was 
deprecated in version 3.0; attribute ignored}}
+void f2() [[clang::availability(ios,introduced=2.1,deprecated=2.1)]];
+
+extern void
+ATSFontGetName(const char *oName) 
[[clang::availability(macosx,introduced=8.0,deprecated=9.0, message="use 
CTFontCopyFullName")]]; // expected-note {{'ATSFontGetName' has been explicitly 
marked deprecated here}}
+
+void test_10095131() {
+  ATSFontGetName("Hello"); // expected-warning {{'ATSFontGetName' is 
deprecated: first deprecated in macOS 9.0 - use CTFontCopyFullName}}
+}
+
+enum
+[[clang::availability(macos, unavailable)]]
+{
+NSDataWritingFileProtectionWriteOnly = 0x3000,
+NSDataWritingFileProtectionCompleteUntilUserAuthentication = 0x4000,
+};
+
+extern int x [[clang::availability(macosx,introduced=10.5)]];
+extern int x;
+
+int i [[clang::availability(this, should = 1.0)]]; // expected-error 
{{'should' is not an availability stage; use 'introduced', 'deprecated', or 
'obsoleted'}} \
+   // expected-warning 
{{unknown platform 'this' in availability macro}}


___

r326038 - Add a C++11 and C2x spelling for the objc_bridge_related attribute in the clang vendor namespace.

2018-02-24 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sat Feb 24 09:37:37 2018
New Revision: 326038

URL: http://llvm.org/viewvc/llvm-project?rev=326038&view=rev
Log:
Add a C++11 and C2x spelling for the objc_bridge_related attribute in the clang 
vendor namespace.

This attribute has custom parsing rules that previously prevented it from being 
supported with square bracket notation.

Added:
cfe/trunk/test/Sema/attr-objc-bridge-related.m
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Parse/ParseDecl.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326038&r1=326037&r2=326038&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sat Feb 24 09:37:37 2018
@@ -1503,9 +1503,7 @@ def ObjCBridgeMutable : InheritableAttr
 }
 
 def ObjCBridgeRelated : InheritableAttr {
-  // TODO: this attribute does not have a [[]] spelling because it requires
-  // custom parsing support.
-  let Spellings = [GNU<"objc_bridge_related">];
+  let Spellings = [Clang<"objc_bridge_related", 1>];
   let Subjects = SubjectList<[Record], ErrorDiag>;
   let Args = [IdentifierArgument<"RelatedClass">,
   IdentifierArgument<"ClassMethod", 1>,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=326038&r1=326037&r2=326038&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sat Feb 24 09:37:37 2018
@@ -416,6 +416,10 @@ unsigned Parser::ParseClangAttributeArgs
 ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, 
ScopeName,
ScopeLoc, Syntax);
 break;
+  case AttributeList::AT_ObjCBridgeRelated:
+ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
+ScopeName, ScopeLoc, Syntax);
+break;
   }
   return Attrs.getList() ? Attrs.getList()->getNumArgs() : 0;
 }

Added: cfe/trunk/test/Sema/attr-objc-bridge-related.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-objc-bridge-related.m?rev=326038&view=auto
==
--- cfe/trunk/test/Sema/attr-objc-bridge-related.m (added)
+++ cfe/trunk/test/Sema/attr-objc-bridge-related.m Sat Feb 24 09:37:37 2018
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fdouble-square-bracket-attributes %s
+
+struct [[clang::objc_bridge_related(NSParagraphStyle,,)]] TestBridgedRef;
+
+struct [[clang::objc_bridge_related(NSColor,colorWithCGColor:,CGColor)]] 
CGColorRefOk;
+struct [[clang::objc_bridge_related(,colorWithCGColor:,CGColor)]] 
CGColorRef1NotOk; // expected-error {{expected a related ObjectiveC class name, 
e.g., 'NSColor'}}
+struct [[clang::objc_bridge_related(NSColor,colorWithCGColor::,CGColor)]] 
CGColorRef3NotOk; // expected-error {{expected a class method selector with 
single argument, e.g., 'colorWithCGColor:'}}


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


r326052 - Add a C++11 and C2x spelling for the type safety attribute (argument_with_type_tag, pointer_with_type_tag, and type_tag_for_datatype) in the clang vendor namespace.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 06:01:04 2018
New Revision: 326052

URL: http://llvm.org/viewvc/llvm-project?rev=326052&view=rev
Log:
Add a C++11 and C2x spelling for the type safety attribute 
(argument_with_type_tag, pointer_with_type_tag, and type_tag_for_datatype) in 
the clang vendor namespace.

The TypeTagForDatatype attribute had custom parsing rules that previously 
prevented it from being supported with square bracket notation. The 
ArgumentWithTypeTag attribute previously had unnecessary custom parsing that 
could be handled declaratively.

Added:
cfe/trunk/test/Sema/attr-type-safety.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/warn-type-safety.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326052&r1=326051&r2=326052&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Feb 25 06:01:04 2018
@@ -2458,18 +2458,18 @@ def TestTypestate : InheritableAttr {
 // Type safety attributes for `void *' pointers and type tags.
 
 def ArgumentWithTypeTag : InheritableAttr {
-  let Spellings = [GNU<"argument_with_type_tag">,
-   GNU<"pointer_with_type_tag">];
+  let Spellings = [Clang<"argument_with_type_tag", 1>,
+   Clang<"pointer_with_type_tag", 1>];
+  let Subjects = SubjectList<[HasFunctionProto], ErrorDiag>;
   let Args = [IdentifierArgument<"ArgumentKind">,
   UnsignedArgument<"ArgumentIdx">,
   UnsignedArgument<"TypeTagIdx">,
-  BoolArgument<"IsPointer">];
-  let HasCustomParsing = 1;
+  BoolArgument<"IsPointer", /*opt*/0, /*fake*/1>];
   let Documentation = [ArgumentWithTypeTagDocs, PointerWithTypeTagDocs];
 }
 
 def TypeTagForDatatype : InheritableAttr {
-  let Spellings = [GNU<"type_tag_for_datatype">];
+  let Spellings = [Clang<"type_tag_for_datatype", 1>];
   let Args = [IdentifierArgument<"ArgumentKind">,
   TypeArgument<"MatchingCType">,
   BoolArgument<"LayoutCompatible">,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=326052&r1=326051&r2=326052&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Feb 25 06:01:04 2018
@@ -420,6 +420,10 @@ unsigned Parser::ParseClangAttributeArgs
 ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
 ScopeName, ScopeLoc, Syntax);
 break;
+  case AttributeList::AT_TypeTagForDatatype:
+ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc,
+ ScopeName, ScopeLoc, Syntax);
+break;
   }
   return Attrs.getList() ? Attrs.getList()->getNumArgs() : 0;
 }

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=326052&r1=326051&r2=326052&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Feb 25 06:01:04 2018
@@ -4554,17 +4554,6 @@ static void handleArgumentWithTypeTagAtt
 return;
   }
   
-  if (!checkAttributeNumArgs(S, AL, 3))
-return;
-
-  IdentifierInfo *ArgumentKind = AL.getArgAsIdent(0)->Ident;
-
-  if (!isFunctionOrMethod(D) || !hasFunctionProto(D)) {
-S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type)
-  << AL.getName() << ExpectedFunctionOrMethod;
-return;
-  }
-
   uint64_t ArgumentIdx;
   if (!checkFunctionOrMethodParameterIndex(S, D, AL, 2, AL.getArgAsExpr(1),
ArgumentIdx))
@@ -4575,7 +4564,7 @@ static void handleArgumentWithTypeTagAtt
TypeTagIdx))
 return;
 
-  bool IsPointer = (AL.getName()->getName() == "pointer_with_type_tag");
+  bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag";
   if (IsPointer) {
 // Ensure that buffer has a pointer type.
 QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
@@ -4585,10 +4574,9 @@ static void handleArgumentWithTypeTagAtt
 }
   }
 
-  D->addAttr(::new (S.Context)
- ArgumentWithTypeTagAttr(AL.getRange(), S.Context, ArgumentKind,
- ArgumentIdx, TypeTagIdx, IsPointer,
- AL.getAttributeSpellingListIndex()));
+  D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(
+  AL.getRange(), S.Context, AL.getArgAsIdent(0)->Ident, ArgumentIdx,
+  TypeTagIdx, IsPointer, AL.getAttributeSpellingListIndex()));
 }
 
 static void h

r326053 - Add a C2x spelling for the external_source_symbol and internal_linkage attributes in the clang vendor namespace.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 06:43:45 2018
New Revision: 326053

URL: http://llvm.org/viewvc/llvm-project?rev=326053&view=rev
Log:
Add a C2x spelling for the external_source_symbol and internal_linkage 
attributes in the clang vendor namespace.

Both of these attributes have existing meaning in C code, so there was no 
reason to exclude them from using the new spelling.

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/test/Sema/attr-external-source-symbol.c
cfe/trunk/test/Sema/internal_linkage.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326053&r1=326052&r2=326053&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Feb 25 06:43:45 2018
@@ -723,7 +723,7 @@ static llvm::StringRef canonicalizePlatf
 }
 
 def ExternalSourceSymbol : InheritableAttr {
-  let Spellings = [Clang<"external_source_symbol">];
+  let Spellings = [Clang<"external_source_symbol", 1>];
   let Args = [StringArgument<"language", 1>,
   StringArgument<"definedIn", 1>,
   BoolArgument<"generatedDeclaration", 1>];
@@ -2817,7 +2817,7 @@ def OMPDeclareTargetDecl : Attr {
 }
 
 def InternalLinkage : InheritableAttr {
-  let Spellings = [Clang<"internal_linkage">];
+  let Spellings = [Clang<"internal_linkage", 1>];
   let Subjects = SubjectList<[Var, Function, CXXRecord]>;
   let Documentation = [InternalLinkageDocs];
 }

Modified: cfe/trunk/test/Sema/attr-external-source-symbol.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-external-source-symbol.c?rev=326053&r1=326052&r2=326053&view=diff
==
--- cfe/trunk/test/Sema/attr-external-source-symbol.c (original)
+++ cfe/trunk/test/Sema/attr-external-source-symbol.c Sun Feb 25 06:43:45 2018
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fblocks -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify 
-fdouble-square-bracket-attributes %s
 
 void threeClauses() __attribute__((external_source_symbol(language="Swift", 
defined_in="module", generated_declaration)));
 
@@ -17,3 +17,15 @@ void namedDeclsOnly() {
   return 1;
   };
 }
+
+void threeClauses2() [[clang::external_source_symbol(language="Swift", 
defined_in="module", generated_declaration)]];
+
+void twoClauses2() [[clang::external_source_symbol(language="Swift", 
defined_in="module")]];
+
+void fourClauses2()
+[[clang::external_source_symbol(language="Swift", defined_in="module", 
generated_declaration, generated_declaration)]]; // expected-error {{duplicate 
'generated_declaration' clause in an 'external_source_symbol' attribute}}
+
+void oneClause2() [[clang::external_source_symbol(generated_declaration)]];
+
+void noArguments2()
+[[clang::external_source_symbol]]; // expected-error 
{{'external_source_symbol' attribute takes at least 1 argument}}

Modified: cfe/trunk/test/Sema/internal_linkage.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/internal_linkage.c?rev=326053&r1=326052&r2=326053&view=diff
==
--- cfe/trunk/test/Sema/internal_linkage.c (original)
+++ cfe/trunk/test/Sema/internal_linkage.c Sun Feb 25 06:43:45 2018
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fdouble-square-bracket-attributes %s
 
 int var __attribute__((internal_linkage));
 int var2 __attribute__((internal_linkage,common)); // 
expected-error{{'internal_linkage' and 'common' attributes are not compatible}} 
\
@@ -19,3 +19,9 @@ struct __attribute__((internal_linkage))
 };
 
 __attribute__((internal_linkage("foo"))) int g() {} // 
expected-error{{'internal_linkage' attribute takes no arguments}}
+
+int var6 [[clang::internal_linkage]];
+int var7 [[clang::internal_linkage]] __attribute__((common)); // 
expected-error{{'internal_linkage' and 'common' attributes are not compatible}} 
\
+   // 
expected-note{{conflicting attribute is here}}
+__attribute__((common)) int var8 [[clang::internal_linkage]]; // 
expected-error{{'internal_linkage' and 'common' attributes are not compatible}} 
\
+   // 
expected-note{{conflicting attribute is here}}


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


r326054 - Document why the consumed attributes (consumable, callable_when, et al) are not exposed with a C2x spelling. NFC.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 06:54:25 2018
New Revision: 326054

URL: http://llvm.org/viewvc/llvm-project?rev=326054&view=rev
Log:
Document why the consumed attributes (consumable, callable_when, et al) are not 
exposed with a C2x spelling. NFC.

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

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326054&r1=326053&r2=326054&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Feb 25 06:54:25 2018
@@ -2390,6 +2390,9 @@ def LocksExcluded : InheritableAttr {
 // C/C++ consumed attributes.
 
 def Consumable : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ struct/class/union.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"consumable">];
   let Subjects = SubjectList<[CXXRecord]>;
   let Args = [EnumArgument<"DefaultState", "ConsumedState",
@@ -2399,18 +2402,27 @@ def Consumable : InheritableAttr {
 }
 
 def ConsumableAutoCast : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ struct/class/union.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"consumable_auto_cast_state">];
   let Subjects = SubjectList<[CXXRecord]>;
   let Documentation = [Undocumented];
 }
 
 def ConsumableSetOnRead : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ struct/class/union.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"consumable_set_state_on_read">];
   let Subjects = SubjectList<[CXXRecord]>;
   let Documentation = [Undocumented];
 }
 
 def CallableWhen : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ function (but doesn't require it to be a member function).
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"callable_when">];
   let Subjects = SubjectList<[CXXMethod]>;
   let Args = [VariadicEnumArgument<"CallableStates", "ConsumedState",
@@ -2420,6 +2432,9 @@ def CallableWhen : InheritableAttr {
 }
 
 def ParamTypestate : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to a parameter whose type is a consumable C++ class.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"param_typestate">];
   let Subjects = SubjectList<[ParmVar]>;
   let Args = [EnumArgument<"ParamState", "ConsumedState",
@@ -2429,6 +2444,9 @@ def ParamTypestate : InheritableAttr {
 }
 
 def ReturnTypestate : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to a parameter or function return type that is a consumable C++ class.
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"return_typestate">];
   let Subjects = SubjectList<[Function, ParmVar]>;
   let Args = [EnumArgument<"State", "ConsumedState",
@@ -2438,6 +2456,9 @@ def ReturnTypestate : InheritableAttr {
 }
 
 def SetTypestate : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ function (but doesn't require it to be a member function).
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"set_typestate">];
   let Subjects = SubjectList<[CXXMethod]>;
   let Args = [EnumArgument<"NewState", "ConsumedState",
@@ -2447,6 +2468,9 @@ def SetTypestate : InheritableAttr {
 }
 
 def TestTypestate : InheritableAttr {
+  // This attribute does not have a C [[]] spelling because it only appertains
+  // to C++ function (but doesn't require it to be a member function).
+  // FIXME: should this attribute have a CPlusPlus language option?
   let Spellings = [Clang<"test_typestate">];
   let Subjects = SubjectList<[CXXMethod]>;
   let Args = [EnumArgument<"TestState", "ConsumedState",


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


r326055 - Switch the default behavior of the Clang<> spelling to opt-in to the C2x attribute spellings. NFC to the attribute spellings themselves.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 07:34:17 2018
New Revision: 326055

URL: http://llvm.org/viewvc/llvm-project?rev=326055&view=rev
Log:
Switch the default behavior of the Clang<> spelling to opt-in to the C2x 
attribute spellings. NFC to the attribute spellings themselves.

The Clang<> spelling helper generates a spelling for C++11, GNU, and C2x 
attribute spellings. Previously, users had to manually opt in to the C2x 
spelling while we cautiously added attributes to that spelling. Now that 
majority of attributes are exposed in C2x, we can switch the default.

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

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326055&r1=326054&r2=326055&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Feb 25 07:34:17 2018
@@ -237,7 +237,7 @@ class GCC : Spelling, CXX11<"clang", name>, and optionally,
 // C2x<"clang", name>. This spelling should be used for any Clang-specific
 // attributes.
-class Clang : Spelling {
+class Clang : Spelling {
   bit AllowInC = allowInC;
 }
 
@@ -534,7 +534,7 @@ def AbiTag : Attr {
 }
 
 def AddressSpace : TypeAttr {
-  let Spellings = [Clang<"address_space", 1>];
+  let Spellings = [Clang<"address_space">];
   let Args = [IntArgument<"AddressSpace">];
   let Documentation = [Undocumented];
 }
@@ -598,18 +598,18 @@ def Artificial : InheritableAttr {
 }
 
 def XRayInstrument : InheritableAttr {
-  let Spellings = [Clang<"xray_always_instrument", 1>,
-   Clang<"xray_never_instrument", 1>];
+  let Spellings = [Clang<"xray_always_instrument">,
+   Clang<"xray_never_instrument">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Accessors = [Accessor<"alwaysXRayInstrument",
- [Clang<"xray_always_instrument", 1>]>,
+ [Clang<"xray_always_instrument">]>,
Accessor<"neverXRayInstrument",
- [Clang<"xray_never_instrument", 1>]>];
+ [Clang<"xray_never_instrument">]>];
   let Documentation = [XRayDocs];
 }
 
 def XRayLogArgs : InheritableAttr {
-  let Spellings = [Clang<"xray_log_args", 1>];
+  let Spellings = [Clang<"xray_log_args">];
   let Subjects = SubjectList<[Function, ObjCMethod]>;
   let Args = [UnsignedArgument<"ArgumentCount">];
   let Documentation = [XRayDocs];
@@ -631,7 +631,7 @@ def AnalyzerNoReturn : InheritableAttr {
 }
 
 def Annotate : InheritableParamAttr {
-  let Spellings = [Clang<"annotate", 1>];
+  let Spellings = [Clang<"annotate">];
   let Args = [StringArgument<"Annotation">];
   // Ensure that the annotate attribute can be used with
   // '#pragma clang attribute' even though it has no subject list.
@@ -673,7 +673,7 @@ def AsmLabel : InheritableAttr {
 }
 
 def Availability : InheritableAttr {
-  let Spellings = [Clang<"availability", 1>];
+  let Spellings = [Clang<"availability">];
   let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
@@ -723,7 +723,7 @@ static llvm::StringRef canonicalizePlatf
 }
 
 def ExternalSourceSymbol : InheritableAttr {
-  let Spellings = [Clang<"external_source_symbol", 1>];
+  let Spellings = [Clang<"external_source_symbol">];
   let Args = [StringArgument<"language", 1>,
   StringArgument<"definedIn", 1>,
   BoolArgument<"generatedDeclaration", 1>];
@@ -733,7 +733,7 @@ def ExternalSourceSymbol : InheritableAt
 }
 
 def Blocks : InheritableAttr {
-  let Spellings = [Clang<"blocks", 1>];
+  let Spellings = [Clang<"blocks">];
   let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
   let Documentation = [Undocumented];
 }
@@ -761,7 +761,7 @@ def CDecl : InheritableAttr {
 // cf_returns_retained attributes.  It is generally applied by
 // '#pragma clang arc_cf_code_audited' rather than explicitly.
 def CFAuditedTransfer : InheritableAttr {
-  let Spellings = [Clang<"cf_audited_transfer", 1>];
+  let Spellings = [Clang<"cf_audited_transfer">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [Undocumented];
 }
@@ -770,25 +770,25 @@ def CFAuditedTransfer : InheritableAttr
 // It indicates that the function has unknown or unautomatable
 // transfer semantics.
 def CFUnknownTransfer : InheritableAttr {
-  let Spellings = [Clang<"cf_unknown_transfer", 1>];
+  let Spellings = [Clang<"cf_unknown_transfer">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [Undocumented];
 }
 
 def CFReturnsRetained : InheritableAttr {
-  let Spellings = [Clang<"cf_returns_retained", 1>];
+  let Spellings = [Clang<"cf_returns_retained">];
 //  let Subjects = SubjectList<[ObjCMethod, ObjCProperty, Fu

r326057 - Fix a failing assertion with the pointer_with_type_tag attribute when the function the attribute appertains to is variadic.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 12:28:10 2018
New Revision: 326057

URL: http://llvm.org/viewvc/llvm-project?rev=326057&view=rev
Log:
Fix a failing assertion with the pointer_with_type_tag attribute when the 
function the attribute appertains to is variadic.

Patch by Joel Denny.

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/warn-type-safety.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=326057&r1=326056&r2=326057&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Feb 25 12:28:10 2018
@@ -4567,11 +4567,10 @@ static void handleArgumentWithTypeTagAtt
   bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag";
   if (IsPointer) {
 // Ensure that buffer has a pointer type.
-QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
-if (!BufferTy->isPointerType()) {
+if (ArgumentIdx >= getFunctionOrMethodNumParams(D) ||
+!getFunctionOrMethodParamType(D, ArgumentIdx)->isPointerType())
   S.Diag(AL.getLoc(), diag::err_attribute_pointers_only)
-<< AL.getName() << 0;
-}
+  << AL.getName() << 0;
   }
 
   D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(

Modified: cfe/trunk/test/Sema/warn-type-safety.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-type-safety.c?rev=326057&r1=326056&r2=326057&view=diff
==
--- cfe/trunk/test/Sema/warn-type-safety.c (original)
+++ cfe/trunk/test/Sema/warn-type-safety.c Sun Feb 25 12:28:10 2018
@@ -37,6 +37,10 @@ int wrong9 __attribute__(( pointer_with_
 int wrong10(double buf, MPI_Datatype type)
 __attribute__(( pointer_with_type_tag(mpi,1,2) )); // expected-error 
{{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
+int ok11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,1,2) ));
+int wrong11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,2,3) )); // expected-error 
{{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
 extern struct A datatype_wrong1
 __attribute__(( type_tag_for_datatype )); // expected-error 
{{'type_tag_for_datatype' attribute requires parameter 1 to be an identifier}}


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


r326058 - When diagnosing the arguments to alloc_size, report the failing argument using a 1-based index instead of a 0-based index for consistency.

2018-02-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 25 12:40:06 2018
New Revision: 326058

URL: http://llvm.org/viewvc/llvm-project?rev=326058&view=rev
Log:
When diagnosing the arguments to alloc_size, report the failing argument using 
a 1-based index instead of a 0-based index for consistency.

Patch by Joel Denny.

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/alloc-size.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=326058&r1=326057&r2=326058&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Feb 25 12:40:06 2018
@@ -765,19 +765,19 @@ static void handleAssertExclusiveLockAtt
   AL.getAttributeSpellingListIndex()));
 }
 
-/// \brief Checks to be sure that the given parameter number is in bounds, and 
is
-/// an integral type. Will emit appropriate diagnostics if this returns
+/// \brief Checks to be sure that the given parameter number is in bounds, and
+/// is an integral type. Will emit appropriate diagnostics if this returns
 /// false.
 ///
-/// FuncParamNo is expected to be from the user, so is base-1. AttrArgNo is 
used
-/// to actually retrieve the argument, so it's base-0.
+/// AttrArgNo is used to actually retrieve the argument, so it's base-0.
 template 
 static bool checkParamIsIntegerType(Sema &S, const FunctionDecl *FD,
-const AttrInfo &AI, Expr *AttrArg,
-unsigned FuncParamNo, unsigned AttrArgNo,
+const AttrInfo &AI, unsigned AttrArgNo,
 bool AllowDependentType = false) {
+  assert(AI.isArgExpr(AttrArgNo) && "Expected expression argument");
+  Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
   uint64_t Idx;
-  if (!checkFunctionOrMethodParameterIndex(S, FD, AI, FuncParamNo, AttrArg,
+  if (!checkFunctionOrMethodParameterIndex(S, FD, AI, AttrArgNo + 1, AttrArg,
Idx))
 return false;
 
@@ -793,20 +793,6 @@ static bool checkParamIsIntegerType(Sema
   return true;
 }
 
-/// \brief Checks to be sure that the given parameter number is in bounds, and 
is
-/// an integral type. Will emit appropriate diagnostics if this returns false.
-///
-/// FuncParamNo is expected to be from the user, so is base-1. AttrArgNo is 
used
-/// to actually retrieve the argument, so it's base-0.
-static bool checkParamIsIntegerType(Sema &S, const FunctionDecl *FD,
-const AttributeList &AL,
-unsigned FuncParamNo, unsigned AttrArgNo,
-bool AllowDependentType = false) {
-  assert(AL.isArgExpr(AttrArgNo) && "Expected expression argument");
-  return checkParamIsIntegerType(S, FD, AL, AL.getArgAsExpr(AttrArgNo),
- FuncParamNo, AttrArgNo, AllowDependentType);
-}
-
 static void handleAllocSizeAttr(Sema &S, Decl *D, const AttributeList &AL) {
   if (!checkAttributeAtLeastNumArgs(S, AL, 1) ||
   !checkAttributeAtMostNumArgs(S, AL, 2))
@@ -825,7 +811,7 @@ static void handleAllocSizeAttr(Sema &S,
   if (!checkPositiveIntArgument(S, AL, SizeExpr, SizeArgNo, /*Index=*/1))
 return;
 
-  if (!checkParamIsIntegerType(S, FD, AL, SizeArgNo, /*AttrArgNo=*/0))
+  if (!checkParamIsIntegerType(S, FD, AL, /*AttrArgNo=*/0))
 return;
 
   // Args are 1-indexed, so 0 implies that the arg was not present
@@ -837,7 +823,7 @@ static void handleAllocSizeAttr(Sema &S,
   /*Index=*/2))
   return;
 
-if (!checkParamIsIntegerType(S, FD, AL, NumberArgNo, /*AttrArgNo=*/1))
+if (!checkParamIsIntegerType(S, FD, AL, /*AttrArgNo=*/1))
   return;
   }
 

Modified: cfe/trunk/test/Sema/alloc-size.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/alloc-size.c?rev=326058&r1=326057&r2=326058&view=diff
==
--- cfe/trunk/test/Sema/alloc-size.c (original)
+++ cfe/trunk/test/Sema/alloc-size.c Sun Feb 25 12:40:06 2018
@@ -3,14 +3,14 @@
 void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' 
attribute takes at least 1 argument}}
 void *fail2(int a) __attribute__((alloc_size())); 
//expected-error{{'alloc_size' attribute takes at least 1 argument}}
 
-void *fail3(int a) __attribute__((alloc_size(0))); 
//expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
-void *fail4(int a) __attribute__((alloc_size(2))); 
//expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
+void *fail3(int a) __attribute__((alloc_size(0))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
+void *fail4(int a) __attribute__((alloc_size(2))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
 
-void *f

Re: r303712 - Enhance the 'diagnose_if' attribute so that we can apply it for ObjC methods and properties as well

2017-05-24 Thread Aaron Ballman via cfe-commits
On Tue, May 23, 2017 at 8:46 PM, Argyrios Kyrtzidis via cfe-commits
 wrote:
> Author: akirtzidis
> Date: Tue May 23 19:46:27 2017
> New Revision: 303712
>
> URL: http://llvm.org/viewvc/llvm-project?rev=303712&view=rev
> Log:
> Enhance the 'diagnose_if' attribute so that we can apply it for ObjC methods 
> and properties as well
>
> This is an initial commit to allow using it with constant expressions, a 
> follow-up commit will enable full support for it in ObjC methods.
>
> Added:
> cfe/trunk/test/SemaObjC/diagnose_if.m
> Modified:
> cfe/trunk/include/clang/Basic/Attr.td
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Sema/AttributeList.h
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/lib/Sema/SemaOverload.cpp
> cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=303712&r1=303711&r2=303712&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Tue May 23 19:46:27 2017
> @@ -149,6 +149,9 @@ class ExprArgument  class FunctionArgument : 
> Argument
> opt,
>
> fake>;
> +class NamedArgument : Argument +  
> opt,
> +  
> fake>;
>  class TypeArgument : Argument;
>  class UnsignedArgument : Argument;
>  class VariadicUnsignedArgument : Argument;
> @@ -1819,14 +1822,14 @@ def Unavailable : InheritableAttr {
>
>  def DiagnoseIf : InheritableAttr {
>let Spellings = [GNU<"diagnose_if">];
> -  let Subjects = SubjectList<[Function]>;
> +  let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
>let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
>EnumArgument<"DiagnosticType",
> "DiagnosticType",
> ["error", "warning"],
> ["DT_Error", "DT_Warning"]>,
>BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
> -  FunctionArgument<"Parent", 0, /*fake*/ 1>];
> +  NamedArgument<"Parent", 0, /*fake*/ 1>];
>let DuplicatesAllowedWhileMerging = 1;
>let LateParsed = 1;
>let AdditionalMembers = [{
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=303712&r1=303711&r2=303712&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 23 19:46:27 
> 2017
> @@ -2771,6 +2771,7 @@ def warn_attribute_wrong_decl_type : War
>"|types and namespaces"
>"|Objective-C interfaces"
>"|methods and properties"
> +  "|functions, methods and properties"

functions, methods, and properties (inserting the Oxford comma).

>"|struct or union"
>"|struct, union or class"
>"|types"
>
> Modified: cfe/trunk/include/clang/Sema/AttributeList.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=303712&r1=303711&r2=303712&view=diff
> ==
> --- cfe/trunk/include/clang/Sema/AttributeList.h (original)
> +++ cfe/trunk/include/clang/Sema/AttributeList.h Tue May 23 19:46:27 2017
> @@ -915,6 +915,7 @@ enum AttributeDeclKind {
>ExpectedTypeOrNamespace,
>ExpectedObjectiveCInterface,
>ExpectedMethodOrProperty,
> +  ExpectedFunctionOrMethodOrProperty,
>ExpectedStructOrUnion,
>ExpectedStructOrUnionOrClass,
>ExpectedType,
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=303712&r1=303711&r2=303712&view=diff
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Tue May 23 19:46:27 2017
> @@ -2727,7 +2727,7 @@ public:
>/// of a function.
>///
>/// Returns true if any errors were emitted.
> -  bool diagnoseArgIndependentDiagnoseIfAttrs(const FunctionDecl *Function,
> +  bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND,
>   SourceLocation Loc);
>
>/// Returns whether the given function's address can be taken or not,
>
> Modified: cfe/trunk/lib/Lex/PPMa

Re: r303712 - Enhance the 'diagnose_if' attribute so that we can apply it for ObjC methods and properties as well

2017-05-24 Thread Aaron Ballman via cfe-commits
On Wed, May 24, 2017 at 1:05 PM, Argyrios Kyrtzidis  wrote:
>
>> On May 24, 2017, at 8:59 AM, Aaron Ballman  wrote:
>>
>> On Tue, May 23, 2017 at 8:46 PM, Argyrios Kyrtzidis via cfe-commits
>>  wrote:
>>> Author: akirtzidis
>>> Date: Tue May 23 19:46:27 2017
>>> New Revision: 303712
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=303712&view=rev
>>> Log:
>>> Enhance the 'diagnose_if' attribute so that we can apply it for ObjC 
>>> methods and properties as well
>>>
>>> This is an initial commit to allow using it with constant expressions, a 
>>> follow-up commit will enable full support for it in ObjC methods.
>>>
>>> Added:
>>>cfe/trunk/test/SemaObjC/diagnose_if.m
>>> Modified:
>>>cfe/trunk/include/clang/Basic/Attr.td
>>>cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>>cfe/trunk/include/clang/Sema/AttributeList.h
>>>cfe/trunk/include/clang/Sema/Sema.h
>>>cfe/trunk/lib/Lex/PPMacroExpansion.cpp
>>>cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>>>cfe/trunk/lib/Sema/SemaExpr.cpp
>>>cfe/trunk/lib/Sema/SemaOverload.cpp
>>>cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
>>>
>>> Modified: cfe/trunk/include/clang/Basic/Attr.td
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=303712&r1=303711&r2=303712&view=diff
>>> ==
>>> --- cfe/trunk/include/clang/Basic/Attr.td (original)
>>> +++ cfe/trunk/include/clang/Basic/Attr.td Tue May 23 19:46:27 2017
>>> @@ -149,6 +149,9 @@ class ExprArgument>> class FunctionArgument : 
>>> Argument>>   
>>> opt,
>>>   
>>> fake>;
>>> +class NamedArgument : 
>>> Argument>> +  
>>> opt,
>>> +  
>>> fake>;
>>> class TypeArgument : Argument;
>>> class UnsignedArgument : Argument;
>>> class VariadicUnsignedArgument : Argument;
>>> @@ -1819,14 +1822,14 @@ def Unavailable : InheritableAttr {
>>>
>>> def DiagnoseIf : InheritableAttr {
>>>   let Spellings = [GNU<"diagnose_if">];
>>> -  let Subjects = SubjectList<[Function]>;
>>> +  let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
>>>   let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
>>>   EnumArgument<"DiagnosticType",
>>>"DiagnosticType",
>>>["error", "warning"],
>>>["DT_Error", "DT_Warning"]>,
>>>   BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
>>> -  FunctionArgument<"Parent", 0, /*fake*/ 1>];
>>> +  NamedArgument<"Parent", 0, /*fake*/ 1>];
>>>   let DuplicatesAllowedWhileMerging = 1;
>>>   let LateParsed = 1;
>>>   let AdditionalMembers = [{
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=303712&r1=303711&r2=303712&view=diff
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 23 
>>> 19:46:27 2017
>>> @@ -2771,6 +2771,7 @@ def warn_attribute_wrong_decl_type : War
>>>   "|types and namespaces"
>>>   "|Objective-C interfaces"
>>>   "|methods and properties"
>>> +  "|functions, methods and properties"
>>
>> functions, methods, and properties (inserting the Oxford comma).
>
> Ok.
>
>>
>>>   "|struct or union"
>>>   "|struct, union or class"
>>>   "|types"
>>>
>>> Modified: cfe/trunk/include/clang/Sema/AttributeList.h
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=303712&r1=303711&r2=303712&view=diff
>>> ==
>>> --- cfe/trunk/include/clang/Sema/AttributeList.h (original)
>>> +++ cfe/trunk/include/clang/Sema/AttributeList.h Tue May 23 19:46:27 2017
>>> @@ -915,6 +915,7 @@ enum AttributeDeclKind {
>>>   ExpectedTypeOrNamespace,
>>>   ExpectedObjectiveCInterface,
>>>   ExpectedMethodOrProperty,
>>> +  ExpectedFunctionOrMethodOrProperty,
>>>   ExpectedStructOrUnion,
>>>   ExpectedStructOrUnionOrClass,
>>>   ExpectedType,
>>>
>>> Modified: cfe/trunk/include/clang/Sema/Sema.h
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=303712&r1=303711&r2=303712&view=diff
>>> ==
>>> --- cfe/trunk/include/clang/Sema/Sema.h (original)
>>> +++ cfe/trunk/include/clang/Sema/Sema.h Tue May 23 19:46:27 2017
>>> @@ -2727,7 +2727,7 @@ public:
>>>   /// of a function.
>>>   ///
>>>   /// Returns true if any errors were emitted.
>>> -  bool di

Re: r303712 - Enhance the 'diagnose_if' attribute so that we can apply it for ObjC methods and properties as well

2017-05-24 Thread Aaron Ballman via cfe-commits
On Wed, May 24, 2017 at 1:37 PM, Argyrios Kyrtzidis  wrote:
>
> On May 24, 2017, at 10:12 AM, Aaron Ballman  wrote:
>
> On Wed, May 24, 2017 at 1:05 PM, Argyrios Kyrtzidis 
> wrote:
>
>
> On May 24, 2017, at 8:59 AM, Aaron Ballman  wrote:
>
> On Tue, May 23, 2017 at 8:46 PM, Argyrios Kyrtzidis via cfe-commits
>  wrote:
>
> Author: akirtzidis
> Date: Tue May 23 19:46:27 2017
> New Revision: 303712
>
> URL: http://llvm.org/viewvc/llvm-project?rev=303712&view=rev
> Log:
> Enhance the 'diagnose_if' attribute so that we can apply it for ObjC methods
> and properties as well
>
> This is an initial commit to allow using it with constant expressions, a
> follow-up commit will enable full support for it in ObjC methods.
>
> Added:
>   cfe/trunk/test/SemaObjC/diagnose_if.m
> Modified:
>   cfe/trunk/include/clang/Basic/Attr.td
>   cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>   cfe/trunk/include/clang/Sema/AttributeList.h
>   cfe/trunk/include/clang/Sema/Sema.h
>   cfe/trunk/lib/Lex/PPMacroExpansion.cpp
>   cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>   cfe/trunk/lib/Sema/SemaExpr.cpp
>   cfe/trunk/lib/Sema/SemaOverload.cpp
>   cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=303712&r1=303711&r2=303712&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Tue May 23 19:46:27 2017
> @@ -149,6 +149,9 @@ class ExprArgument class FunctionArgument :
> Argument
> opt,
>
> fake>;
> +class NamedArgument :
> Argument +
> opt,
> +
> fake>;
> class TypeArgument : Argument;
> class UnsignedArgument : Argument;
> class VariadicUnsignedArgument : Argument;
> @@ -1819,14 +1822,14 @@ def Unavailable : InheritableAttr {
>
> def DiagnoseIf : InheritableAttr {
>  let Spellings = [GNU<"diagnose_if">];
> -  let Subjects = SubjectList<[Function]>;
> +  let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
>  let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
>  EnumArgument<"DiagnosticType",
>   "DiagnosticType",
>   ["error", "warning"],
>   ["DT_Error", "DT_Warning"]>,
>  BoolArgument<"ArgDependent", 0, /*fake*/ 1>,
> -  FunctionArgument<"Parent", 0, /*fake*/ 1>];
> +  NamedArgument<"Parent", 0, /*fake*/ 1>];
>  let DuplicatesAllowedWhileMerging = 1;
>  let LateParsed = 1;
>  let AdditionalMembers = [{
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=303712&r1=303711&r2=303712&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 23 19:46:27
> 2017
> @@ -2771,6 +2771,7 @@ def warn_attribute_wrong_decl_type : War
>  "|types and namespaces"
>  "|Objective-C interfaces"
>  "|methods and properties"
> +  "|functions, methods and properties"
>
>
> functions, methods, and properties (inserting the Oxford comma).
>
>
> Ok.
>
>
>  "|struct or union"
>  "|struct, union or class"
>  "|types"
>
> Modified: cfe/trunk/include/clang/Sema/AttributeList.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=303712&r1=303711&r2=303712&view=diff
> ==
> --- cfe/trunk/include/clang/Sema/AttributeList.h (original)
> +++ cfe/trunk/include/clang/Sema/AttributeList.h Tue May 23 19:46:27 2017
> @@ -915,6 +915,7 @@ enum AttributeDeclKind {
>  ExpectedTypeOrNamespace,
>  ExpectedObjectiveCInterface,
>  ExpectedMethodOrProperty,
> +  ExpectedFunctionOrMethodOrProperty,
>  ExpectedStructOrUnion,
>  ExpectedStructOrUnionOrClass,
>  ExpectedType,
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=303712&r1=303711&r2=303712&view=diff
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Tue May 23 19:46:27 2017
> @@ -2727,7 +2727,7 @@ public:
>  /// of a function.
>  ///
>  /// Returns true if any errors were emitted.
> -  bool diagnoseArgIndependentDiagnoseIfAttrs(const FunctionDecl *Function,
> +  bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND,
> SourceLocation Loc);
>
>  /// Returns whether the given function's address can be taken or not,
>
> Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=303712&r1=30371

r303913 - Update the getting started documentation to match the corresponding LLVM commit in r303912.

2017-05-25 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu May 25 16:02:49 2017
New Revision: 303913

URL: http://llvm.org/viewvc/llvm-project?rev=303913&view=rev
Log:
Update the getting started documentation to match the corresponding LLVM commit 
in r303912.

Modified:
cfe/trunk/www/get_started.html

Modified: cfe/trunk/www/get_started.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/get_started.html?rev=303913&r1=303912&r2=303913&view=diff
==
--- cfe/trunk/www/get_started.html (original)
+++ cfe/trunk/www/get_started.html Thu May 25 16:02:49 2017
@@ -196,6 +196,10 @@ Visual Studio:
 mkdir build (for building without polluting the source 
dir)
 cd build
 If you are using Visual Studio 2013:  cmake -G "Visual Studio 12" 
..\llvm
+By default, the Visual Studio project files generated by CMake use the
+ 32-bit toolset. If you are developing on a 64-bit version of Windows and
+ want to use the 64-bit toolset, pass the ``-Thost=x64`` flag when
+ generating the Visual Studio solution. This requires CMake 3.8.0 or 
later.
 See the http://www.llvm.org/docs/CMake.html";>LLVM CMake 
guide for
 more information on other configuration options for CMake.
 The above, if successful, will have created an LLVM.sln file in the


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


r304000 - Adding a const overload of DesignatedInitExpr::getDesignator().

2017-05-26 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri May 26 10:55:52 2017
New Revision: 304000

URL: http://llvm.org/viewvc/llvm-project?rev=304000&view=rev
Log:
Adding a const overload of DesignatedInitExpr::getDesignator().

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

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=304000&r1=303999&r2=304000&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri May 26 10:55:52 2017
@@ -4284,6 +4284,9 @@ public:
   }
 
   Designator *getDesignator(unsigned Idx) { return &designators()[Idx]; }
+  const Designator *getDesignator(unsigned Idx) const {
+return &designators()[Idx];
+  }
 
   void setDesignators(const ASTContext &C, const Designator *Desigs,
   unsigned NumDesigs);


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


Re: [PATCH] D33788: Return a canonical path from getClangResourcePath()

2017-06-02 Thread Aaron Ballman via cfe-commits
On Fri, Jun 2, 2017 at 3:04 PM, Richard Smith  wrote:
> On 2 June 2017 at 11:39, Aaron Ballman via Phabricator via cfe-commits
>  wrote:
>>
>> aaron.ballman added a comment.
>>
>> In https://reviews.llvm.org/D33788#771671, @bruno wrote:
>>
>> > > I'm unaware of any other API that canonicalizes the path, which is
>> > > what users of this API are going to expect.
>> >
>> > You can also call `sys::path::remove_dots(Path,
>> > /*remove_dot_dot=*/true);`
>>
>>
>> Yes, but that does not canonicalize the path. For instance, it won't
>> handle doubled-up slashes or symlinks.
>
>
> That's at least partly a feature, not a bug. Resolving symlinks and removing
> x/.. are both potentially breaking changes when applied to the path -- if
> you canonicalize, you break installations where the file is actually a
> symlink to a file that does *not* also have a resource directory relative to
> it.

Breaking changes would be bad, but I'm not particularly sympathetic to
that use case compared to expecting callers to canonicalize the
results before passing off to POSIX APIs (as we do). Effectively, by
pushing this off to callers, we create a more fragile system that's
harder to reason about. You could argue that while this does break
such an installation, the installation is rather defective for
expecting the symlink to not resolve.

> The path with the bin/../lib in it is presumably the path from the clang
> binary, not the path from libclang, so it's not clear to me that this patch
> would even help -- the clang driver also does not canonicalize the path (see
> SetInstallDir in tools/driver/driver.cpp).

To be clear: this change fixed the test case breakage we were seeing.
So I do believe it helps. ;-)

>> Ultimately, the value returned from this API gets passed to POSIX
>> functions which expect a canonical path. I don't think `remove_dots()` is
>> sufficient. It should do the same thing as `getMainExecutable()`, I believe.
>
>
> Note that we don't actually use getMainExecutable for the main clang driver,
> just for tooling purposes, and it *also* does not canonicalize.

Maybe I'm confused, but in main() (ToolChain.cpp), I see a call to
GetExecutablePath(), and it canonicalizes prefixes unless passing
-no-canonical-prefixes. When canonicalizing, it calls
getMainExecutable(), which calls real_path() in at least two cases
(one of which is for __APPLE__ targets).

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


Re: [PATCH] D33788: Return a canonical path from getClangResourcePath()

2017-06-02 Thread Aaron Ballman via cfe-commits
On Fri, Jun 2, 2017 at 3:22 PM, Richard Smith  wrote:
> On 2 June 2017 at 12:04, Richard Smith  wrote:
>>
>> On 2 June 2017 at 11:39, Aaron Ballman via Phabricator via cfe-commits
>>  wrote:
>>>
>>> aaron.ballman added a comment.
>>>
>>> In https://reviews.llvm.org/D33788#771671, @bruno wrote:
>>>
>>> > > I'm unaware of any other API that canonicalizes the path, which is
>>> > > what users of this API are going to expect.
>>> >
>>> > You can also call `sys::path::remove_dots(Path,
>>> > /*remove_dot_dot=*/true);`
>>>
>>>
>>> Yes, but that does not canonicalize the path. For instance, it won't
>>> handle doubled-up slashes or symlinks.
>>
>>
>> That's at least partly a feature, not a bug. Resolving symlinks and
>> removing x/.. are both potentially breaking changes when applied to the path
>> -- if you canonicalize, you break installations where the file is actually a
>> symlink to a file that does *not* also have a resource directory relative to
>> it.
>>
>> The path with the bin/../lib in it is presumably the path from the clang
>> binary, not the path from libclang,
>
>
> I'm not sure about this any more. Looks like clang::Driver::Driver applies
> parent_path to the .../bin directory instead of adding a .. component. So
> maybe the bin/../lib path comes from how the dynamic loader finds the
> libclang.so file relative to c-index-test?

What we're finding is that the path we get back from dladdr() in
getClangResourcesPath() is what contains the "..", so I think you're
correct.

> In any case, adding canonicalization in just one of the places where we
> compute the resource path will break this test for anyone who has symlinks
> elsewhere in the path (then the paths will differ because the symlinks are
> resolved in the libclang path but not in the clang binary path). And
> canonicalization everywhere will break existing clang installations that
> rely on the symlinks *not* being resolved. I think we need to find another
> option.

I can probably switch to just removing the dots to get the test case
to stop failing, but as you point out below, this is a bit of a mess.
:-D

~Aaron

>
>> so it's not clear to me that this patch would even help -- the clang
>> driver also does not canonicalize the path (see SetInstallDir in
>> tools/driver/driver.cpp).
>
>
> ... but if you run -cc1 directly rather than from the clang driver, we
> instead make a call that does use getMainExecutable(). What a mess.
>
>>> Ultimately, the value returned from this API gets passed to POSIX
>>> functions which expect a canonical path. I don't think `remove_dots()` is
>>> sufficient. It should do the same thing as `getMainExecutable()`, I believe.
>>
>>
>> Note that we don't actually use getMainExecutable for the main clang
>> driver, just for tooling purposes, and it *also* does not canonicalize.
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D34002: [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

2017-06-08 Thread Aaron Ballman via cfe-commits
On Thu, Jun 8, 2017 at 6:24 PM, Alexander Kornienko via Phabricator
 wrote:
> alexfh added a comment.
>
> In https://reviews.llvm.org/D34002#776193, @chh wrote:
>
>> In https://reviews.llvm.org/D34002#775830, @alexfh wrote:
>>
>> > IIUC, when `vector` (for a class `T` that has both move and copy 
>> > constructors) resizes, it will prefer move constructors, but only if 
>> > they're declared `noexcept`.  This is true even if `-fno-exceptions` is 
>> > on. So I don't think this check should depend on `-fno-exceptions`.
>>
>>
>> Should the compiler assume `noexcept` when -fno-exceptions is on?
>>  That means move constructors should be preferred under -fno-exceptions, and 
>> this check would be unnecessary, right?
>
>
> The compiler doesn't assume `noexcept` and I heard from competent people the 
> reasons why it shouldn't, though I can't immediately recall these reasons. I 
> think, the patch should be reverted.

Yes, in light of this, I agree.

~Aaron

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


r305385 - Corrected some comment typos; NFC.

2017-06-14 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Jun 14 07:48:18 2017
New Revision: 305385

URL: http://llvm.org/viewvc/llvm-project?rev=305385&view=rev
Log:
Corrected some comment typos; NFC.

Modified:
cfe/trunk/include/clang/Frontend/FrontendOptions.h

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=305385&r1=305384&r2=305385&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Wed Jun 14 07:48:18 2017
@@ -317,8 +317,8 @@ public:
   /// \brief Auxiliary triple for CUDA compilation.
   std::string AuxTriple;
 
-  /// \brief If non-empty, search the pch input file as it was a header
-  // included by this file.
+  /// \brief If non-empty, search the pch input file as if it was a header
+  /// included by this file.
   std::string FindPchSource;
 
   /// Filename to write statistics to.


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


r305432 - Handle -ast-dump-all when passed as the only option.

2017-06-14 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Jun 14 19:00:08 2017
New Revision: 305432

URL: http://llvm.org/viewvc/llvm-project?rev=305432&view=rev
Log:
Handle -ast-dump-all when passed as the only option.

Patch by Don Hinton

Modified:
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/test/Coverage/ast-printing.c
cfe/trunk/test/Coverage/ast-printing.cpp

Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=305432&r1=305431&r2=305432&view=diff
==
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Wed Jun 14 19:00:08 2017
@@ -142,7 +142,7 @@ std::unique_ptr clang::Crea
 bool DumpDecls,
 bool Deserialize,
 bool DumpLookups) {
-  assert((DumpDecls || DumpLookups) && "nothing to dump");
+  assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump");
   return llvm::make_unique(nullptr,
Deserialize ? ASTPrinter::DumpFull :
DumpDecls ? ASTPrinter::Dump :

Modified: cfe/trunk/test/Coverage/ast-printing.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/ast-printing.c?rev=305432&r1=305431&r2=305432&view=diff
==
--- cfe/trunk/test/Coverage/ast-printing.c (original)
+++ cfe/trunk/test/Coverage/ast-printing.c Wed Jun 14 19:00:08 2017
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -ast-print %t.1.c -o %t.2.c
 // RUN: diff %t.1.c %t.2.c
 // RUN: %clang_cc1 -ast-dump %s
+// RUN: %clang_cc1 -ast-dump-all %s
 // RUN: %clang_cc1 -print-decl-contexts %s
 
 #include "c-language-features.inc"

Modified: cfe/trunk/test/Coverage/ast-printing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/ast-printing.cpp?rev=305432&r1=305431&r2=305432&view=diff
==
--- cfe/trunk/test/Coverage/ast-printing.cpp (original)
+++ cfe/trunk/test/Coverage/ast-printing.cpp Wed Jun 14 19:00:08 2017
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -std=c++14 -ast-print %t.1.cpp -o %t.2.cpp
 // RUN: diff %t.1.cpp %t.2.cpp
 // RUN: %clang_cc1 -std=c++14 -ast-dump %s
+// RUN: %clang_cc1 -std=c++14 -ast-dump-all %s
 // RUN: %clang_cc1 -std=c++14 -print-decl-contexts %s
 // RUN: %clang_cc1 -std=c++14 -fdump-record-layouts %s
 


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


r305586 - Killing a tab and some other spurious whitespace; NFC.

2017-06-16 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Jun 16 15:52:59 2017
New Revision: 305586

URL: http://llvm.org/viewvc/llvm-project?rev=305586&view=rev
Log:
Killing a tab and some other spurious whitespace; NFC.

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

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=305586&r1=305585&r2=305586&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Fri Jun 16 15:52:59 2017
@@ -517,7 +517,7 @@ void PrintPreprocessedAction::ExecuteAct
 // file.  This is mostly a sanity check in case the file has no 
 // newlines whatsoever.
 if (end - cur > 256) end = cur + 256;
- 
+
 while (next < end) {
   if (*cur == 0x0D) {  // CR
 if (*next == 0x0A)  // CRLF


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


r305738 - Typo fix: appropo -> apropos. NFC.

2017-06-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Mon Jun 19 15:08:20 2017
New Revision: 305738

URL: http://llvm.org/viewvc/llvm-project?rev=305738&view=rev
Log:
Typo fix: appropo -> apropos. NFC.

Modified:
cfe/trunk/docs/Block-ABI-Apple.rst

Modified: cfe/trunk/docs/Block-ABI-Apple.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Block-ABI-Apple.rst?rev=305738&r1=305737&r2=305738&view=diff
==
--- cfe/trunk/docs/Block-ABI-Apple.rst (original)
+++ cfe/trunk/docs/Block-ABI-Apple.rst Mon Jun 19 15:08:20 2017
@@ -856,15 +856,15 @@ mentioned above, call:
 
 .. code-block:: c
 
- _Block_object_assign(&dst->target, src->target, BLOCK_FIELD_);
+ _Block_object_assign(&dst->target, src->target, BLOCK_FIELD_);
 
 in the copy helper and:
 
 .. code-block:: c
 
-_Block_object_dispose(->target, BLOCK_FIELD_);
+_Block_object_dispose(->target, BLOCK_FIELD_);
 
-in the dispose helper where  is:
+in the dispose helper where  is:
 
 .. code-block:: c
 
@@ -888,7 +888,7 @@ and functions are generated in the same
 Under ObjC we allow ``__weak`` as an attribute on ``__block`` variables, and
 this causes the addition of ``BLOCK_FIELD_IS_WEAK`` orred onto the
 ``BLOCK_FIELD_IS_BYREF`` flag when copying the ``block_byref`` structure in the
-``Block`` copy helper, and onto the ``BLOCK_FIELD_`` field within the
+``Block`` copy helper, and onto the ``BLOCK_FIELD_`` field within the
 ``block_byref`` copy/dispose helper calls.
 
 The prototypes, and summary, of the helper functions are:


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


Re: r320697 - Warn if we find a Unicode homoglyph for a symbol in an identifier.

2017-12-14 Thread Aaron Ballman via cfe-commits
On Thu, Dec 14, 2017 at 8:15 AM, Richard Smith via cfe-commits
 wrote:
> Author: rsmith
> Date: Thu Dec 14 05:15:08 2017
> New Revision: 320697
>
> URL: http://llvm.org/viewvc/llvm-project?rev=320697&view=rev
> Log:
> Warn if we find a Unicode homoglyph for a symbol in an identifier.
>
> Specifically, warn if:
>  * we find a character that the language standard says we must treat as an
>identifier, and
>  * that character is not reasonably an identifier character (it's a 
> punctuation
>character or similar), and
>  * it renders identically to a valid non-identifier character in common
>fixed-width fonts.
>
> Some tools "helpfully" substitute the surprising characters for the expected
> characters, and replacing semicolons with Greek question marks is a common
> "prank".
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
> cfe/trunk/lib/Lex/Lexer.cpp
> cfe/trunk/test/Lexer/unicode.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=320697&r1=320696&r2=320697&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Thu Dec 14 05:15:08 
> 2017
> @@ -119,6 +119,9 @@ def err_non_ascii : Error<
>  def ext_unicode_whitespace : ExtWarn<
>"treating Unicode character as whitespace">,
>InGroup>;
> +def warn_utf8_symbol_homoglyph : Warning<
> +  "treating Unicode character  as identifier character rather than "
> +  "as '%1' symbol">, InGroup>;

Can this wording be tweaked slightly to "as an identifier character"
or does that cause too much of an "a/an" problem with "as %1 symbol"?

~Aaron

>
>  def err_hex_escape_no_digits : Error<
>"\\%0 used with no following hex digits">;
>
> Modified: cfe/trunk/lib/Lex/Lexer.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=320697&r1=320696&r2=320697&view=diff
> ==
> --- cfe/trunk/lib/Lex/Lexer.cpp (original)
> +++ cfe/trunk/lib/Lex/Lexer.cpp Thu Dec 14 05:15:08 2017
> @@ -37,6 +37,7 @@
>  #include "llvm/Support/ConvertUTF.h"
>  #include "llvm/Support/MathExtras.h"
>  #include "llvm/Support/MemoryBuffer.h"
> +#include "llvm/Support/NativeFormatting.h"
>  #include "llvm/Support/UnicodeCharRanges.h"
>  #include 
>  #include 
> @@ -1500,6 +1501,75 @@ static void maybeDiagnoseIDCharCompat(Di
>}
>  }
>
> +/// After encountering UTF-8 character C and interpreting it as an identifier
> +/// character, check whether it's a homoglyph for a common non-identifier
> +/// source character that is unlikely to be an intentional identifier
> +/// character and warn if so.
> +static void maybeDiagnoseUTF8Homoglyph(DiagnosticsEngine &Diags, uint32_t C,
> +   CharSourceRange Range) {
> +  // FIXME: Handle Unicode quotation marks (smart quotes, fullwidth quotes).
> +  struct HomoglyphPair {
> +uint32_t Character;
> +char LooksLike;
> +bool operator<(HomoglyphPair R) const { return Character < R.Character; }
> +  };
> +  static constexpr HomoglyphPair SortedHomoglyphs[] = {
> +{U'\u01c3', '!'}, // LATIN LETTER RETROFLEX CLICK
> +{U'\u037e', ';'}, // GREEK QUESTION MARK
> +{U'\u2212', '-'}, // MINUS SIGN
> +{U'\u2215', '/'}, // DIVISION SLASH
> +{U'\u2216', '\\'}, // SET MINUS
> +{U'\u2217', '*'}, // ASTERISK OPERATOR
> +{U'\u2223', '|'}, // DIVIDES
> +{U'\u2227', '^'}, // LOGICAL AND
> +{U'\u2236', ':'}, // RATIO
> +{U'\u223c', '~'}, // TILDE OPERATOR
> +{U'\ua789', ':'}, // MODIFIER LETTER COLON
> +{U'\uff01', '!'}, // FULLWIDTH EXCLAMATION MARK
> +{U'\uff03', '#'}, // FULLWIDTH NUMBER SIGN
> +{U'\uff04', '$'}, // FULLWIDTH DOLLAR SIGN
> +{U'\uff05', '%'}, // FULLWIDTH PERCENT SIGN
> +{U'\uff06', '&'}, // FULLWIDTH AMPERSAND
> +{U'\uff08', '('}, // FULLWIDTH LEFT PARENTHESIS
> +{U'\uff09', ')'}, // FULLWIDTH RIGHT PARENTHESIS
> +{U'\uff0a', '*'}, // FULLWIDTH ASTERISK
> +{U'\uff0b', '+'}, // FULLWIDTH ASTERISK
> +{U'\uff0c', ','}, // FULLWIDTH COMMA
> +{U'\uff0d', '-'}, // FULLWIDTH HYPHEN-MINUS
> +{U'\uff0e', '.'}, // FULLWIDTH FULL STOP
> +{U'\uff0f', '/'}, // FULLWIDTH SOLIDUS
> +{U'\uff1a', ':'}, // FULLWIDTH COLON
> +{U'\uff1b', ';'}, // FULLWIDTH SEMICOLON
> +{U'\uff1c', '<'}, // FULLWIDTH LESS-THAN SIGN
> +{U'\uff1d', '='}, // FULLWIDTH EQUALS SIGN
> +{U'\uff1e', '>'}, // FULLWIDTH GREATER-THAN SIGN
> +{U'\uff1f', '?'}, // FULLWIDTH QUESTION MARK
> +{U'\uff20', '@'}, // FULLWIDTH COMMERCIAL AT
> +{U'\uff3b', '['}, // FULLWIDTH LEFT SQUARE BRACKET
> +{U'\uff3c', '\\'}, // FULLWIDTH REVERSE SOLIDUS
> +{U'\uff3d', ']'}, // FULLWIDTH RIGHT SQUARE BRACKET
> +{U'\uff3e', '^'}, 

[clang-tools-extra] r320713 - Add support for NOLINT and NOLINTNEXTLINE comments mentioning specific check names.

2017-12-14 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Dec 14 08:13:57 2017
New Revision: 320713

URL: http://llvm.org/viewvc/llvm-project?rev=320713&view=rev
Log:
Add support for NOLINT and NOLINTNEXTLINE comments mentioning specific check 
names.

Supports a comma-separated list of check names to be disabled on the given 
line. Also supports * as a wildcard to disable all lint diagnostic messages on 
that line.

Patch by Anton (xgsa).

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/index.rst
clang-tools-extra/trunk/test/clang-tidy/nolint.cpp
clang-tools-extra/trunk/test/clang-tidy/nolintnextline.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=320713&r1=320712&r2=320713&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Thu Dec 
14 08:13:57 2017
@@ -21,6 +21,7 @@
 #include "clang/AST/ASTDiagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include 
 #include 
@@ -290,7 +291,38 @@ void ClangTidyDiagnosticConsumer::finali
   LastErrorPassesLineFilter = false;
 }
 
-static bool LineIsMarkedWithNOLINT(SourceManager &SM, SourceLocation Loc) {
+static bool IsNOLINTFound(StringRef NolintDirectiveText, StringRef Line,
+  unsigned DiagID, const ClangTidyContext &Context) {
+  const size_t NolintIndex = Line.find(NolintDirectiveText);
+  if (NolintIndex == StringRef::npos)
+return false;
+
+  size_t BracketIndex = NolintIndex + NolintDirectiveText.size();
+  // Check if the specific checks are specified in brackets.
+  if (BracketIndex < Line.size() && Line[BracketIndex] == '(') {
+++BracketIndex;
+const size_t BracketEndIndex = Line.find(')', BracketIndex);
+if (BracketEndIndex != StringRef::npos) {
+  StringRef ChecksStr =
+  Line.substr(BracketIndex, BracketEndIndex - BracketIndex);
+  // Allow disabling all the checks with "*".
+  if (ChecksStr != "*") {
+StringRef CheckName = Context.getCheckName(DiagID);
+// Allow specifying a few check names, delimited with comma.
+SmallVector Checks;
+ChecksStr.split(Checks, ',', -1, false);
+llvm::transform(Checks, Checks.begin(),
+[](StringRef S) { return S.trim(); });
+return llvm::find(Checks, CheckName) != Checks.end();
+  }
+}
+  }
+  return true;
+}
+
+static bool LineIsMarkedWithNOLINT(SourceManager &SM, SourceLocation Loc,
+   unsigned DiagID,
+   const ClangTidyContext &Context) {
   bool Invalid;
   const char *CharacterData = SM.getCharacterData(Loc, &Invalid);
   if (Invalid)
@@ -301,8 +333,7 @@ static bool LineIsMarkedWithNOLINT(Sourc
   while (*P != '\0' && *P != '\r' && *P != '\n')
 ++P;
   StringRef RestOfLine(CharacterData, P - CharacterData + 1);
-  // FIXME: Handle /\bNOLINT\b(\([^)]*\))?/ as cpplint.py does.
-  if (RestOfLine.find("NOLINT") != StringRef::npos)
+  if (IsNOLINTFound("NOLINT", RestOfLine, DiagID, Context))
 return true;
 
   // Check if there's a NOLINTNEXTLINE on the previous line.
@@ -329,16 +360,17 @@ static bool LineIsMarkedWithNOLINT(Sourc
 --P;
 
   RestOfLine = StringRef(P, LineEnd - P + 1);
-  if (RestOfLine.find("NOLINTNEXTLINE") != StringRef::npos)
+  if (IsNOLINTFound("NOLINTNEXTLINE", RestOfLine, DiagID, Context))
 return true;
 
   return false;
 }
 
-static bool LineIsMarkedWithNOLINTinMacro(SourceManager &SM,
-  SourceLocation Loc) {
+static bool LineIsMarkedWithNOLINTinMacro(SourceManager &SM, SourceLocation 
Loc,
+  unsigned DiagID,
+  const ClangTidyContext &Context) {
   while (true) {
-if (LineIsMarkedWithNOLINT(SM, Loc))
+if (LineIsMarkedWithNOLINT(SM, Loc, DiagID, Context))
   return true;
 if (!Loc.isMacroID())
   return false;
@@ -355,7 +387,8 @@ void ClangTidyDiagnosticConsumer::Handle
   if (Info.getLocation().isValid() && DiagLevel != DiagnosticsEngine::Error &&
   DiagLevel != DiagnosticsEngine::Fatal &&
   LineIsMarkedWithNOLINTinMacro(Diags->getSourceManager(),
-Info.getLocation())) {
+Info.getLocation(), Info.getID(),
+Context)) {
 ++Context.Stats.ErrorsIgnoredNOLINT;
 // Ignored a warning, should ignore related notes as well
 LastErrorWasIgnored = true;

Modified: cla

r320752 - Harmonize GNU- and C++-style attribute spellings.

2017-12-14 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Dec 14 14:17:09 2017
New Revision: 320752

URL: http://llvm.org/viewvc/llvm-project?rev=320752&view=rev
Log:
Harmonize GNU- and C++-style attribute spellings.

Most attributes will now use the Clang<"name"> construct to provide both 
__attribute__((name)) and [[clang::name]] syntaxes for the attribute. 
Attributes deviating from this should be marked with a comment explaining why 
they are not supported under both spellings. Common reasons are: the attribute 
is provided by some other specification that controls the syntax or the 
attribute cannot be exposed under a particular spelling for some given reason.

Because this is a mechanical change that only introduces new spellings, there 
are no test cases for the commit.

Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/include/clang/Basic/Attr.td

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=320752&r1=320751&r2=320752&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Thu Dec 14 14:17:09 2017
@@ -149,6 +149,12 @@ Clang now supports the ...
 Attribute Changes in Clang
 --
 
+- Clang now supports the majority of its attributes under both the GNU-style
+  spelling (``__attribute((name))``) and the double square-bracket spelling
+  in the ``clang`` vendor namespace (``[[clang::name]]``). Attributes whose
+  syntax is specified by some other standard (such as CUDA and OpenCL
+  attributes) continue to follow their respective specification.
+  
 - Added the ``__has_c_attribute()`` builtin preprocessor macro which allows
   users to dynamically detect whether a double square-bracket attribute is
   supported in C mode. This attribute syntax can be enabled with the

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=320752&r1=320751&r2=320752&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Dec 14 14:17:09 2017
@@ -513,7 +513,7 @@ def AbiTag : Attr {
 }
 
 def AddressSpace : TypeAttr {
-  let Spellings = [GNU<"address_space">];
+  let Spellings = [Clang<"address_space">];
   let Args = [IntArgument<"AddressSpace">];
   let Documentation = [Undocumented];
 }
@@ -545,6 +545,9 @@ def AlignValue : Attr {
 // the future (and a corresponding C++ attribute), but this can be done
 // later once we decide if we also want them to have slightly-different
 // semantics than Intel's align_value.
+// 
+// Does not get a [[]] spelling because the attribute is not exposed as 
such
+// by Intel.
 GNU<"align_value">
 // Intel's compiler on Windows also supports:
 // , Declspec<"align_value">
@@ -593,12 +596,15 @@ def TLSModel : InheritableAttr {
 }
 
 def AnalyzerNoReturn : InheritableAttr {
+  // TODO: should this attribute be exposed with a [[]] spelling under the 
clang
+  // vendor namespace, or should it use a vendor namespace specific to the
+  // analyzer?
   let Spellings = [GNU<"analyzer_noreturn">];
   let Documentation = [Undocumented];
 }
 
 def Annotate : InheritableParamAttr {
-  let Spellings = [GNU<"annotate">];
+  let Spellings = [Clang<"annotate">];
   let Args = [StringArgument<"Annotation">];
   // Ensure that the annotate attribute can be used with
   // '#pragma clang attribute' even though it has no subject list.
@@ -640,6 +646,8 @@ def AsmLabel : InheritableAttr {
 }
 
 def Availability : InheritableAttr {
+  // TODO: does not have a [[]] spelling because it requires custom parsing
+  // support.
   let Spellings = [GNU<"availability">];
   let Args = [IdentifierArgument<"platform">, VersionArgument<"introduced">,
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
@@ -700,12 +708,13 @@ def ExternalSourceSymbol : InheritableAt
 }
 
 def Blocks : InheritableAttr {
-  let Spellings = [GNU<"blocks">];
+  let Spellings = [Clang<"blocks">];
   let Args = [EnumArgument<"Type", "BlockType", ["byref"], ["ByRef"]>];
   let Documentation = [Undocumented];
 }
 
 def Bounded : IgnoredAttr {
+  // Does not have a [[]] spelling because the attribute is ignored.
   let Spellings = [GNU<"bounded">];
 }
 
@@ -727,7 +736,7 @@ def CDecl : InheritableAttr {
 // cf_returns_retained attributes.  It is generally applied by
 // '#pragma clang arc_cf_code_audited' rather than explicitly.
 def CFAuditedTransfer : InheritableAttr {
-  let Spellings = [GNU<"cf_audited_transfer">];
+  let Spellings = [Clang<"cf_audited_transfer">];
   let Subjects = SubjectList<[Function], ErrorDiag>;
   let Documentation = [Undocumented];
 }
@@ -736,25 +745,25 @@ def CFAuditedTransfer : InheritableAttr
 // It indicates that the function has unknown or unautomatable
 // t

r321228 - Silence a -Wreorder warning from r321223.

2017-12-20 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Dec 20 15:11:05 2017
New Revision: 321228

URL: http://llvm.org/viewvc/llvm-project?rev=321228&view=rev
Log:
Silence a -Wreorder warning from r321223.

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=321228&r1=321227&r2=321228&view=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Wed Dec 20 15:11:05 2017
@@ -219,8 +219,8 @@ namespace  {
 ASTDumper(raw_ostream &OS, const CommandTraits *Traits,
   const SourceManager *SM, bool ShowColors,
   const PrintingPolicy &PrintPolicy)
-: OS(OS), Traits(Traits), SM(SM), ShowColors(ShowColors),
-  PrintPolicy(PrintPolicy) {}
+: OS(OS), Traits(Traits), SM(SM), PrintPolicy(PrintPolicy),
+  ShowColors(ShowColors) {}
 
 void setDeserialize(bool D) { Deserialize = D; }
 


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


r321237 - Reverting a file that snuck in with r321229 by accident.

2017-12-20 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Dec 20 17:34:46 2017
New Revision: 321237

URL: http://llvm.org/viewvc/llvm-project?rev=321237&view=rev
Log:
Reverting a file that snuck in with r321229 by accident.

Modified:
cfe/trunk/test/Misc/ast-dump-color.cpp

Modified: cfe/trunk/test/Misc/ast-dump-color.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/ast-dump-color.cpp?rev=321237&r1=321236&r2=321237&view=diff
==
--- cfe/trunk/test/Misc/ast-dump-color.cpp (original)
+++ cfe/trunk/test/Misc/ast-dump-color.cpp Wed Dec 20 17:34:46 2017
@@ -43,7 +43,7 @@ struct Invalid {
 //CHECK: {{^}}[[Blue]]| 
|-[[RESET]][[Blue]]HTMLEndTagComment[[RESET]][[Yellow]] 
0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:13[[RESET]], 
[[Yellow]]col:16[[RESET]]> Name="a"{{$}}
 //CHECK: {{^}}[[Blue]]| |-[[RESET]][[Blue]]TextComment[[RESET]][[Yellow]] 
0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:5:4[[RESET]]> Text=" "{{$}}
 //CHECK: {{^}}[[Blue]]| 
`-[[RESET]][[Blue]]HTMLStartTagComment[[RESET]][[Yellow]] 
0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:5[[RESET]], 
[[Yellow]]col:8[[RESET]]> Name="br" SelfClosing{{$}}
-//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]FunctionDecl[[RESET]][[Yellow]] 
0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:9:1[[RESET]], 
[[Yellow]]line:16:1[[RESET]]> [[Yellow]]line:9:6[[RESET]][[CYAN]] 
TestAttributedStmt[[RESET]] [[Green]]'void ()'[[RESET]]{{$}}
+//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]FunctionDecl[[RESET]][[Yellow]] 
0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:9:1[[RESET]], 
[[Yellow]]line:16:1[[RESET]]> [[Yellow]]line:9:6[[RESET]][[CYAN]] 
TestAttributedStmt[[RESET]] [[Green]]'void (void)'[[RESET]]{{$}}
 //CHECK: {{^}}[[Blue]]| 
|-[[RESET]][[MAGENTA:.\[0;1;35m]]CompoundStmt[[RESET]][[Yellow]] 
0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:27[[RESET]], 
[[Yellow]]line:16:1[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| | `-[[RESET]][[MAGENTA]]SwitchStmt[[RESET]][[Yellow]] 
0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:10:3[[RESET]], 
[[Yellow]]line:15:3[[RESET]]>{{$}}
 //CHECK: {{^}}[[Blue]]| |   
|-[[RESET]][[Blue:.\[0;34m]]<<>>[[RESET]]{{$}}


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


Re: [clang-tools-extra] r321363 - [clang-tidy] Adding Fuchsia checker for overloaded operators

2017-12-22 Thread Aaron Ballman via cfe-commits
On Fri, Dec 22, 2017 at 11:52 AM, Julie Hockett via cfe-commits
 wrote:
> Author: juliehockett
> Date: Fri Dec 22 08:52:25 2017
> New Revision: 321363
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321363&view=rev
> Log:
> [clang-tidy] Adding Fuchsia checker for overloaded operators
>
> Adds a check to the Fuchsia module to warn if an operator is overloaded,
> except move and copy operators.
>
> See https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md for
> reference.
>
> Differential Revision: https://reviews.llvm.org/D41363
>
> Added:
> clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
> 
> clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
> clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
> Modified:
> clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
> clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
> clang-tools-extra/trunk/docs/ReleaseNotes.rst
> clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
>
> Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt?rev=321363&r1=321362&r2=321363&view=diff
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt (original)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt Fri Dec 22 
> 08:52:25 2017
> @@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
>  add_clang_library(clangTidyFuchsiaModule
>DefaultArgumentsCheck.cpp
>FuchsiaTidyModule.cpp
> +  OverloadedOperatorCheck.cpp
>VirtualInheritanceCheck.cpp
>
>LINK_LIBS
>
> Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp?rev=321363&r1=321362&r2=321363&view=diff
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp 
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp Fri Dec 
> 22 08:52:25 2017
> @@ -11,6 +11,7 @@
>  #include "../ClangTidyModule.h"
>  #include "../ClangTidyModuleRegistry.h"
>  #include "DefaultArgumentsCheck.h"
> +#include "OverloadedOperatorCheck.h"
>  #include "VirtualInheritanceCheck.h"
>
>  using namespace clang::ast_matchers;
> @@ -25,6 +26,8 @@ public:
>void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
>  CheckFactories.registerCheck(
>  "fuchsia-default-arguments");
> +CheckFactories.registerCheck(
> +"fuchsia-overloaded-operator");
>  CheckFactories.registerCheck(
>  "fuchsia-virtual-inheritance");
>}
>
> Added: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp?rev=321363&view=auto
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp 
> (added)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp 
> Fri Dec 22 08:52:25 2017
> @@ -0,0 +1,39 @@
> +//===--- OverloadedOperatorCheck.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 "OverloadedOperatorCheck.h"
> +
> +using namespace clang::ast_matchers;
> +
> +namespace clang {
> +namespace tidy {
> +namespace fuchsia {
> +
> +AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
> +  if (const auto *CXXMethodNode = dyn_cast(&Node)) {
> +if (CXXMethodNode->isCopyAssignmentOperator() ||
> +CXXMethodNode->isMoveAssignmentOperator())
> +  return false;
> +  }
> +  return Node.isOverloadedOperator();
> +}
> +
> +void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
> +  
> Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
> + this);
> +}
> +
> +void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
> +  if (const auto *D = Result.Nodes.getNodeAs("decl"))
> +diag(D->getLocStart(), "cannot overload %0") << D;
> +}
> +
> +} // namespace fuchsia
> +} // namespace tidy
> +} // namespace clang
>
> Added: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h?rev=321363&view=auto
> =

Re: [PATCH] D41512: [Sema] -Wtautological-constant-compare is too good. Cripple it.

2017-12-24 Thread Aaron Ballman via cfe-commits
On Sun, Dec 24, 2017 at 11:45 AM, Dimitry Andric via Phabricator
 wrote:
> dim added a comment.
>
> Actually, having thought about it a little more, if the warning is "rather 
> broken", or even "completely broken", depending on one's point of view, then 
> maybe it is better not have it under `-Wextra` either?  E.g. somebody has to 
> ask for the warning specifically, using `-Wtautological-constant-compare`, or 
> use `-Weverything`?
>
> I ask this, because in FreeBSD we have traditionally been using `-W`, which 
> is (again, historically) an alias for `-Wextra`.  We now still have to 
> explicitly use `-Wno-tautological-constant-compare` everywhere. :-(

I think having it under -Wextra is reasonable -- I don't think it's
rather/completely broken, I think it's more strict at diagnosing
issues than some people would like to see by default (which can be a
subjective measure).

If we're talking about removing it from -Wextra such that you have to
enable it by name only, I'd say it should be removed entirely (at
least temporarily) -- "no one" enables diagnostics by name (and very
few use -Weverything) and it increases our maintenance burden to carry
around a feature no one will use.

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


Re: [clang-tools-extra] r321762 - [clang-tidy] Update fuchsia-overloaded-operator to check for valid loc

2018-01-03 Thread Aaron Ballman via cfe-commits
Hans, I'd like to nominate this patch for the 6.0 branch. It fixes a
failing assertion with new functionality; without this fix, anyone
enabling this check and including a STL header that transitively
includes  (which is most of them) will hit the assertion.

Thanks!

~Aaron

On Wed, Jan 3, 2018 at 5:10 PM, Julie Hockett via cfe-commits
 wrote:
> Author: juliehockett
> Date: Wed Jan  3 14:10:11 2018
> New Revision: 321762
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321762&view=rev
> Log:
> [clang-tidy] Update fuchsia-overloaded-operator to check for valid loc
>
> Updating fuchsia-overloaded-operator check to not issue warnings for
> invalid locations.
>
> Fixes PR35803.
>
> Differential Revision: https://reviews.llvm.org/D41708
>
> Modified:
> clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
>
> Modified: 
> clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp?rev=321762&r1=321761&r2=321762&view=diff
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp 
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp 
> Wed Jan  3 14:10:11 2018
> @@ -30,8 +30,12 @@ void OverloadedOperatorCheck::registerMa
>  }
>
>  void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
> -  if (const auto *D = Result.Nodes.getNodeAs("decl"))
> -diag(D->getLocStart(), "cannot overload %0") << D;
> +  const auto *D = Result.Nodes.getNodeAs("decl");
> +  assert(D && "No FunctionDecl captured!");
> +
> +  SourceLocation Loc = D->getLocStart();
> +  if (Loc.isValid())
> +diag(Loc, "cannot overload %0") << D;
>  }
>
>  } // namespace fuchsia
>
> Modified: 
> clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp?rev=321762&r1=321761&r2=321762&view=diff
> ==
> --- clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp 
> (original)
> +++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp 
> Wed Jan  3 14:10:11 2018
> @@ -16,3 +16,6 @@ public:
>
>  A operator-(const A &A1, const A &A2);
>  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: cannot overload 'operator-' 
> [fuchsia-overloaded-operator]
> +
> +void operator delete(void*, void*) throw();
> +// CHECK-MESSAGES: [[@LINE-1]]:1: warning: cannot overload 'operator delete' 
> [fuchsia-overloaded-operator]
>
>
> ___
> 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


r321763 - Introduce some infrastructure for adding C attributes with [[]] syntax.

2018-01-03 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Jan  3 14:22:48 2018
New Revision: 321763

URL: http://llvm.org/viewvc/llvm-project?rev=321763&view=rev
Log:
Introduce some infrastructure for adding C attributes with [[]] syntax.

This patch adds support to the attribute tablegen for specifying a [[]] 
attribute is allowed in C mode. This patch also adds the annotate attribute to 
the list of double square bracket attributes we support in C mode.

Eventually, I anticipate that this logic will be reversed (you have to opt out 
of allowing an attribute in C rather than opting in), but I want to see how the 
design plays out as more attributes are considered.

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/test/Sema/annotate.c
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=321763&r1=321762&r2=321763&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Jan  3 14:22:48 2018
@@ -231,9 +231,12 @@ class GCC : Spelling and CXX11<"clang", name>. This spelling
-// should be used for any Clang-specific attributes.
-class Clang : Spelling;
+// The Clang spelling implies GNU, CXX11<"clang", name>, and optionally,
+// C2x<"clang", name>. This spelling should be used for any Clang-specific
+// attributes.
+class Clang : Spelling {
+  bit AllowInC = allowInC;
+}
 
 class Accessor spellings> {
   string Name = name;
@@ -618,7 +621,7 @@ def AnalyzerNoReturn : InheritableAttr {
 }
 
 def Annotate : InheritableParamAttr {
-  let Spellings = [Clang<"annotate">];
+  let Spellings = [Clang<"annotate", 1>];
   let Args = [StringArgument<"Annotation">];
   // Ensure that the annotate attribute can be used with
   // '#pragma clang attribute' even though it has no subject list.

Modified: cfe/trunk/test/Sema/annotate.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/annotate.c?rev=321763&r1=321762&r2=321763&view=diff
==
--- cfe/trunk/test/Sema/annotate.c (original)
+++ cfe/trunk/test/Sema/annotate.c Wed Jan  3 14:22:48 2018
@@ -1,9 +1,13 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -fdouble-square-bracket-attributes -verify
 
 void __attribute__((annotate("foo"))) foo(float *a) {
   __attribute__((annotate("bar"))) int x;
+  [[clang::annotate("bar")]] int x2;
   __attribute__((annotate(1))) int y; // expected-error {{'annotate' attribute 
requires a string}}
+  [[clang::annotate(1)]] int y2; // expected-error {{'annotate' attribute 
requires a string}}
   __attribute__((annotate("bar", 1))) int z; // expected-error {{'annotate' 
attribute takes one argument}}
+  [[clang::annotate("bar", 1)]] int z2; // expected-error {{'annotate' 
attribute takes one argument}}
+
   int u = __builtin_annotation(z, (char*) 0); // expected-error {{second 
argument to __builtin_annotation must be a non-wide string constant}}
   int v = __builtin_annotation(z, (char*) L"bar"); // expected-error {{second 
argument to __builtin_annotation must be a non-wide string constant}}
   int w = __builtin_annotation(z, "foo");

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=321763&r1=321762&r2=321763&view=diff
==
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Wed Jan  3 14:22:48 2018
@@ -87,6 +87,8 @@ GetFlattenedSpellings(const Record &Attr
 } else if (Variety == "Clang") {
   Ret.emplace_back("GNU", Name, "", false);
   Ret.emplace_back("CXX11", Name, "clang", false);
+  if (Spelling->getValueAsBit("AllowInC"))
+Ret.emplace_back("C2x", Name, "clang", false);
 } else
   Ret.push_back(FlattenedSpelling(*Spelling));
   }


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


r322074 - Track in the AST whether the operand to a UnaryOperator can overflow and then use that logic when evaluating constant expressions and emitting codegen.

2018-01-09 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Jan  9 05:07:03 2018
New Revision: 322074

URL: http://llvm.org/viewvc/llvm-project?rev=322074&view=rev
Log:
Track in the AST whether the operand to a UnaryOperator can overflow and then 
use that logic when evaluating constant expressions and emitting codegen.

Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Analysis/BodyFarm.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Frontend/Rewrite/RewriteModernObjC.cpp
cfe/trunk/lib/Frontend/Rewrite/RewriteObjC.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/Misc/ast-dump-stmt.c

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=322074&r1=322073&r2=322074&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Jan  9 05:07:03 2018
@@ -1720,19 +1720,19 @@ public:
 
 private:
   unsigned Opc : 5;
+  unsigned CanOverflow : 1;
   SourceLocation Loc;
   Stmt *Val;
 public:
-
-  UnaryOperator(Expr *input, Opcode opc, QualType type,
-ExprValueKind VK, ExprObjectKind OK, SourceLocation l)
-: Expr(UnaryOperatorClass, type, VK, OK,
-   input->isTypeDependent() || type->isDependentType(),
-   input->isValueDependent(),
-   (input->isInstantiationDependent() ||
-type->isInstantiationDependentType()),
-   input->containsUnexpandedParameterPack()),
-  Opc(opc), Loc(l), Val(input) {}
+  UnaryOperator(Expr *input, Opcode opc, QualType type, ExprValueKind VK,
+ExprObjectKind OK, SourceLocation l, bool CanOverflow)
+  : Expr(UnaryOperatorClass, type, VK, OK,
+ input->isTypeDependent() || type->isDependentType(),
+ input->isValueDependent(),
+ (input->isInstantiationDependent() ||
+  type->isInstantiationDependentType()),
+ input->containsUnexpandedParameterPack()),
+Opc(opc), CanOverflow(CanOverflow), Loc(l), Val(input) {}
 
   /// \brief Build an empty unary operator.
   explicit UnaryOperator(EmptyShell Empty)
@@ -1748,6 +1748,15 @@ public:
   SourceLocation getOperatorLoc() const { return Loc; }
   void setOperatorLoc(SourceLocation L) { Loc = L; }
 
+  /// Returns true if the unary operator can cause an overflow. For instance,
+  ///   signed int i = INT_MAX; i++;
+  ///   signed char c = CHAR_MAX; c++;
+  /// Due to integer promotions, c++ is promoted to an int before the postfix
+  /// increment, and the result is an int that cannot overflow. However, i++
+  /// can overflow.
+  bool canOverflow() const { return CanOverflow; }
+  void setCanOverflow(bool C) { CanOverflow = C; }
+
   /// isPostfix - Return true if this is a postfix operation, like x++.
   static bool isPostfix(Opcode Op) {
 return Op == UO_PostInc || Op == UO_PostDec;

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=322074&r1=322073&r2=322074&view=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jan  9 05:07:03 2018
@@ -2214,12 +2214,14 @@ void ASTDumper::VisitArrayInitIndexExpr(
 }
 
 void ASTDumper::VisitUnaryOperator(const UnaryOperator *Node) {
-  VisitExpr(Node);
-  OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
- << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
-}
-
-void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
+  VisitExpr(Node);
+  OS << " " << (Node->isPostfix() ? "postfix" : "prefix")
+ << " '" << UnaryOperator::getOpcodeStr(Node->getOpcode()) << "'";
+  if (!Node->canOverflow())
+OS << " cannot overflow";
+}
+
+void ASTDumper::VisitUnaryExprOrTypeTraitExpr(
 const UnaryExprOrTypeTraitExpr *Node) {
   VisitExpr(Node);
   switch(Node->getKind()) {

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=322074&r1=322073&r2=322074&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Jan  9 05:07:03 2018
@@ -5120,14 +5120,13 @@ Expr *ASTNodeImporter::VisitUnaryOperato
   if (!SubExpr)
 return nullptr;
 
-  return new (Importer.getToContext()) UnaryOperator(SubExpr, E->getOpcode(),
- 

r326266 - Improve the way attribute argument printing happens for omitted optional arguments when pretty printing.

2018-02-27 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Feb 27 15:49:28 2018
New Revision: 326266

URL: http://llvm.org/viewvc/llvm-project?rev=326266&view=rev
Log:
Improve the way attribute argument printing happens for omitted optional 
arguments when pretty printing.

Patch by Joel Denny.

Added:
cfe/trunk/test/Sema/attr-print.cpp
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/test/Sema/attr-print.c
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326266&r1=326265&r2=326266&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Feb 27 15:49:28 2018
@@ -1506,8 +1506,8 @@ def ObjCBridgeRelated : InheritableAttr
   let Spellings = [Clang<"objc_bridge_related">];
   let Subjects = SubjectList<[Record], ErrorDiag>;
   let Args = [IdentifierArgument<"RelatedClass">,
-  IdentifierArgument<"ClassMethod", 1>,
-  IdentifierArgument<"InstanceMethod", 1>];
+  IdentifierArgument<"ClassMethod">,
+  IdentifierArgument<"InstanceMethod">];
   let HasCustomParsing = 1;
   let Documentation = [Undocumented];
 }

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=326266&r1=326265&r2=326266&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue Feb 27 15:49:28 2018
@@ -1258,7 +1258,9 @@ void Parser::ParseObjCBridgeRelatedAttri
 return;
   }
 
-  // Parse optional class method name.
+  // Parse class method name.  It's non-optional in the sense that a trailing
+  // comma is required, but it can be the empty string, and then we record a
+  // nullptr.
   IdentifierLoc *ClassMethod = nullptr;
   if (Tok.is(tok::identifier)) {
 ClassMethod = ParseIdentifierLoc();
@@ -1277,7 +1279,8 @@ void Parser::ParseObjCBridgeRelatedAttri
 return;
   }
   
-  // Parse optional instance method name.
+  // Parse instance method name.  Also non-optional but empty string is
+  // permitted.
   IdentifierLoc *InstanceMethod = nullptr;
   if (Tok.is(tok::identifier))
 InstanceMethod = ParseIdentifierLoc();

Modified: cfe/trunk/test/Sema/attr-print.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-print.c?rev=326266&r1=326265&r2=326266&view=diff
==
--- cfe/trunk/test/Sema/attr-print.c (original)
+++ cfe/trunk/test/Sema/attr-print.c Tue Feb 27 15:49:28 2018
@@ -7,6 +7,9 @@ int x __attribute__((aligned(4)));
 // CHECK: int y __declspec(align(4));
 __declspec(align(4)) int y;
 
+// CHECK: short arr[3] __attribute__((aligned));
+short arr[3] __attribute__((aligned));
+
 // CHECK: void foo() __attribute__((const));
 void foo() __attribute__((const));
 

Added: cfe/trunk/test/Sema/attr-print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-print.cpp?rev=326266&view=auto
==
--- cfe/trunk/test/Sema/attr-print.cpp (added)
+++ cfe/trunk/test/Sema/attr-print.cpp Tue Feb 27 15:49:28 2018
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -ast-print | FileCheck %s
+
+// CHECK: void *as2(int, int) __attribute__((alloc_size(1, 2)));
+void *as2(int, int) __attribute__((alloc_size(1, 2)));
+// CHECK: void *as1(void *, int) __attribute__((alloc_size(2)));
+void *as1(void *, int) __attribute__((alloc_size(2)));

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=326266&r1=326265&r2=326266&view=diff
==
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Tue Feb 27 15:49:28 2018
@@ -231,6 +231,7 @@ namespace {
 virtual void writePCHReadArgs(raw_ostream &OS) const = 0;
 virtual void writePCHReadDecls(raw_ostream &OS) const = 0;
 virtual void writePCHWrite(raw_ostream &OS) const = 0;
+virtual std::string getIsOmitted() const { return "false"; }
 virtual void writeValue(raw_ostream &OS) const = 0;
 virtual void writeDump(raw_ostream &OS) const = 0;
 virtual void writeDumpChildren(raw_ostream &OS) const {}
@@ -298,23 +299,28 @@ namespace {
std::string(getUpperName()) + "()");
 }
 
+std::string getIsOmitted() const override {
+  if (type == "IdentifierInfo *")
+return "!get" + getUpperName().str() + "()";
+  // FIXME: Do this declaratively in Attr.td.
+  if (getAttrName() == "AllocSize")
+return "0 == get" + getUpperName().

Re: r326542 - [Frontend] Avoid including default system header paths on Fuchsia

2018-03-02 Thread Aaron Ballman via cfe-commits
On Fri, Mar 2, 2018 at 2:19 AM, Petr Hosek via cfe-commits
 wrote:
> Author: phosek
> Date: Thu Mar  1 23:19:42 2018
> New Revision: 326542
>
> URL: http://llvm.org/viewvc/llvm-project?rev=326542&view=rev
> Log:
> [Frontend] Avoid including default system header paths on Fuchsia
>
> These paths aren't used and don't make sense on Fuchsia.
>
> Differential Revision: https://reviews.llvm.org/D43992
>
> Modified:
> cfe/trunk/lib/Frontend/InitHeaderSearch.cpp

Please add test cases to verify the behavior and help ensure we don't
regress it later.

~Aaron

>
> Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=326542&r1=326541&r2=326542&view=diff
> ==
> --- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
> +++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Thu Mar  1 23:19:42 2018
> @@ -216,6 +216,7 @@ void InitHeaderSearch::AddDefaultCInclud
>  case llvm::Triple::NaCl:
>  case llvm::Triple::PS4:
>  case llvm::Triple::ELFIAMCU:
> +case llvm::Triple::Fuchsia:
>break;
>  case llvm::Triple::Win32:
>if (triple.getEnvironment() != llvm::Triple::Cygnus)
> @@ -322,6 +323,7 @@ void InitHeaderSearch::AddDefaultCInclud
>case llvm::Triple::RTEMS:
>case llvm::Triple::NaCl:
>case llvm::Triple::ELFIAMCU:
> +  case llvm::Triple::Fuchsia:
>  break;
>case llvm::Triple::PS4: {
>  //  gets prepended later in AddPath().
>
>
> ___
> 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


r326604 - Fix the hasType() AST matcher to not assert when the QualType is invalid.

2018-03-02 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Mar  2 11:14:21 2018
New Revision: 326604

URL: http://llvm.org/viewvc/llvm-project?rev=326604&view=rev
Log:
Fix the hasType() AST matcher to not assert when the QualType is invalid.

There's not a particularly good way to test this with the AST matchers unit 
tests because the only way to get an invalid type (that I can devise) involves 
creating parse errors, which the test harness always treats as a failure. 
Instead, a clang-tidy test case will be added in a follow-up commit based on 
the original bug report.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=326604&r1=326603&r2=326604&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Mar  2 11:14:21 2018
@@ -2843,8 +2843,10 @@ AST_MATCHER_P_OVERLOAD(CallExpr, callee,
 AST_POLYMORPHIC_MATCHER_P_OVERLOAD(
 hasType, AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, TypedefNameDecl, ValueDecl),
 internal::Matcher, InnerMatcher, 0) {
-  return InnerMatcher.matches(internal::getUnderlyingType(Node),
-  Finder, Builder);
+  QualType QT = internal::getUnderlyingType(Node);
+  if (!QT.isNull())
+return InnerMatcher.matches(QT, Finder, Builder);
+  return false;
 }
 
 /// \brief Overloaded to match the declaration of the expression's or value


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


[clang-tools-extra] r326605 - Adds a clang-tidy test for a failing assertion in the misc-misplaced-const check.

2018-03-02 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Mar  2 11:14:34 2018
New Revision: 326605

URL: http://llvm.org/viewvc/llvm-project?rev=326605&view=rev
Log:
Adds a clang-tidy test for a failing assertion in the misc-misplaced-const 
check.

The test case previously triggered an assertion in the AST matchers because the 
QualType being matched is invalid. That is no longer the case after r326604.

Added:
clang-tools-extra/trunk/test/clang-tidy/misc-misplaced-const-cxx17.cpp

Added: clang-tools-extra/trunk/test/clang-tidy/misc-misplaced-const-cxx17.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-misplaced-const-cxx17.cpp?rev=326605&view=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-misplaced-const-cxx17.cpp 
(added)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-misplaced-const-cxx17.cpp Fri 
Mar  2 11:14:34 2018
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s misc-misplaced-const %t -- -- -std=c++17
+
+// This test previously would cause a failed assertion because the structured
+// binding declaration had no valid type associated with it. This ensures the
+// expected clang diagnostic is generated instead.
+// CHECK-MESSAGES: :[[@LINE+1]]:6: error: decomposition declaration '[x]' 
requires an initializer [clang-diagnostic-error]
+auto [x];
+
+struct S { int a; };
+S f();
+
+int main() {
+  auto [x] = f();
+}
+


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


  1   2   3   4   5   6   7   8   9   10   >