[PATCH] D73520: [analyzer] BugReporterVisitors: Refactor and documentation

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 248110.
Charusso marked 4 inline comments as done.
Charusso added a comment.
Herald added subscribers: martong, steakhal.

- Make the tags robust and more unique.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73520/new/

https://reviews.llvm.org/D73520

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp

Index: clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Version.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
 #include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -238,8 +239,9 @@
 // FIXME: What should be reported here?
 break;
   case PathDiagnosticPiece::Event:
-return Piece.getTagStr() == "ConditionBRVisitor" ? Importance::Important
- : Importance::Essential;
+return Piece.getTag() == ConditionBRVisitor::getTag()
+   ? Importance::Important
+   : Importance::Essential;
   case PathDiagnosticPiece::ControlFlow:
 return Importance::Unimportant;
   }
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1,15 +1,10 @@
-//===- BugReporterVisitors.cpp - Helpers for reporting bugs ---===//
+//===- BugReporterVisitors.cpp - Bug explaining and suppression -*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===--===//
-//
-//  This file defines a set of BugReporter "visitors" which can be used to
-//  enhance the diagnostics reported for a bug.
-//
-//===--===//
 
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
 #include "clang/AST/ASTContext.h"
@@ -82,18 +77,6 @@
   return nullptr;
 }
 
-/// Given that expression S represents a pointer that would be dereferenced,
-/// try to find a sub-expression from which the pointer came from.
-/// This is used for tracking down origins of a null or undefined value:
-/// "this is null because that is null because that is null" etc.
-/// We wipe away field and element offsets because they merely add offsets.
-/// We also wipe away all casts except lvalue-to-rvalue casts, because the
-/// latter represent an actual pointer dereference; however, we remove
-/// the final lvalue-to-rvalue cast before returning from this function
-/// because it demonstrates more clearly from where the pointer rvalue was
-/// loaded. Examples:
-///   x->y.z  ==>  x (lvalue)
-///   foo()->y.z  ==>  foo() (rvalue)
 const Expr *bugreporter::getDerefExpr(const Stmt *S) {
   const auto *E = dyn_cast(S);
   if (!E)
@@ -362,21 +345,17 @@
 SM(MmrMgr.getContext().getSourceManager()),
 PP(MmrMgr.getContext().getPrintingPolicy()), TKind(TKind) {}
 
-  void Profile(llvm::FoldingSetNodeID ) const override {
-static int Tag = 0;
-ID.AddPointer();
-ID.AddPointer(RegionOfInterest);
-  }
-
-  void *getTag() const {
-static int Tag = 0;
-return static_cast();
-  }
-
   PathDiagnosticPieceRef VisitNode(const ExplodedNode *N,
BugReporterContext ,
PathSensitiveBugReport ) override;
 
+  static const char *getTag() { return "NoStoreFuncVisitor"; }
+
+  void Profile(llvm::FoldingSetNodeID ) const override {
+ID.AddPointer(getTag());
+ID.AddPointer(RegionOfInterest);
+  }
+
 private:
   /// Attempts to find the region of interest in a given record decl,
   /// by either following the base classes or fields.
@@ -837,10 +816,7 @@
   R->getAs(), V));
   }
 
-  void* getTag() const {
-static int Tag = 0;
-return static_cast();
-  }
+  static const char *getTag() { return "MacroNullReturnSuppressionVisitor"; }
 
   void Profile(llvm::FoldingSetNodeID ) const override {
 ID.AddPointer(getTag());
@@ -903,13 +879,10 @@
   : CalleeSFC(Frame), EnableNullFPSuppression(Suppressed),
 Options(Options), TKind(TKind) {}
 
-  static void *getTag() {
-static int Tag = 0;
-return static_cast();
-  }
+  static const char *getTag() { return 

[PATCH] D75461: Ignore macro expansions when scanning for fallthrough comments

2020-03-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

fallthrough comment detection has been reverted, so abandon this in the 
meantime.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75461/new/

https://reviews.llvm.org/D75461



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


[PATCH] D73520: [analyzer] BugReporterVisitors: Refactor and documentation

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h:44
 
-/// BugReporterVisitors are used to add custom diagnostics along a path.
+/// BugReporterVisitors are used to add custom diagnostics along a \emoji bug
+/// path. They also could serve false positive suppression.

Szelethus wrote:
> I suspect `\emoji` wasn't intentional here, given that it needs another 
> argument :^)
Well, it is "So Pro" (- Apple) and I really like that. Someone wrote "along a 
path", but we are definitely mentioning the  path.
{F11475626}


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73520/new/

https://reviews.llvm.org/D73520



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


[PATCH] D73729: [analyzer] AnalyzerOptions: Remove 'fixits-as-remarks'

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

[Achievement unlocked] 3 green marks.

Thanks!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73729/new/

https://reviews.llvm.org/D73729



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


[PATCH] D73519: [analyzer] AnalysisDeclContext: Refactor and documentation

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7e1a6ca9e89c: [analyzer] AnalysisDeclContext: Refactor and 
documentation (authored by Charusso).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73519/new/

https://reviews.llvm.org/D73519

Files:
  clang/include/clang/Analysis/AnalysisDeclContext.h
  clang/lib/Analysis/AnalysisDeclContext.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -842,8 +842,7 @@
 return SFC;
 }
 if (const auto *BC = dyn_cast(LC)) {
-  const auto *BR =
-  static_cast(BC->getContextData());
+  const auto *BR = static_cast(BC->getData());
   // FIXME: This can be made more efficient.
   for (BlockDataRegion::referenced_vars_iterator
I = BR->referenced_vars_begin(),
Index: clang/lib/Analysis/AnalysisDeclContext.cpp
===
--- clang/lib/Analysis/AnalysisDeclContext.cpp
+++ clang/lib/Analysis/AnalysisDeclContext.cpp
@@ -52,16 +52,16 @@
 
 using ManagedAnalysisMap = llvm::DenseMap;
 
-AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
- const Decl *d,
- const CFG::BuildOptions )
-: Manager(Mgr), D(d), cfgBuildOptions(buildOptions) {
+AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *ADCMgr,
+ const Decl *D,
+ const CFG::BuildOptions )
+: ADCMgr(ADCMgr), D(D), cfgBuildOptions(Options) {
   cfgBuildOptions.forcedBlkExprs = 
 }
 
-AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
- const Decl *d)
-: Manager(Mgr), D(d) {
+AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *ADCMgr,
+ const Decl *D)
+: ADCMgr(ADCMgr), D(D) {
   cfgBuildOptions.forcedBlkExprs = 
 }
 
@@ -96,8 +96,8 @@
 Stmt *Body = FD->getBody();
 if (auto *CoroBody = dyn_cast_or_null(Body))
   Body = CoroBody->getBody();
-if (Manager && Manager->synthesizeBodies()) {
-  Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(FD);
+if (ADCMgr && ADCMgr->synthesizeBodies()) {
+  Stmt *SynthesizedBody = ADCMgr->getBodyFarm().getBody(FD);
   if (SynthesizedBody) {
 Body = SynthesizedBody;
 IsAutosynthesized = true;
@@ -107,8 +107,8 @@
   }
   else if (const auto *MD = dyn_cast(D)) {
 Stmt *Body = MD->getBody();
-if (Manager && Manager->synthesizeBodies()) {
-  Stmt *SynthesizedBody = Manager->getBodyFarm().getBody(MD);
+if (ADCMgr && ADCMgr->synthesizeBodies()) {
+  Stmt *SynthesizedBody = ADCMgr->getBodyFarm().getBody(MD);
   if (SynthesizedBody) {
 Body = SynthesizedBody;
 IsAutosynthesized = true;
@@ -309,19 +309,17 @@
 BodyFarm ::getBodyFarm() { return FunctionBodyFarm; }
 
 const StackFrameContext *
-AnalysisDeclContext::getStackFrame(LocationContext const *Parent, const Stmt *S,
-   const CFGBlock *Blk, unsigned BlockCount,
-   unsigned Idx) {
-  return getLocationContextManager().getStackFrame(this, Parent, S, Blk,
-   BlockCount, Idx);
+AnalysisDeclContext::getStackFrame(const LocationContext *ParentLC,
+   const Stmt *S, const CFGBlock *Blk,
+   unsigned BlockCount, unsigned Index) {
+  return getLocationContextManager().getStackFrame(this, ParentLC, S, Blk,
+   BlockCount, Index);
 }
 
-const BlockInvocationContext *
-AnalysisDeclContext::getBlockInvocationContext(const LocationContext *parent,
-   const BlockDecl *BD,
-   const void *ContextData) {
-  return getLocationContextManager().getBlockInvocationContext(this, parent,
-   BD, ContextData);
+const BlockInvocationContext *AnalysisDeclContext::getBlockInvocationContext(
+const LocationContext *ParentLC, const BlockDecl *BD, const void *Data) {
+  return getLocationContextManager().getBlockInvocationContext(this, ParentLC,
+   BD, Data);
 }
 
 bool AnalysisDeclContext::isInStdNamespace(const Decl *D) {
@@ -340,9 +338,10 @@
 }
 
 LocationContextManager ::getLocationContextManager() {
-  assert(Manager &&
- "Cannot create LocationContexts without an 

[PATCH] D73729: [analyzer] AnalyzerOptions: Remove 'fixits-as-remarks'

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGabdd33c86a34: [analyzer] AnalyzerOptions: Remove 
fixits-as-remarks (authored by Charusso).

Changed prior to commit:
  https://reviews.llvm.org/D73729?vs=241507=248106#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73729/new/

https://reviews.llvm.org/D73729

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/dead-stores.c
  clang/test/Analysis/virtualcall-fixit.cpp
  clang/test/Analysis/virtualcall-fixits.cpp

Index: clang/test/Analysis/virtualcall-fixits.cpp
===
--- clang/test/Analysis/virtualcall-fixits.cpp
+++ clang/test/Analysis/virtualcall-fixits.cpp
@@ -1,10 +1,11 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.VirtualCall \
 // RUN: -analyzer-config optin.cplusplus.VirtualCall:ShowFixIts=true \
 // RUN: %s 2>&1 | FileCheck -check-prefix=TEXT %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,optin.cplusplus.VirtualCall \
+
+// RUN: %check_analyzer_fixit %s %t \
+// RUN: -analyzer-checker=core,optin.cplusplus.VirtualCall \
 // RUN: -analyzer-config optin.cplusplus.VirtualCall:ShowFixIts=true \
-// RUN: -analyzer-config fixits-as-remarks=true \
-// RUN: -analyzer-output=plist -o %t.plist -verify %s
+// RUN: -analyzer-output=plist -o %t.plist
 // RUN: cat %t.plist | FileCheck -check-prefix=PLIST %s
 
 struct S {
@@ -12,7 +13,9 @@
   S() {
 foo();
 // expected-warning@-1{{Call to virtual method 'S::foo' during construction bypasses virtual dispatch}}
-// expected-remark@-2{{5-5: 'S::'}}
+// CHECK-FIXES:  S() {
+// CHECK-FIXES-NEXT:   S::foo();
+// CHECK-FIXES-NEXT: }
   }
   ~S();
 };
@@ -30,12 +33,12 @@
 // PLIST-NEXT:remove_range
 // PLIST-NEXT:
 // PLIST-NEXT: 
-// PLIST-NEXT:  line13
+// PLIST-NEXT:  line14
 // PLIST-NEXT:  col5
 // PLIST-NEXT:  file0
 // PLIST-NEXT: 
 // PLIST-NEXT: 
-// PLIST-NEXT:  line13
+// PLIST-NEXT:  line14
 // PLIST-NEXT:  col4
 // PLIST-NEXT:  file0
 // PLIST-NEXT: 
Index: clang/test/Analysis/virtualcall-fixit.cpp
===
--- clang/test/Analysis/virtualcall-fixit.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-// RUN: %check_analyzer_fixit %s %t \
-// RUN:   -analyzer-checker=core,optin.cplusplus.VirtualCall \
-// RUN:   -analyzer-config optin.cplusplus.VirtualCall:ShowFixIts=true
-
-struct S {
-  virtual void foo();
-  S() {
-foo();
-// expected-warning@-1 {{Call to virtual method 'S::foo' during construction bypasses virtual dispatch}}
-// CHECK-FIXES: S::foo();
-  }
-  ~S();
-};
Index: clang/test/Analysis/dead-stores.c
===
--- clang/test/Analysis/dead-stores.c
+++ clang/test/Analysis/dead-stores.c
@@ -1,16 +1,16 @@
-// RUN: %clang_analyze_cc1 -Wunused-variable -fblocks -Wno-unreachable-code \
+// RUN: %check_analyzer_fixit %s %t \
+// RUN:   -Wunused-variable -fblocks -Wno-unreachable-code \
 // RUN:   -analyzer-checker=core,deadcode.DeadStores \
 // RUN:   -analyzer-config deadcode.DeadStores:ShowFixIts=true \
-// RUN:   -analyzer-config fixits-as-remarks=true \
 // RUN:   -analyzer-config \
 // RUN:   deadcode.DeadStores:WarnForDeadNestedAssignments=false \
-// RUN:   -verify=non-nested %s
+// RUN:   -verify=non-nested
 
-// RUN: %clang_analyze_cc1 -Wunused-variable -fblocks -Wno-unreachable-code \
+// RUN: %check_analyzer_fixit %s %t \
+// RUN:   -Wunused-variable -fblocks -Wno-unreachable-code \
 // RUN:   -analyzer-checker=core,deadcode.DeadStores \
 // RUN:   -analyzer-config deadcode.DeadStores:ShowFixIts=true \
-// RUN:   -analyzer-config fixits-as-remarks=true \
-// RUN:   -verify=non-nested,nested %s
+// RUN:   -verify=non-nested,nested
 
 void f1() {
   int k, y; // non-nested-warning {{unused variable 'k'}}
@@ -18,14 +18,17 @@
   int abc = 1;
   long idx = abc + 3 * 5; // non-nested-warning {{never read}}
   // non-nested-warning@-1 {{unused variable 'idx'}}
-  // non-nested-remark@-2 {{11-24: ''}}
+  // CHECK-FIXES:  int abc = 1;
+  // CHECK-FIXES-NEXT: long idx;
 }
 
 void f2(void *b) {
   char *c = (char *)b; // no-warning
   char *d = b + 1; // non-nested-warning {{never read}}
// non-nested-warning@-1 {{unused variable 'd'}}
-   // non-nested-remark@-2 {{10-17: ''}}
+  // CHECK-FIXES:  char *c = (char *)b;
+  // CHECK-FIXES-NEXT: char *d;
+
   printf("%s", c);
   // non-nested-warning@-1 {{implicitly declaring library function 'printf' with type 'int (const char *, ...)'}}
   // non-nested-note@-2 {{include the header  or explicitly provide a 

[clang] 7e1a6ca - [analyzer] AnalysisDeclContext: Refactor and documentation

2020-03-03 Thread via cfe-commits

Author: Charusso
Date: 2020-03-04T07:06:54+01:00
New Revision: 7e1a6ca9e89c3ea08f8b008e9140d9fdc048d1df

URL: 
https://github.com/llvm/llvm-project/commit/7e1a6ca9e89c3ea08f8b008e9140d9fdc048d1df
DIFF: 
https://github.com/llvm/llvm-project/commit/7e1a6ca9e89c3ea08f8b008e9140d9fdc048d1df.diff

LOG: [analyzer] AnalysisDeclContext: Refactor and documentation

Summary:
`ScopeContext` wanted to be a thing, but sadly it is dead code.

If you wish to continue the work in D19979, here was a tiny code which
could be reused, but that tiny and that dead, I felt that it is unneded.

Note: Other changes are truly uninteresting.

Reviewed By: NoQ

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

Added: 


Modified: 
clang/include/clang/Analysis/AnalysisDeclContext.h
clang/lib/Analysis/AnalysisDeclContext.cpp
clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/AnalysisDeclContext.h 
b/clang/include/clang/Analysis/AnalysisDeclContext.h
index 9faa78cde89c..ed554feedead 100644
--- a/clang/include/clang/Analysis/AnalysisDeclContext.h
+++ b/clang/include/clang/Analysis/AnalysisDeclContext.h
@@ -1,4 +1,4 @@
-// AnalysisDeclContext.h - Analysis context for Path Sens analysis -*- C++ 
-*-//
+//===- AnalysisDeclContext.h - Context for path sensitivity -*- C++ 
-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,11 @@
 //
 
//===--===//
 //
-// This file defines AnalysisDeclContext, a class that manages the analysis
-// context data for path sensitive analysis.
+/// \file
+/// This file defines AnalysisDeclContext, a class that manages the analysis
+/// context data for context sensitive and path sensitive analysis.
+/// It also defines the helper classes to model entering, leaving or inlining
+/// function calls.
 //
 
//===--===//
 
@@ -64,14 +67,14 @@ class ManagedAnalysis {
   // which creates the analysis object given an AnalysisDeclContext.
 };
 
-/// AnalysisDeclContext contains the context data for the function or method
-/// under analysis.
+/// AnalysisDeclContext contains the context data for the function, method
+/// or block under analysis.
 class AnalysisDeclContext {
-  /// Backpoint to the AnalysisManager object that created this
-  /// AnalysisDeclContext. This may be null.
-  AnalysisDeclContextManager *Manager;
+  // Backpoint to the AnalysisManager object that created this
+  // AnalysisDeclContext. This may be null.
+  AnalysisDeclContextManager *ADCMgr;
 
-  const Decl * const D;
+  const Decl *const D;
 
   std::unique_ptr cfg, completeCFG;
   std::unique_ptr cfgStmtMap;
@@ -86,45 +89,36 @@ class AnalysisDeclContext {
 
   llvm::BumpPtrAllocator A;
 
-  llvm::DenseMap *ReferencedBlockVars = nullptr;
+  llvm::DenseMap *ReferencedBlockVars = nullptr;
 
   void *ManagedAnalyses = nullptr;
 
 public:
-  AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
-  const Decl *D);
+  AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *D);
 
-  AnalysisDeclContext(AnalysisDeclContextManager *Mgr,
-  const Decl *D,
-  const CFG::BuildOptions );
+  AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *D,
+  const CFG::BuildOptions );
 
   ~AnalysisDeclContext();
 
   ASTContext () const { return D->getASTContext(); }
+
   const Decl *getDecl() const { return D; }
 
-  /// Return the AnalysisDeclContextManager (if any) that created
-  /// this AnalysisDeclContext.
-  AnalysisDeclContextManager *getManager() const {
-return Manager;
-  }
+  AnalysisDeclContextManager *getManager() const { return ADCMgr; }
 
-  /// Return the build options used to construct the CFG.
-  CFG::BuildOptions () {
-return cfgBuildOptions;
-  }
+  CFG::BuildOptions () { return cfgBuildOptions; }
 
   const CFG::BuildOptions () const {
 return cfgBuildOptions;
   }
 
-  /// getAddEHEdges - Return true iff we are adding exceptional edges from
-  /// callExprs.  If this is false, then try/catch statements and blocks
-  /// reachable from them can appear to be dead in the CFG, analysis passes 
must
-  /// cope with that.
+  /// \returns Whether we are adding exception handling edges from CallExprs.
+  /// If this is false, then try/catch statements and blocks reachable from 
them
+  /// can appear to be dead in the CFG, analysis passes must cope with that.
   bool getAddEHEdges() const { return cfgBuildOptions.AddEHEdges; }
   bool getUseUnoptimizedCFG() const {
-  return !cfgBuildOptions.PruneTriviallyFalseEdges;
+return !cfgBuildOptions.PruneTriviallyFalseEdges;
   }
   bool getAddImplicitDtors() const { return 

Buildbot numbers for the week of 02/23/2020 - 02/29/2020

2020-03-03 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the last week of 02/23/2020 -
02/29/2020.

Please see the same data in attached csv files:

The longest time each builder was red during the week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the week:
   buildername   | was_red
-+-
 aosp-O3-polly-before-vectorizer-unprofitable| 89:58:22
 libcxx-libcxxabi-libunwind-armv7-linux-noexceptions | 61:06:00
 libcxx-libcxxabi-libunwind-armv7-linux  | 61:04:33
 libcxx-libcxxabi-x86_64-linux-ubuntu-ubsan  | 60:56:50
 libcxx-libcxxabi-x86_64-linux-ubuntu-32bit  | 60:52:47
 libcxx-libcxxabi-libunwind-armv8-linux-noexceptions | 60:28:36
 libcxx-libcxxabi-libunwind-armv8-linux  | 60:27:54
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx14  | 56:13:47
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx11  | 56:09:19
 sanitizer-x86_64-linux-fast | 31:37:30
 sanitizer-x86_64-linux-bootstrap-msan   | 29:58:56
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx03  | 24:47:20
 libcxx-libcxxabi-x86_64-linux-ubuntu-gcc5-cxx11 | 24:44:43
 clang-x64-windows-msvc  | 22:39:08
 clang-cmake-aarch64-full| 20:39:13
 llvm-clang-win-x-aarch64| 17:30:50
 sanitizer-x86_64-linux-bootstrap| 16:16:19
 libcxx-libcxxabi-libunwind-x86_64-linux-debian  | 16:00:09
 fuchsia-x86_64-linux| 15:16:59
 sanitizer-x86_64-linux-bootstrap-ubsan  | 14:08:28
 clang-with-lto-ubuntu   | 13:10:47
 clang-with-thin-lto-ubuntu  | 12:36:07
 openmp-clang-x86_64-linux-debian| 06:35:09
 clang-ppc64le-linux-multistage  | 05:08:16
 ppc64le-lld-multistage-test | 04:53:00
 openmp-gcc-x86_64-linux-debian  | 04:36:36
 libcxx-libcxxabi-x86_64-linux-debian| 04:30:32
 clang-cmake-x86_64-avx2-linux   | 04:02:58
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast| 03:58:44
 llvm-clang-x86_64-expensive-checks-ubuntu   | 03:54:01
 lld-x86_64-ubuntu-fast  | 03:53:52
 llvm-clang-win-x-armv7l | 03:53:52
 lld-x86_64-win7 | 03:50:22
 clang-cmake-x86_64-sde-avx512-linux | 03:49:00
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast  | 03:44:46
 clang-ppc64le-rhel  | 03:33:04
 clang-hexagon-elf   | 03:30:18
 lldb-aarch64-ubuntu | 03:26:20
 sanitizer-ppc64be-linux | 03:12:48
 sanitizer-x86_64-linux-android  | 03:03:44
 llvm-clang-x86_64-expensive-checks-win  | 03:03:19
 clang-ppc64le-linux | 02:54:50
 clang-atom-d525-fedora-rel  | 02:54:26
 sanitizer-x86_64-linux  | 02:43:19
 clang-ppc64le-linux-lnt | 02:13:23
 clang-ppc64be-linux-lnt | 02:11:41
 clang-s390x-linux   | 02:00:57
 llvm-clang-x86_64-win-fast  | 01:56:29
 clang-ppc64be-linux | 01:49:49
 clang-ppc64be-linux-multistage  | 01:46:58
 reverse-iteration   | 01:45:08
 lldb-x64-windows-ninja  | 01:43:23
 clang-cuda-build| 01:25:33
 clang-cmake-armv7-lnt   | 01:21:57
 libcxx-libcxxabi-x86_64-linux-ubuntu-gcc-tot-latest-std | 01:15:27
 libcxx-libcxxabi-x86_64-linux-ubuntu-msan   | 01:14:47
 lldb-x86_64-debian  | 01:13:43
 clang-x86_64-debian-fast| 01:07:48
 libcxx-libcxxabi-x86_64-linux-ubuntu-cxx2a  | 01:06:53
 libcxx-libcxxabi-x86_64-linux-ubuntu-asan   | 01:03:05
 libcxx-libcxxabi-x86_64-linux-debian-noexceptions   | 01:02:16
 libcxx-libcxxabi-singlethreaded-x86_64-linux-debian | 01:00:49
 

Buildbot numbers for the week of 02/16/2020 - 02/22/2020

2020-03-03 Thread Galina Kistanova via cfe-commits
Hello everyone,

Below are some buildbot numbers for the week of 02/16/2020 - 02/22/2020.

Please see the same data in attached csv files:

The longest time each builder was red during the week;
"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green);
Count of commits by project;
Number of completed builds, failed builds and average build time for
successful builds per active builder;
Average waiting time for a revision to get build result per active builder
(response time).

Thanks

Galina


The longest time each builder was red during the week:
   buildername|  was_red
--+--
 clang-native-arm-lnt-perf| 103:24:11
 clang-cmake-aarch64-full | 56:56:23
 llvm-clang-x86_64-expensive-checks-win   | 44:55:56
 clang-s390x-linux-lnt| 37:24:45
 clang-with-thin-lto-ubuntu   | 35:46:45
 clang-ppc64be-linux  | 27:58:33
 sanitizer-x86_64-linux-bootstrap | 27:26:52
 sanitizer-x86_64-linux-fast  | 25:52:39
 lldb-aarch64-ubuntu  | 25:34:05
 clang-with-lto-ubuntu| 25:20:22
 clang-s390x-linux| 23:01:12
 clang-ppc64be-linux-multistage   | 22:57:48
 clang-ppc64be-linux-lnt  | 22:54:50
 ppc64le-lld-multistage-test  | 21:26:12
 llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast   | 21:20:01
 clang-cmake-x86_64-avx2-linux| 21:18:52
 clang-atom-d525-fedora-rel   | 21:16:58
 clang-ppc64le-linux  | 21:10:17
 clang-cmake-x86_64-sde-avx512-linux  | 21:02:00
 llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast | 20:58:43
 clang-ppc64le-linux-multistage   | 20:43:45
 clang-cmake-armv7-lnt| 20:32:17
 sanitizer-x86_64-linux-bootstrap-ubsan   | 19:41:41
 clang-s390x-linux-multistage | 18:57:25
 clang-x64-windows-msvc   | 09:55:15
 llvm-clang-win-x-armv7l  | 09:49:03
 fuchsia-x86_64-linux | 09:47:38
 llvm-clang-win-x-aarch64 | 09:45:10
 lldb-x64-windows-ninja   | 09:00:44
 libc-x86_64-debian-asan  | 06:52:21
 libc-x86_64-debian   | 06:51:23
 clang-x86_64-debian-new-pass-manager-fast| 06:06:14
 clang-ppc64le-linux-lnt  | 05:53:57
 clang-ppc64le-rhel   | 05:49:29
 lld-x86_64-darwin13  | 05:29:22
 polly-arm-linux  | 04:50:21
 sanitizer-ppc64le-linux  | 04:46:45
 sanitizer-x86_64-linux-bootstrap-msan| 04:37:39
 llvm-clang-x86_64-expensive-checks-debian| 04:35:22
 sanitizer-x86_64-linux   | 04:15:06
 lld-x86_64-win7  | 04:10:26
 lld-x86_64-ubuntu-fast   | 04:07:49
 llvm-clang-x86_64-expensive-checks-ubuntu| 04:00:38
 clang-x86_64-debian-fast | 03:45:15
 openmp-gcc-x86_64-linux-debian   | 03:40:36
 clang-cuda-build | 03:35:06
 sanitizer-ppc64be-linux  | 03:19:42
 lldb-x86_64-debian   | 03:03:58
 reverse-iteration| 03:01:01
 clang-hexagon-elf| 01:45:31
 openmp-clang-x86_64-linux-debian | 01:40:03
 sanitizer-x86_64-linux-fuzzer| 01:11:15
 sanitizer-x86_64-linux-android   | 01:07:54
 sanitizer-x86_64-linux-autoconf  | 01:03:52
 clang-aarch64-linux-build-cache  | 01:00:37
 clang-x86_64-linux-abi-test  | 00:58:48
 sanitizer-windows| 00:57:00
 clang-armv7-linux-build-cache| 00:55:47
 llvm-clang-x86_64-win-fast   | 00:55:27
 mlir-nvidia  | 00:21:37
(60 rows)


"Status change ratio" by active builder (percent of builds that changed the
builder status from greed to red or from red to green):
   buildername   | builds | changes
| status_change_ratio
-++-+
 llvm-clang-x86_64-expensive-checks-debian   |342 |  84
|24.6
 sanitizer-x86_64-linux  | 99 |  24
|24.2
 clang-x86_64-debian-new-pass-manager-fast 

[clang] abdd33c - [analyzer] AnalyzerOptions: Remove 'fixits-as-remarks'

2020-03-03 Thread via cfe-commits

Author: Charusso
Date: 2020-03-04T06:56:32+01:00
New Revision: abdd33c86a34517bbbe91adcacaae1ed5ea6b1d8

URL: 
https://github.com/llvm/llvm-project/commit/abdd33c86a34517bbbe91adcacaae1ed5ea6b1d8
DIFF: 
https://github.com/llvm/llvm-project/commit/abdd33c86a34517bbbe91adcacaae1ed5ea6b1d8.diff

LOG: [analyzer] AnalyzerOptions: Remove 'fixits-as-remarks'

Summary: The new way of checking fix-its is `%check_analyzer_fixit`.

Reviewed By: NoQ, Szelethus, xazax.hun

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

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/dead-stores.c
clang/test/Analysis/virtualcall-fixits.cpp

Removed: 
clang/test/Analysis/virtualcall-fixit.cpp



diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index 400e953e3c6c..ee67f60df948 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -306,10 +306,6 @@ ANALYZER_OPTION(bool, ShouldTrackConditionsDebug, 
"track-conditions-debug",
 "Whether to place an event at each tracked condition.",
 false)
 
-ANALYZER_OPTION(bool, ShouldEmitFixItHintsAsRemarks, "fixits-as-remarks",
-"Emit fix-it hints as remarks for testing purposes",
-false)
-
 ANALYZER_OPTION(bool, ShouldApplyFixIts, "apply-fixits",
 "Apply the fix-it hints to the files",
 false)

diff  --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp 
b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 1e036dba2de5..417eb7ec3d31 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -92,7 +92,6 @@ class ClangDiagPathDiagConsumer : public 
PathDiagnosticConsumer {
 
   bool IncludePath = false;
   bool ShouldEmitAsError = false;
-  bool FixitsAsRemarks = false;
   bool ApplyFixIts = false;
 
 public:
@@ -110,7 +109,6 @@ class ClangDiagPathDiagConsumer : public 
PathDiagnosticConsumer {
 
   void enablePaths() { IncludePath = true; }
   void enableWerror() { ShouldEmitAsError = true; }
-  void enableFixitsAsRemarks() { FixitsAsRemarks = true; }
   void enableApplyFixIts() { ApplyFixIts = true; }
 
   void FlushDiagnosticsImpl(std::vector ,
@@ -120,42 +118,24 @@ class ClangDiagPathDiagConsumer : public 
PathDiagnosticConsumer {
 ? Diag.getCustomDiagID(DiagnosticsEngine::Error, "%0")
 : Diag.getCustomDiagID(DiagnosticsEngine::Warning, "%0");
 unsigned NoteID = Diag.getCustomDiagID(DiagnosticsEngine::Note, "%0");
-unsigned RemarkID = Diag.getCustomDiagID(DiagnosticsEngine::Remark, "%0");
 SourceManager  = Diag.getSourceManager();
 
 Replacements Repls;
 auto reportPiece = [&](unsigned ID, FullSourceLoc Loc, StringRef String,
ArrayRef Ranges,
ArrayRef Fixits) {
-  if (!FixitsAsRemarks && !ApplyFixIts) {
+  if (!ApplyFixIts) {
 Diag.Report(Loc, ID) << String << Ranges << Fixits;
 return;
   }
 
   Diag.Report(Loc, ID) << String << Ranges;
-  if (FixitsAsRemarks) {
-for (const FixItHint  : Fixits) {
-  llvm::SmallString<128> Str;
-  llvm::raw_svector_ostream OS(Str);
-  // FIXME: Add support for InsertFromRange and
-  // BeforePreviousInsertion.
-  assert(!Hint.InsertFromRange.isValid() && "Not implemented yet!");
-  assert(!Hint.BeforePreviousInsertions && "Not implemented yet!");
-  OS << SM.getSpellingColumnNumber(Hint.RemoveRange.getBegin()) << "-"
- << SM.getSpellingColumnNumber(Hint.RemoveRange.getEnd()) << ": '"
- << Hint.CodeToInsert << "'";
-  Diag.Report(Loc, RemarkID) << OS.str();
-}
-  }
+  for (const FixItHint  : Fixits) {
+Replacement Repl(SM, Hint.RemoveRange, Hint.CodeToInsert);
 
-  if (ApplyFixIts) {
-for (const FixItHint  : Fixits) {
-  Replacement Repl(SM, Hint.RemoveRange, Hint.CodeToInsert);
-
-  if (llvm::Error Err = Repls.add(Repl)) {
-llvm::errs() << "Error applying replacement " << Repl.toString()
- << ": " << Err << "\n";
-  }
+if (llvm::Error Err = Repls.add(Repl)) {
+  llvm::errs() << "Error applying replacement " << Repl.toString()
+   << ": " << Err << "\n";
 }
   }
 };
@@ -298,9 +278,6 @@ class AnalysisConsumer : public AnalysisASTConsumer,
   if (Opts->AnalyzerWerror)
 clangDiags->enableWerror();
 
-  if (Opts->ShouldEmitFixItHintsAsRemarks)
-

[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang-Tidy's script

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked an inline comment as done.
Charusso added a comment.

Thanks everyone! I hope the Analyzer developers start to use the wonderful 
features from Clang-Tidy.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69746/new/

https://reviews.llvm.org/D69746



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


[PATCH] D75402: [HIP] Make sure, unused hip-pinned-shadow global var is kept within device code

2020-03-03 Thread Mahesha S via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcac068600e55: [HIP] Make sure, unused hip-pinned-shadow 
global var is kept within device code (authored by hsmhsm).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75402/new/

https://reviews.llvm.org/D75402

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGenCUDA/hip-pinned-shadow.cu


Index: clang/test/CodeGenCUDA/hip-pinned-shadow.cu
===
--- clang/test/CodeGenCUDA/hip-pinned-shadow.cu
+++ clang/test/CodeGenCUDA/hip-pinned-shadow.cu
@@ -4,6 +4,8 @@
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPDEV %s
 // RUN: %clang_cc1 -triple x86_64 -std=c++11 \
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPHOST %s
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 -fvisibility 
hidden -fapply-global-visibility-to-externs \
+// RUN: -O3 -emit-llvm -o - -x hip %s | FileCheck 
-check-prefixes=HIPDEVUNSED %s
 
 struct textureReference {
   int a;
@@ -21,3 +23,5 @@
 // HIPDEV-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  define{{.*}}@_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  call i32 @__hipRegisterVar{{.*}}@tex{{.*}}i32 0, i32 4, i32 0, 
i32 0)
+// HIPDEVUNSED: @tex = external addrspace(1) global %struct.texture
+// HIPDEVUNSED-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1037,7 +1037,7 @@
   void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
 
   /// Add a global to a list to be added to the llvm.used metadata.
-  void addUsedGlobal(llvm::GlobalValue *GV);
+  void addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck = false);
 
   /// Add a global to a list to be added to the llvm.compiler.used metadata.
   void addCompilerUsedGlobal(llvm::GlobalValue *GV);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -1916,9 +1916,9 @@
   }
 }
 
-void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
-  assert(!GV->isDeclaration() &&
- "Only globals with definition can force usage.");
+void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck) {
+  assert(SkipCheck || (!GV->isDeclaration() &&
+   "Only globals with definition can force usage."));
   LLVMUsed.emplace_back(GV);
 }
 
@@ -4071,9 +4071,17 @@
 }
   }
 
-  if (!IsHIPPinnedShadowVar)
+  // HIPPinnedShadowVar should remain in the final code object irrespective of
+  // whether it is used or not within the code. Add it to used list, so that
+  // it will not get eliminated when it is unused. Also, it is an extern var
+  // within device code, and it should *not* get initialized within device 
code.
+  if (IsHIPPinnedShadowVar)
+addUsedGlobal(GV, /*SkipCheck=*/true);
+  else
 GV->setInitializer(Init);
-  if (emitter) emitter->finalize(GV);
+
+  if (emitter)
+emitter->finalize(GV);
 
   // If it is safe to mark the global 'constant', do so now.
   GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&


Index: clang/test/CodeGenCUDA/hip-pinned-shadow.cu
===
--- clang/test/CodeGenCUDA/hip-pinned-shadow.cu
+++ clang/test/CodeGenCUDA/hip-pinned-shadow.cu
@@ -4,6 +4,8 @@
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPDEV %s
 // RUN: %clang_cc1 -triple x86_64 -std=c++11 \
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPHOST %s
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 -fvisibility hidden -fapply-global-visibility-to-externs \
+// RUN: -O3 -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPDEVUNSED %s
 
 struct textureReference {
   int a;
@@ -21,3 +23,5 @@
 // HIPDEV-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  define{{.*}}@_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  call i32 @__hipRegisterVar{{.*}}@tex{{.*}}i32 0, i32 4, i32 0, i32 0)
+// HIPDEVUNSED: @tex = external addrspace(1) global %struct.texture
+// HIPDEVUNSED-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1037,7 +1037,7 @@
   void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
 
   /// Add a global to a list to be added to the llvm.used metadata.
-  void addUsedGlobal(llvm::GlobalValue *GV);
+  void addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck = false);
 
   /// Add a global to a list to be added to the 

[PATCH] D69746: [analyzer] FixItHint: Apply and test hints with the Clang-Tidy's script

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf69c74db34f4: [analyzer] FixItHint: Apply and test hints 
with the Clang-Tidys script (authored by Charusso).

Changed prior to commit:
  https://reviews.llvm.org/D69746?vs=246209=248103#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69746/new/

https://reviews.llvm.org/D69746

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  clang/lib/StaticAnalyzer/Frontend/CMakeLists.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/check-analyzer-fixit.py
  clang/test/Analysis/virtualcall-fixit.cpp
  clang/test/lit.cfg.py

Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -77,6 +77,11 @@
 if config.clang_staticanalyzer_z3 == '1':
 config.available_features.add('z3')
 
+check_analyzer_fixit_path = os.path.join(
+config.test_source_root, "Analysis", "check-analyzer-fixit.py")
+config.substitutions.append(
+('%check_analyzer_fixit',
+ '%s %s' % (config.python_executable, check_analyzer_fixit_path)))
 
 llvm_config.add_tool_substitutions(tools, tool_dirs)
 
Index: clang/test/Analysis/virtualcall-fixit.cpp
===
--- /dev/null
+++ clang/test/Analysis/virtualcall-fixit.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_analyzer_fixit %s %t \
+// RUN:   -analyzer-checker=core,optin.cplusplus.VirtualCall \
+// RUN:   -analyzer-config optin.cplusplus.VirtualCall:ShowFixIts=true
+
+struct S {
+  virtual void foo();
+  S() {
+foo();
+// expected-warning@-1 {{Call to virtual method 'S::foo' during construction bypasses virtual dispatch}}
+// CHECK-FIXES: S::foo();
+  }
+  ~S();
+};
Index: clang/test/Analysis/check-analyzer-fixit.py
===
--- /dev/null
+++ clang/test/Analysis/check-analyzer-fixit.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+#
+#===- check-analyzer-fixit.py - Static Analyzer test helper ---*- python -*-===#
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#======#
+#
+# This file copy-pasted mostly from the Clang-Tidy's 'check_clang_tidy.py'.
+#
+#======#
+
+r"""
+Clang Static Analyzer test helper
+=
+
+This script runs the Analyzer in fix-it mode and verify fixes, warnings, notes.
+
+Usage:
+  check-analyzer-fixit.py   [analyzer arguments]
+
+Example:
+  // RUN: %check-analyzer-fixit %s %t -analyzer-checker=core
+"""
+
+import argparse
+import os
+import re
+import subprocess
+import sys
+
+
+def write_file(file_name, text):
+with open(file_name, 'w') as f:
+f.write(text)
+
+
+def run_test_once(args, extra_args):
+input_file_name = args.input_file_name
+temp_file_name = args.temp_file_name
+clang_analyzer_extra_args = extra_args
+
+file_name_with_extension = input_file_name
+_, extension = os.path.splitext(file_name_with_extension)
+if extension not in ['.c', '.hpp', '.m', '.mm']:
+extension = '.cpp'
+temp_file_name = temp_file_name + extension
+
+with open(input_file_name, 'r') as input_file:
+input_text = input_file.read()
+
+# Remove the contents of the CHECK lines to avoid CHECKs matching on
+# themselves.  We need to keep the comments to preserve line numbers while
+# avoiding empty lines which could potentially trigger formatting-related
+# checks.
+cleaned_test = re.sub('// *CHECK-[A-Z0-9\-]*:[^\r\n]*', '//', input_text)
+write_file(temp_file_name, cleaned_test)
+
+original_file_name = temp_file_name + ".orig"
+write_file(original_file_name, cleaned_test)
+
+try:
+builtin_include_dir = subprocess.check_output(
+['clang', '-print-file-name=include'], stderr=subprocess.STDOUT)
+except subprocess.CalledProcessError as e:
+print('Cannot print Clang include directory: ' + e.output.decode())
+
+builtin_include_dir = os.path.normpath(builtin_include_dir)
+
+args = (['clang', '-cc1', '-internal-isystem', builtin_include_dir,
+ '-nostdsysteminc', '-analyze', '-analyzer-constraints=range',
+ '-analyzer-config', 'apply-fixits=true']
++ clang_analyzer_extra_args + ['-verify', temp_file_name])
+
+print('Running ' + str(args) + '...')
+
+try:
+clang_analyzer_output = \
+subprocess.check_output(args, stderr=subprocess.STDOUT).decode()
+except subprocess.CalledProcessError as e:
+

[clang] f69c74d - [analyzer] FixItHint: Apply and test hints with the Clang-Tidy's script

2020-03-03 Thread via cfe-commits

Author: Charusso
Date: 2020-03-04T06:26:33+01:00
New Revision: f69c74db34f42c20c167b8fb0f93ec05a0e77b45

URL: 
https://github.com/llvm/llvm-project/commit/f69c74db34f42c20c167b8fb0f93ec05a0e77b45
DIFF: 
https://github.com/llvm/llvm-project/commit/f69c74db34f42c20c167b8fb0f93ec05a0e77b45.diff

LOG: [analyzer] FixItHint: Apply and test hints with the Clang-Tidy's script

Summary:
This patch introduces a way to apply the fix-its by the Analyzer:
`-analyzer-config apply-fixits=true`.

The fix-its should be testable, therefore I have copied the well-tested
`check_clang_tidy.py` script. The idea is that the Analyzer's workflow
is different so it would be very difficult to use only one script for
both Tidy and the Analyzer, the script would diverge a lot.
Example test: `// RUN: %check-analyzer-fixit %s %t -analyzer-checker=core`

When the copy-paste happened the original authors were:
@alexfh, @zinovy.nis, @JonasToth, @hokein, @gribozavr, @lebedev.ri

Reviewed By: NoQ, alexfh, zinovy.nis

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

Added: 
clang/test/Analysis/check-analyzer-fixit.py
clang/test/Analysis/virtualcall-fixit.cpp

Modified: 
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
clang/lib/StaticAnalyzer/Frontend/CMakeLists.txt
clang/test/Analysis/analyzer-config.c
clang/test/lit.cfg.py

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index 00febf688195..400e953e3c6c 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -310,6 +310,10 @@ ANALYZER_OPTION(bool, ShouldEmitFixItHintsAsRemarks, 
"fixits-as-remarks",
 "Emit fix-it hints as remarks for testing purposes",
 false)
 
+ANALYZER_OPTION(bool, ShouldApplyFixIts, "apply-fixits",
+"Apply the fix-it hints to the files",
+false)
+
 
//===--===//
 // Unsigned analyzer options.
 
//===--===//

diff  --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp 
b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 28a3ab2ba188..1e036dba2de5 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -12,7 +12,6 @@
 
 #include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
 #include "ModelInjector.h"
-#include "clang/Analysis/PathDiagnostic.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
@@ -21,10 +20,12 @@
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CallGraph.h"
 #include "clang/Analysis/CodeInjector.h"
+#include "clang/Analysis/PathDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/CrossTU/CrossTranslationUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/StaticAnalyzer/Checkers/LocalCheckers.h"
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
@@ -33,6 +34,8 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "clang/StaticAnalyzer/Frontend/CheckerRegistration.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/FileSystem.h"
@@ -46,6 +49,7 @@
 
 using namespace clang;
 using namespace ento;
+using namespace tooling;
 
 #define DEBUG_TYPE "AnalysisConsumer"
 
@@ -84,11 +88,16 @@ void ento::createTextPathDiagnosticConsumer(
 namespace {
 class ClangDiagPathDiagConsumer : public PathDiagnosticConsumer {
   DiagnosticsEngine 
-  bool IncludePath = false, ShouldEmitAsError = false, FixitsAsRemarks = false;
+  LangOptions LO;
+
+  bool IncludePath = false;
+  bool ShouldEmitAsError = false;
+  bool FixitsAsRemarks = false;
+  bool ApplyFixIts = false;
 
 public:
-  ClangDiagPathDiagConsumer(DiagnosticsEngine )
-  : Diag(Diag) {}
+  ClangDiagPathDiagConsumer(DiagnosticsEngine , LangOptions LO)
+  : Diag(Diag), LO(LO) {}
   ~ClangDiagPathDiagConsumer() override {}
   StringRef getName() const override { return "ClangDiags"; }
 
@@ -102,6 +111,7 @@ class ClangDiagPathDiagConsumer : public 
PathDiagnosticConsumer {
   void enablePaths() { IncludePath = true; }
   void enableWerror() { ShouldEmitAsError = true; }
   void enableFixitsAsRemarks() { FixitsAsRemarks = true; }
+  void enableApplyFixIts() { ApplyFixIts = true; }
 
   void 

[clang] cac0686 - [HIP] Make sure, unused hip-pinned-shadow global var is kept within device code

2020-03-03 Thread via cfe-commits

Author: hsmahesha
Date: 2020-03-04T10:54:26+05:30
New Revision: cac068600e55e489844156d3581b61eeecee7d4e

URL: 
https://github.com/llvm/llvm-project/commit/cac068600e55e489844156d3581b61eeecee7d4e
DIFF: 
https://github.com/llvm/llvm-project/commit/cac068600e55e489844156d3581b61eeecee7d4e.diff

LOG: [HIP] Make sure, unused hip-pinned-shadow global var is kept within device 
code

Summary:
hip-pinned-shadow global var should remain in the final code object irrespective
of whether it is used or not within the code. Add it to used list, so that it
will not get eliminated when it is unused.

Reviewers: yaxunl, tra, hliao

Reviewed By: yaxunl

Subscribers: hliao, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGenCUDA/hip-pinned-shadow.cu

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index faff623a2973..719cb05d9ec8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1916,9 +1916,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, 
llvm::Function *F,
   }
 }
 
-void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
-  assert(!GV->isDeclaration() &&
- "Only globals with definition can force usage.");
+void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck) {
+  assert(SkipCheck || (!GV->isDeclaration() &&
+   "Only globals with definition can force usage."));
   LLVMUsed.emplace_back(GV);
 }
 
@@ -4071,9 +4071,17 @@ void CodeGenModule::EmitGlobalVarDefinition(const 
VarDecl *D,
 }
   }
 
-  if (!IsHIPPinnedShadowVar)
+  // HIPPinnedShadowVar should remain in the final code object irrespective of
+  // whether it is used or not within the code. Add it to used list, so that
+  // it will not get eliminated when it is unused. Also, it is an extern var
+  // within device code, and it should *not* get initialized within device 
code.
+  if (IsHIPPinnedShadowVar)
+addUsedGlobal(GV, /*SkipCheck=*/true);
+  else
 GV->setInitializer(Init);
-  if (emitter) emitter->finalize(GV);
+
+  if (emitter)
+emitter->finalize(GV);
 
   // If it is safe to mark the global 'constant', do so now.
   GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&

diff  --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index ff8cea486cc2..fc4486659426 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1037,7 +1037,7 @@ class CodeGenModule : public CodeGenTypeCache {
   void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
 
   /// Add a global to a list to be added to the llvm.used metadata.
-  void addUsedGlobal(llvm::GlobalValue *GV);
+  void addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck = false);
 
   /// Add a global to a list to be added to the llvm.compiler.used metadata.
   void addCompilerUsedGlobal(llvm::GlobalValue *GV);

diff  --git a/clang/test/CodeGenCUDA/hip-pinned-shadow.cu 
b/clang/test/CodeGenCUDA/hip-pinned-shadow.cu
index 75798f7e1dec..1d22ed6dc94c 100644
--- a/clang/test/CodeGenCUDA/hip-pinned-shadow.cu
+++ b/clang/test/CodeGenCUDA/hip-pinned-shadow.cu
@@ -4,6 +4,8 @@
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPDEV %s
 // RUN: %clang_cc1 -triple x86_64 -std=c++11 \
 // RUN: -emit-llvm -o - -x hip %s | FileCheck -check-prefixes=HIPHOST %s
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 -fvisibility 
hidden -fapply-global-visibility-to-externs \
+// RUN: -O3 -emit-llvm -o - -x hip %s | FileCheck 
-check-prefixes=HIPDEVUNSED %s
 
 struct textureReference {
   int a;
@@ -21,3 +23,5 @@ __attribute__((hip_pinned_shadow)) texture tex;
 // HIPDEV-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  define{{.*}}@_ZN7textureIfLi2ELi1EEC1Ev
 // HIPHOST:  call i32 @__hipRegisterVar{{.*}}@tex{{.*}}i32 0, i32 4, i32 0, 
i32 0)
+// HIPDEVUNSED: @tex = external addrspace(1) global %struct.texture
+// HIPDEVUNSED-NOT: declare{{.*}}void @_ZN7textureIfLi2ELi1EEC1Ev



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


LLVM buildmaster will be restarted soon

2020-03-03 Thread Galina Kistanova via cfe-commits
 Hello everyone,

LLVM buildmaster will be updated and restarted in few minutes.

Thanks

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


[PATCH] D75591: [OpenMP] Add firstprivate as a default data-sharing attribute to clang

2020-03-03 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 248098.
atmnpatel added a comment.

Fixes typos that causes certain unit tests to fail.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75591/new/

https://reviews.llvm.org/D75591

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/distribute_parallel_for_default_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/parallel_default_messages.cpp
  clang/test/OpenMP/parallel_for_default_messages.cpp
  clang/test/OpenMP/parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/parallel_master_codegen.cpp
  clang/test/OpenMP/parallel_master_default_messages.cpp
  clang/test/OpenMP/parallel_sections_default_messages.cpp
  clang/test/OpenMP/target_parallel_default_messages.cpp
  clang/test/OpenMP/target_parallel_for_default_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/target_teams_default_messages.cpp
  clang/test/OpenMP/target_teams_distribute_default_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_default_messages.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/task_default_messages.cpp
  clang/test/OpenMP/task_messages.cpp
  clang/test/OpenMP/teams_default_messages.cpp
  clang/test/OpenMP/teams_distribute_default_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_default_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/teams_distribute_simd_default_messages.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -381,6 +381,7 @@
 
 __OMP_DEFAULT_KIND(none)
 __OMP_DEFAULT_KIND(shared)
+__OMP_DEFAULT_KIND(firstprivate)
 __OMP_DEFAULT_KIND(unknown)
 
 #undef __OMP_DEFAULT_KIND
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1843,11 +1843,18 @@
   EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
 
   const std::string Source4 = R"(
+void x() {
+#pragma omp parallel default(firstprivate)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+
+  const std::string Source5 = R"(
 void x(int x) {
 #pragma omp parallel num_threads(x)
 ;
 })";
-  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+  EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher));
 }
 
 TEST(MatchFinderAPI, matchesDynamic) {
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2812,11 +2812,18 @@
   EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
 
   const std::string Source4 = R"(
+void x() {
+#pragma omp parallel default(firstprivate)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+
+  const std::string Source5 = R"(
 void x(int x) {
 #pragma omp parallel num_threads(x)
 ;
 })";
-  EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+  EXPECT_TRUE(matchesWithOpenMP(Source5, Matcher));
 }
 
 TEST(OMPDefaultClause, isNoneKind) {
@@ -2852,10 +2859,17 @@
 
   const std::string Source4 = R"(
 void x(int x) {
-#pragma omp parallel num_threads(x)
+#pragma omp parallel default(firstprivate)
 ;
 })";
   EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+
+  const std::string Source5 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher));
 }
 
 TEST(OMPDefaultClause, isSharedKind) {
@@ -2891,10 +2905,63 @@
 
   const std::string Source4 = R"(
 void x(int x) {
-#pragma omp parallel num_threads(x)
+#pragma omp parallel default(firstprivate)
 ;
 })";
   EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+
+  const std::string Source5 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher));
+}
+
+TEST(OMPDefaultClause, isFirstPrivateKind) {
+  auto Matcher = ompExecutableDirective(
+  hasAnyClause(ompDefaultClause(isFirstPrivateKind(;
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+

[PATCH] D69726: [analyzer] DynamicSize: Store the dynamic size

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 248097.
Charusso marked 4 inline comments as done.
Charusso edited the summary of this revision.
Charusso added a comment.

- Set the size properly.
- Add new debug.ExprInspection patterns: region, size, element count.
- `clang-format -i ExprInspectionChecker.cpp`.
- Having no idea what is the single regression in tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69726/new/

https://reviews.llvm.org/D69726

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h
  clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/explain-svals.cpp
  clang/test/Analysis/expr-inspection.cpp
  clang/test/Analysis/memory-model.cpp
  clang/test/Analysis/misc-ps-region-store.m

Index: clang/test/Analysis/misc-ps-region-store.m
===
--- clang/test/Analysis/misc-ps-region-store.m
+++ clang/test/Analysis/misc-ps-region-store.m
@@ -1186,7 +1186,8 @@
 for (y = 0; y < b_h; y++) {
   for (x = 0; x < b_w + 1; x++) {
 int am = 0;
-tmp2[x] = am;
+tmp2[x] = am; // expected-warning \
+{{Access out-of-bound array element (buffer overflow)}}
   }
 }
   }
Index: clang/test/Analysis/memory-model.cpp
===
--- /dev/null
+++ clang/test/Analysis/memory-model.cpp
@@ -0,0 +1,108 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix,cplusplus,debug.ExprInspection \
+// RUN:  -triple x86_64-unknown-linux-gnu \
+// RUN:  -verify %s
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+typedef __SIZE_TYPE__ size_t;
+void *malloc(size_t);
+void *alloca(size_t);
+void *realloc(void *ptr, size_t size);
+void *calloc(size_t number, size_t size);
+void free(void *);
+
+struct S { int f; };
+
+void clang_analyzer_region(int);
+void clang_analyzer_region(const void *);
+void clang_analyzer_size(int);
+void clang_analyzer_size(const void *);
+void clang_analyzer_elementCount(int);
+void clang_analyzer_elementCount(const void *);
+
+void var_region_simple_ref() {
+  int a = 13;
+  clang_analyzer_region(); // expected-warning {{a}}
+  clang_analyzer_size(); // expected-warning {{4 S64b}}
+  clang_analyzer_elementCount(); // expected-warning {{1 S64b}}
+}
+
+void var_region_simple_ptr(int *a) {
+  clang_analyzer_region(a); // expected-warning {{SymRegion{reg_$0}}}
+  clang_analyzer_size(a); // expected-warning {{extent_$1{SymRegion{reg_$0
+  clang_analyzer_elementCount(a); // expected-warning {{(extent_$1{SymRegion{reg_$0}}) / 8}}
+}
+
+void var_region_array() {
+  int a[] = {1, 2, 3};
+  clang_analyzer_region(a); // expected-warning {{Element{a,0 S64b,int}}}
+  clang_analyzer_size(a); // expected-warning {{12 S64b}}
+  clang_analyzer_elementCount(a); // expected-warning {{3 S64b}}
+}
+
+void string_region() {
+  clang_analyzer_region("foo"); // expected-warning {{Element{"foo",0 S64b,char}}}
+  clang_analyzer_size("foo"); // expected-warning {{4 S64b}}
+  clang_analyzer_elementCount("foo"); // expected-warning {{4 S64b}}
+}
+
+void field_region_ref(S a) {
+  clang_analyzer_region(); // expected-warning {{a.f}}
+  clang_analyzer_size(); // expected-warning {{4 S64b}}
+  clang_analyzer_elementCount(); // expected-warning {{1 S64b}}
+}
+
+void field_region_ptr(S *a) {
+  clang_analyzer_region(>f); // expected-warning {{SymRegion{reg_$0}.f}}
+  clang_analyzer_size(>f); // expected-warning {{4 S64b}}
+  clang_analyzer_elementCount(>f); // expected-warning {{1 S64b}}
+}
+
+void symbolic_array() {
+  int *a = new int[3];
+  clang_analyzer_region(a); // expected-warning {{Element{HeapSymRegion{conj}}
+  clang_analyzer_size(a); // expected-warning {{12 S64b}}
+  clang_analyzer_elementCount(a); // expected-warning {{3 S64b}}
+  delete[] a;
+}
+
+void symbolic_placement_new() {
+  char *buf = new char[sizeof(int) * 3];
+  int *a = new (buf) int(13);
+  clang_analyzer_region(a); // expected-warning {{Element{HeapSymRegion{conj}}
+  clang_analyzer_size(a); // expected-warning {{12 S64b}}
+  clang_analyzer_elementCount(a); // expected-warning {{3 S64b}}
+  delete[] buf;
+}
+
+void symbolic_malloc() {
+  int *a = (int *)malloc(12);
+  clang_analyzer_region(a); // expected-warning {{Element{HeapSymRegion{conj}}
+  clang_analyzer_size(a); // expected-warning {{12 S64b}}
+  clang_analyzer_elementCount(a); // expected-warning {{3 S64b}}
+  free(a);
+}
+
+void symbolic_alloca() {
+  int *a = (int *)alloca(12);
+  clang_analyzer_region(a); // expected-warning {{Element{HeapSymRegion{conj}}
+  clang_analyzer_size(a); // 

[PATCH] D69726: [analyzer] DynamicSize: Store the dynamic size

2020-03-03 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 2 inline comments as done.
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/DynamicSize.cpp:85
+if (CI->getValue().isUnsigned())
+  Size = SVB.makeIntVal(CI->getValue(), /*IsUnsigned=*/false);
+

That one is interesting. Some of the checkers / SValBuilder(?) generate 
unsigned integers which should not happen, I believe. May we need a FIXME and 
an assertion about signedness. What do you think?



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp:698
+  DefinedOrUnknownSVal Size = UnknownVal();
+  if (const Expr *SizeExpr = CNE->getArraySize().getValueOr(nullptr))
+Size = State->getSVal(SizeExpr, LCtx).castAs();

NoQ wrote:
> Same. I guess we should add a test for both cases, given that nothing failed 
> when we screwed up the extent.
Well, it was equally wrong everywhere, so that it works... I have noticed it 
like 5 months ago, but I was lazy to fix.



Comment at: clang/test/Analysis/explain-svals.cpp:52
   // Sic! What gets computed is the extent of the element-region.
-  clang_analyzer_explain(clang_analyzer_getExtent(x)); // 
expected-warning-re^signed 32-bit integer '4'$
+  clang_analyzer_explain(clang_analyzer_getExtent(x)); // 
expected-warning-re^\(argument 'ext'\) \* 4$
   delete[] x;

Yea, that is the fact: The size is the size of the parameter, which is unknown.



Comment at: clang/test/Analysis/memory-model.cpp:108
+  free(c);
+}

Here I wanted to put more, but I am not that cool with other MemRegions. Some 
wise words about the followups of this test file:
> Some day
- The 11 years old comment in ExprEngine.cpp: 
https://github.com/llvm/llvm-project/blame/master/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp#L237



Comment at: clang/test/Analysis/misc-ps-region-store.m:1190
+tmp2[x] = am; // expected-warning \
+{{Access out-of-bound array element (buffer overflow)}}
   }

That is the single regression which I do not get.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69726/new/

https://reviews.llvm.org/D69726



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


[PATCH] D75162: [X86][F16C] Remove cvtph2ps intrinsics and use generic half2float conversion (PR37554)

2020-03-03 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsX86.td:2551
-  Intrinsic<[llvm_v4f32_ty], [llvm_v8i16_ty], [IntrNoMem]>;
-  def int_x86_vcvtph2ps_256 : GCCBuiltin<"__builtin_ia32_vcvtph2ps256">,
-  Intrinsic<[llvm_v8f32_ty], [llvm_v8i16_ty], [IntrNoMem]>;

hoyFB wrote:
> Hello, we have some tools generating these intrinsics being removed here. Can 
> you suggest what we should generate on LLVM IR with this change?
I think the diffs to test/CodeGen/f16c-builtins.c should show the difference. 
You can also follow the code in the changes to AutoUpgrade.cpp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75162/new/

https://reviews.llvm.org/D75162



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


[PATCH] D75430: [analyzer][NFC] Introduce CXXDeallocatorCall, deploy it in MallocChecker

2020-03-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I love where this is going.

> the reason behind this is that neither does `preStmt` have a 
> `postStmt` pair. But I have no clue why that is :^)

I'm pretty sure it's forgotten :/




Comment at: clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:67
   CE_CXXAllocator,
+  CE_CXXDeallocator,
   CE_BEG_FUNCTION_CALLS = CE_Function,

After this you probably received compiler warnings saying "case isn't covered 
in switch". You'll need to clean them up.

Another thing to do would be to update `CallEventManager`'s `getCall()` and 
`getCaller()` methods that'd allow the users to construct the new `CallEvent` 
easily without thinking about what specific kind of call event it is.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:958
+
+  unsigned getNumArgs() const override { return getDecl()->getNumParams(); }
+

Charusso wrote:
> `return getOriginExpr()->getNumArgs()`
This wouldn't compile. `CXXDeleteExpr` is not a `CallExpr`.

It sounds like there are currently [[ 
http://www.cplusplus.com/reference/new/operator%20delete/ | five different 
`operator delete`s ]]:
{F11474783}

And, unlike `operator new`, there's no option to provide custom "placement" 
arguments.

So i think the logic in this patch is correct but we should do some custom 
logic for all 5 cases in the `getArgExpr` method, where argument expressions 
for the extra arguments will have to be conjured out of thin air (or we might 
as well return null).



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:853
+  CDE, Pred->getState(), Pred->getLocationContext());
+  getCheckerManager().runCheckersForPreCall(Dst, Pred, *Call, *this);
 }

Yes, we should absolutely have `PostCall` here as well, even if nothing happens 
in between.

And once it's there, the next major step would be to invoke 
`ExprEngine::evalCall()` instead if the operator was overloaded, so that we 
could //inline// the deallocator (or evaluate it conservatively, which might 
also be of value as it would invalidate the necessary globals).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75430/new/

https://reviews.llvm.org/D75430



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


[PATCH] D75591: [OpenMP] Add firstprivate as a default data-sharing attribute to clang

2020-03-03 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel created this revision.
atmnpatel added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, guansong.
Herald added projects: clang, LLVM.

This implements the default(firstprivate) clause as defined in OpenMP
Technical Report 8 (2.22.4).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75591

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/distribute_parallel_for_default_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/parallel_default_messages.cpp
  clang/test/OpenMP/parallel_for_default_messages.cpp
  clang/test/OpenMP/parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/parallel_master_codegen.cpp
  clang/test/OpenMP/parallel_master_default_messages.cpp
  clang/test/OpenMP/parallel_sections_default_messages.cpp
  clang/test/OpenMP/target_parallel_default_messages.cpp
  clang/test/OpenMP/target_parallel_for_default_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/target_teams_default_messages.cpp
  clang/test/OpenMP/target_teams_distribute_default_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_default_messages.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/task_default_messages.cpp
  clang/test/OpenMP/task_messages.cpp
  clang/test/OpenMP/teams_default_messages.cpp
  clang/test/OpenMP/teams_distribute_default_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_default_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_default_messages.cpp
  clang/test/OpenMP/teams_distribute_simd_default_messages.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -381,6 +381,7 @@
 
 __OMP_DEFAULT_KIND(none)
 __OMP_DEFAULT_KIND(shared)
+__OMP_DEFAULT_KIND(firstprivate)
 __OMP_DEFAULT_KIND(unknown)
 
 #undef __OMP_DEFAULT_KIND
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1843,11 +1843,18 @@
   EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
 
   const std::string Source4 = R"(
+void x() {
+#pragma omp parallel default(firstprivate)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+
+  const std::string Source5 = R"(
 void x(int x) {
 #pragma omp parallel num_threads(x)
 ;
 })";
-  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+  EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher));
 }
 
 TEST(MatchFinderAPI, matchesDynamic) {
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2812,11 +2812,18 @@
   EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
 
   const std::string Source4 = R"(
+void x() {
+#pragma omp parallel default(firstprivate)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+
+  const std::string Source5 = R"(
 void x(int x) {
 #pragma omp parallel num_threads(x)
 ;
 })";
-  EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+  EXPECT_TRUE(matchesWithOpenMP(Source5, Matcher));
 }
 
 TEST(OMPDefaultClause, isNoneKind) {
@@ -2852,10 +2859,17 @@
 
   const std::string Source4 = R"(
 void x(int x) {
-#pragma omp parallel num_threads(x)
+#pragma omp parallel default(firstprivate)
 ;
 })";
   EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+
+  const std::string Source5 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher));
 }
 
 TEST(OMPDefaultClause, isSharedKind) {
@@ -2891,10 +2905,63 @@
 
   const std::string Source4 = R"(
 void x(int x) {
-#pragma omp parallel num_threads(x)
+#pragma omp parallel default(firstprivate)
 ;
 })";
   EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+
+  const std::string Source5 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source5, Matcher));
+}
+
+TEST(OMPDefaultClause, isFirstPrivateKind) {
+  auto Matcher = ompExecutableDirective(
+  hasAnyClause(ompDefaultClause(isFirstPrivateKind(;
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp 

[PATCH] D75569: [clang-tidy] New check for methods marked __attribute__((unavailable)) that do not override a method from a superclass.

2020-03-03 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:104
+
+  Finds methods marked unavailable that do not override any method from a
+  superclass.

Please synchronize with first statement in documentation.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/objc-method-unavailable-not-override.rst:6
+
+Checks that a method marked with __attribute__((unavailable)) is overriding
+a method declaration from a superclass. That declaration can usually be

Please enclose __attribute__((unavailable)) in double back-ticks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75569/new/

https://reviews.llvm.org/D75569



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


[PATCH] D75162: [X86][F16C] Remove cvtph2ps intrinsics and use generic half2float conversion (PR37554)

2020-03-03 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsX86.td:2551
-  Intrinsic<[llvm_v4f32_ty], [llvm_v8i16_ty], [IntrNoMem]>;
-  def int_x86_vcvtph2ps_256 : GCCBuiltin<"__builtin_ia32_vcvtph2ps256">,
-  Intrinsic<[llvm_v8f32_ty], [llvm_v8i16_ty], [IntrNoMem]>;

Hello, we have some tools generating these intrinsics being removed here. Can 
you suggest what we should generate on LLVM IR with this change?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75162/new/

https://reviews.llvm.org/D75162



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


[PATCH] D75298: [Clang][SVE] Parse builtin type string for scalable vectors

2020-03-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

> This is because many of the builtins are protected by an architecture guard 
> like `#ifdef __ARM_FEATURE_SVE` or `#ifdef __ARM_FEATURE_SVE2`.

I think TARGET_HEADER_BUILTIN has support for requiring target features.  
Granted, we don't use it much at the moment, so there might be some non-obvious 
issue with this.

> Do you happen to know which method in Sema does this? I had a look before, 
> but couldn't find where we could do something like this.

See Sema::LazilyCreateBuiltin, and its caller Sema::LookupBuiltin.

> The reason for using #defines for the non-overloaded intrinsics was mainly 
> performance, the preprocessor was much faster than having to parse all 
> declarations, with the only downside being the redirection in the diagnostics.

Oh, that makes sense.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75298/new/

https://reviews.llvm.org/D75298



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


[PATCH] D75572: [Sema][SVE] Reject sizeof and alignof for sizeless types

2020-03-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I think the specialized error messages are useful.  I don't have a strong 
opinion on what order the patches should land.

The difference between emitting the diagnostic in RequireCompleteType, vs. 
letting the caller do it, is basically just that it's harder to forget to check 
whether the type is sizeless.  I think that's important enough to be worth 
complicating the API a bit; better to forbid scalable types, rather than crash 
or miscompile later.  Probably the entry point that allows sizeless types 
should have a different name.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75572/new/

https://reviews.llvm.org/D75572



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


[PATCH] D74735: [analyzer] Add support for CXXInheritedCtorInitExpr.

2020-03-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D74735#1903503 , @martong wrote:

> @NoQ
>
> I've found the following reproducer to crash in `CallAndMessageChecker`:
>
>   class a {
>   public:
> a(int);
>   };
>   struct b : a {
> using a::a;
>   };
>   void c() {
> int d;
> b x(d); //Crash!, Note, x(0) causes no crash
>   }
>
>
> I am working on a fix, but any insight and help from you is really 
> appreciated.


Uh-oh, i've been looking for those but never found them.

If you do `-analyzer-display-progress` you'll see that it crashes not in `c()` 
but in `b::a()`, i.e. when trying to analyze an inheriting constructor as a 
top-level function. It then crashes when it's trying to figure out which 
argument expressions do we pass into the inherited constructor, but is unable 
to do that because the answer is "the same arguments we've received" but we 
don't know which arguments we've received, because, well, we are the top-level 
call, so no expressions for us.

I believe we simply should not try to analyze inheriting constructors as 
top-level functions. We won't be able to even display any diagnostics, given 
that the inheriting constructor doesn't have a body.

I thereby leave out the reason why `x(d)` and `x(0)` demonstrate different 
behavior as a simple exercise to the reader :]


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74735/new/

https://reviews.llvm.org/D74735



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


[PATCH] D75572: [Sema][SVE] Reject sizeof and alignof for sizeless types

2020-03-03 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a comment.

In D75572#1904415 , @efriedma wrote:

> The planned changes to RequireCompleteType should catch this, right?  If we 
> want a specialized diagnostic for sizeless types in RequireCompleteType, we 
> should probably just pass it to RequireCompleteType.  (Otherwise, you'll end 
> up with the "wrong" diagnostic in templates.)


Yeah, the planned changes to RequireCompleteType would catch this by default.  
If RequireCompleteType should always get the first shot, I guess there are 
three possible approaches:

1. Stick with the approach in D62962 , without 
specialised error messages.  I can break that patch up into smaller chunks if 
the general approach seems right.
2. Stick with the approach in this patch of having seperate isSizelessType 
checks and diagnostics, but test isSizelessType after RequireCompleteType 
instead of before it.  The later changes to RequireCompleteType allow sizeless 
types to be let through on demand, and the isSizelessType handling would be 
similar to the isFunctionType handling just below.
3. Like you say, stick with separate diagnostics for incomplete and sizeless 
types but make RequireCompleteType emit them both.

I guess one way doing 3. would be to use %select{incomplete|sizeless} and pass 
the result of isSizelessType() as one of the diagnostic parameters to 
RequireCompleteType.  But in some ways that feels a bit clunky because the 
caller is then doing the work to prove that the use is invalid (which it always 
is if isSizelessType()) but isn:t actually doing the work to emit the 
associated diagnostic.  Another option would be to make RequireCompleteType 
have a choice between three actions:

- the normal, standard-defined behaviour, with no special error messages for 
sizeless types.  This would remain the default if no action is explicitly 
specified.
- a mode that explicitly allows sizeless types
- a mode that explicitly disallows sizeless types, with the first diagnostic 
parameter being whether the type is sizeless or not.  In contrast to the above, 
RequireCompleteType would add this parameter automatically.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75572/new/

https://reviews.llvm.org/D75572



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


[PATCH] D75582: [clangd] Track document versions, include them with diags, enhance logs

2020-03-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 248070.
sammccall added a comment.

Fix incomplete message.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75582/new/

https://reviews.llvm.org/D75582

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/test/diagnostic-category.test
  clang-tools-extra/clangd/test/diagnostics-no-tidy.test
  clang-tools-extra/clangd/test/diagnostics-notes.test
  clang-tools-extra/clangd/test/diagnostics.test
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/test/execute-command.test
  clang-tools-extra/clangd/test/fixits-codeaction.test
  clang-tools-extra/clangd/test/fixits-command.test
  clang-tools-extra/clangd/test/fixits-embed-in-diagnostic.test
  clang-tools-extra/clangd/test/path-mappings.test
  clang-tools-extra/clangd/test/semantic-highlighting.test
  clang-tools-extra/clangd/test/version.test
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.h
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -838,7 +838,8 @@
   ElementsAre(Sym("foo.h", FooHeader.range(;
 
   // Only preamble is built, and no AST is built in this request.
-  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::No);
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), nullptr,
+ WantDiagnostics::No);
   // We build AST here, and it should use the latest preamble rather than the
   // stale one.
   EXPECT_THAT(
@@ -848,7 +849,8 @@
   // Reset test environment.
   runAddDocument(Server, FooCpp, FooWithHeader.code());
   // Both preamble and AST are built in this request.
-  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::Yes);
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), nullptr,
+ WantDiagnostics::Yes);
   // Use the AST being built in above request.
   EXPECT_THAT(
   cantFail(runLocateSymbolAt(Server, FooCpp, FooWithoutHeader.point())),
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -97,16 +97,16 @@
 
 SymbolSlab TestTU::headerSymbols() const {
   auto AST = build();
-  return std::get<0>(indexHeaderSymbols(AST.getASTContext(),
-AST.getPreprocessorPtr(),
-AST.getCanonicalIncludes()));
+  return std::get<0>(
+  indexHeaderSymbols(/*Version=*/nullptr, AST.getASTContext(),
+ AST.getPreprocessorPtr(), AST.getCanonicalIncludes()));
 }
 
 std::unique_ptr TestTU::index() const {
   auto AST = build();
   auto Idx = std::make_unique(/*UseDex=*/true);
-  Idx->updatePreamble(Filename, AST.getASTContext(), AST.getPreprocessorPtr(),
-  AST.getCanonicalIncludes());
+  Idx->updatePreamble(Filename, /*Version=*/nullptr, AST.getASTContext(),
+  AST.getPreprocessorPtr(), AST.getCanonicalIncludes());
   Idx->updateMain(Filename, AST);
   return std::move(Idx);
 }
Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -40,7 +40,15 @@
 using ::testing::UnorderedElementsAre;
 
 MATCHER_P2(TUState, State, ActionName, "") {
-  return arg.Action.S == State && arg.Action.Name == ActionName;
+  if (arg.Action.S != State) {
+*result_listener << "state is " << arg.Action.S;
+return false;
+  }
+  if (arg.Action.Name != ActionName) {
+*result_listener << "name is " << arg.Action.Name;
+return false;
+  }

[PATCH] D75572: [Sema][SVE] Reject sizeof and alignof for sizeless types

2020-03-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Just looked at the comment on D75572 ; not 
sure if RequireCompleteType is going to reject sizeless types.  In any case, 
you have to instantiate templates using RequireCompleteType before you can 
determine whether a type is sizeless.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75572/new/

https://reviews.llvm.org/D75572



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


[PATCH] D62962: Clang implementation of sizeless types

2020-03-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Okay, thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62962/new/

https://reviews.llvm.org/D62962



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


[PATCH] D75579: [WIP] Replace MCTargetOptionsCommandFlags.inc and CommandFlags.inc by libraries

2020-03-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

On Arch Linux side, I reported a similar issue 
https://bugs.archlinux.org/task/64464#comment183541 for ldc (LLVM-based D 
compiler)

  % cmake -H. -BArch -G Ninja -DCMAKE_BUILD_TYPE=Debug 
-DD_COMPILER=$HOME/dlang/dmd-2.089.0/linux/bin64/dmd -DCMAKE_CXX_STANDARD=14 
-DLDC_WITH_LLD=On
  % ninja -C Arch
  ...
  : CommandLine Error: Option 'mc-relax-all' registered more than once!
  % Arch/bin/ldc2
  : CommandLine Error: Option 'mc-relax-all' registered more than once!
  LLVM ERROR: inconsistency in registered CommandLine options

I agree that moving global constructors from `.inc` files into 
`lib/CodeGen/CommandFlags/CommandFlags.cpp` is the correct direction.

Testing several configurations helps capture build problems early:

- `-DBUILD_SHARED_LIBS=off` (default)
- `-DBUILD_SHARED_LIBS=off` `-DLLVM_LINK_LLVM_DYLIB=on` 
`-DCLANG_LINK_CLANG_DYLIB=on`
- `-DBUILD_SHARED_LIBSS=on`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75579/new/

https://reviews.llvm.org/D75579



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


[PATCH] D75582: [clangd] Track document versions, include them with diags, enhance logs

2020-03-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 248069.
sammccall added a comment.

Fix accidental default.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75582/new/

https://reviews.llvm.org/D75582

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/test/diagnostic-category.test
  clang-tools-extra/clangd/test/diagnostics-no-tidy.test
  clang-tools-extra/clangd/test/diagnostics-notes.test
  clang-tools-extra/clangd/test/diagnostics.test
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/test/execute-command.test
  clang-tools-extra/clangd/test/fixits-codeaction.test
  clang-tools-extra/clangd/test/fixits-command.test
  clang-tools-extra/clangd/test/fixits-embed-in-diagnostic.test
  clang-tools-extra/clangd/test/path-mappings.test
  clang-tools-extra/clangd/test/semantic-highlighting.test
  clang-tools-extra/clangd/test/version.test
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.h
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -838,7 +838,8 @@
   ElementsAre(Sym("foo.h", FooHeader.range(;
 
   // Only preamble is built, and no AST is built in this request.
-  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::No);
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), nullptr,
+ WantDiagnostics::No);
   // We build AST here, and it should use the latest preamble rather than the
   // stale one.
   EXPECT_THAT(
@@ -848,7 +849,8 @@
   // Reset test environment.
   runAddDocument(Server, FooCpp, FooWithHeader.code());
   // Both preamble and AST are built in this request.
-  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::Yes);
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), nullptr,
+ WantDiagnostics::Yes);
   // Use the AST being built in above request.
   EXPECT_THAT(
   cantFail(runLocateSymbolAt(Server, FooCpp, FooWithoutHeader.point())),
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -97,16 +97,16 @@
 
 SymbolSlab TestTU::headerSymbols() const {
   auto AST = build();
-  return std::get<0>(indexHeaderSymbols(AST.getASTContext(),
-AST.getPreprocessorPtr(),
-AST.getCanonicalIncludes()));
+  return std::get<0>(
+  indexHeaderSymbols(/*Version=*/nullptr, AST.getASTContext(),
+ AST.getPreprocessorPtr(), AST.getCanonicalIncludes()));
 }
 
 std::unique_ptr TestTU::index() const {
   auto AST = build();
   auto Idx = std::make_unique(/*UseDex=*/true);
-  Idx->updatePreamble(Filename, AST.getASTContext(), AST.getPreprocessorPtr(),
-  AST.getCanonicalIncludes());
+  Idx->updatePreamble(Filename, /*Version=*/nullptr, AST.getASTContext(),
+  AST.getPreprocessorPtr(), AST.getCanonicalIncludes());
   Idx->updateMain(Filename, AST);
   return std::move(Idx);
 }
Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -40,7 +40,15 @@
 using ::testing::UnorderedElementsAre;
 
 MATCHER_P2(TUState, State, ActionName, "") {
-  return arg.Action.S == State && arg.Action.Name == ActionName;
+  if (arg.Action.S != State) {
+*result_listener << "state is " << arg.Action.S;
+return false;
+  }
+  if (arg.Action.Name != ActionName) {
+*result_listener << "name is " << arg.Action.Name;
+return false;
+  }

[PATCH] D75582: [clangd] Track document versions, include them with diags, enhance logs

2020-03-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, javed.absar, ilya-biryukov.
Herald added a project: clang.
sammccall updated this revision to Diff 248069.
sammccall added a comment.
sammccall added a reviewer: hokein.
sammccall updated this revision to Diff 248070.

Fix accidental default.


sammccall added a comment.

Fix incomplete message.


This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.

As such it's fairly invasive, for a logging patch :-\

Key decisions:

- at the LSP layer, we don't reqire the client to provide versions (LSP makes 
it mandatory but we never enforced it). If not provided, versions start at 0 
and increment. DraftStore handles this.
- don't propagate magically using contexts, but rather manually: addDocument -> 
ParseInputs -> (ParsedAST, Preamble, various callbacks) Context-propagation 
would hide the versions from ClangdServer, which would make producing good log 
messages hard
- within ClangdServer, treat versions as opaque and unordered. json::Value is a 
convenient type for this, and allows richer versions for embedders. They're 
"mandatory" but nullptr is a sensible default.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75582

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Compiler.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/ParsedAST.h
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/Preamble.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/FileIndex.h
  clang-tools-extra/clangd/test/diagnostic-category.test
  clang-tools-extra/clangd/test/diagnostics-no-tidy.test
  clang-tools-extra/clangd/test/diagnostics-notes.test
  clang-tools-extra/clangd/test/diagnostics.test
  clang-tools-extra/clangd/test/did-change-configuration-params.test
  clang-tools-extra/clangd/test/execute-command.test
  clang-tools-extra/clangd/test/fixits-codeaction.test
  clang-tools-extra/clangd/test/fixits-command.test
  clang-tools-extra/clangd/test/fixits-embed-in-diagnostic.test
  clang-tools-extra/clangd/test/path-mappings.test
  clang-tools-extra/clangd/test/semantic-highlighting.test
  clang-tools-extra/clangd/test/version.test
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/FileIndexTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.cpp
  clang-tools-extra/clangd/unittests/SyncAPI.h
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -838,7 +838,8 @@
   ElementsAre(Sym("foo.h", FooHeader.range(;
 
   // Only preamble is built, and no AST is built in this request.
-  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::No);
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), nullptr,
+ WantDiagnostics::No);
   // We build AST here, and it should use the latest preamble rather than the
   // stale one.
   EXPECT_THAT(
@@ -848,7 +849,8 @@
   // Reset test environment.
   runAddDocument(Server, FooCpp, FooWithHeader.code());
   // Both preamble and AST are built in this request.
-  Server.addDocument(FooCpp, FooWithoutHeader.code(), WantDiagnostics::Yes);
+  Server.addDocument(FooCpp, FooWithoutHeader.code(), nullptr,
+ WantDiagnostics::Yes);
   // Use the AST being built in above request.
   EXPECT_THAT(
   cantFail(runLocateSymbolAt(Server, FooCpp, FooWithoutHeader.point())),
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -97,16 +97,16 @@
 
 SymbolSlab TestTU::headerSymbols() const {
   auto AST = build();
-  return std::get<0>(indexHeaderSymbols(AST.getASTContext(),
-AST.getPreprocessorPtr(),
-AST.getCanonicalIncludes()));
+  return std::get<0>(
+  indexHeaderSymbols(/*Version=*/nullptr, AST.getASTContext(),
+ 

[PATCH] D75563: [clang][Parse] properly parse asm-qualifiers, asm inline

2020-03-03 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added inline comments.



Comment at: clang/test/Parser/asm-qualifiers.c:20
+
+void combinations(void) {
+  asm volatile inline("");

nickdesaulniers wrote:
> nathanchance wrote:
> > I'm probably being dense but what is intended to be tested differently 
> > between `combinations` and `permutations`? I assume the order of the 
> > qualifiers? Wouldn't it just be better to merge `combinations` into 
> > `permutations` or was there some deeper reasoning for the 
> > compartmentalization?
> `combinations` tests a combination of different `asm-qualifiers` together. 
> `permutations` are just permutations of the combinations that have not been 
> tested above. I may not even have my nomenclature correct.  Shall I combine 
> them?
I assume that you want permutations since you want to make sure that the 
ordering does not matter, right? If you just care about combinations then

```
  asm inline goto volatile("" foo);
  asm inline volatile goto("" foo);

  asm goto inline volatile("" foo);
  asm goto volatile inline("" foo);

  asm volatile goto inline("" foo); // note, this one should probably be 
added in permutations
  asm volatile inline goto("" foo);
``` 

could just be distilled down to one of those since they are the same 
combination of qualifiers (combinations do not care about order). I would say 
that moving `combinations` into `permutations` would be wise since 
`permutations` tests the same thing that `combinations` does and more.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75563/new/

https://reviews.llvm.org/D75563



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


[PATCH] D75579: [WIP] Replace MCTargetOptionsCommandFlags.inc and CommandFlags.inc by libraries

2020-03-03 Thread serge via Phabricator via cfe-commits
serge-sans-paille created this revision.
serge-sans-paille added reviewers: MaskRay, tstellar.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith, steven_wu, 
gbedwell, aheejin, hiraditya, mgorny, dschuff.
Herald added a reviewer: JDevlieghere.
Herald added a reviewer: andreadb.
Herald added projects: clang, LLVM.

MCTargetOptionsCommandFlags.inc and CommandFlags.inc are headers which contain 
cl::opt with static storage.
These headers are meant to be incuded by tools to make it easier to parametrize 
codegen/mc.

However, these headers are also included in at least two libraries: lldCommon 
and handle-llvm. As a result, when creating DYLIB, clang-cpp holds a reference 
to the options, and lldCommon holds another reference. Linking the two in a 
single executable, as zig does[0], results in a double registration.

This patch explores an other approach: instead of bundling headers, bindle them 
as non-component libs, that way we get shared libraries that are only loaded 
once.

It's a WIP, not fully tested, to gather feedback.

[0] https://bugzilla.redhat.com/show_bug.cgi?id=1756977#c5


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75579

Files:
  clang/tools/clang-fuzzer/handle-llvm/CMakeLists.txt
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  lld/Common/CMakeLists.txt
  lld/Common/TargetOptionsCommandFlags.cpp
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/CommandFlags.inc
  llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
  llvm/include/llvm/MC/MCTargetOptionsCommandFlags.inc
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CommandFlags/CMakeLists.txt
  llvm/lib/CodeGen/CommandFlags/CommandFlags.cpp
  llvm/lib/MC/CMakeLists.txt
  llvm/lib/MC/CommandFlags/CMakeLists.txt
  llvm/lib/MC/CommandFlags/MCTargetOptionsCommandFlags.cpp
  llvm/tools/dsymutil/CMakeLists.txt
  llvm/tools/dsymutil/DwarfStreamer.cpp
  llvm/tools/llc/CMakeLists.txt
  llvm/tools/llc/llc.cpp
  llvm/tools/lli/CMakeLists.txt
  llvm/tools/lli/lli.cpp
  llvm/tools/llvm-dwp/CMakeLists.txt
  llvm/tools/llvm-dwp/llvm-dwp.cpp
  llvm/tools/llvm-isel-fuzzer/CMakeLists.txt
  llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
  llvm/tools/llvm-lto/CMakeLists.txt
  llvm/tools/llvm-lto/llvm-lto.cpp
  llvm/tools/llvm-lto2/CMakeLists.txt
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/llvm-mc/CMakeLists.txt
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-mca/CMakeLists.txt
  llvm/tools/llvm-mca/llvm-mca.cpp
  llvm/tools/llvm-ml/CMakeLists.txt
  llvm/tools/llvm-ml/llvm-ml.cpp
  llvm/tools/llvm-opt-fuzzer/CMakeLists.txt
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
  llvm/tools/lto/CMakeLists.txt
  llvm/tools/lto/lto.cpp
  llvm/tools/opt/CMakeLists.txt
  llvm/tools/opt/opt.cpp
  llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
  llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp

Index: llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
===
--- llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
+++ llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
@@ -25,7 +25,7 @@
 #include "llvm/MC/MCRegisterInfo.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSubtargetInfo.h"
-#include "llvm/MC/MCTargetOptionsCommandFlags.inc"
+#include "llvm/MC/MCTargetOptionsCommandFlags.h"
 #include "llvm/PassAnalysisSupport.h"
 #include "llvm/Support/LEB128.h"
 #include "llvm/Support/TargetRegistry.h"
@@ -433,7 +433,7 @@
TripleName,
inconvertibleErrorCode());
 
-  MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
+  MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
   MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
   if (!MAI)
 return make_error("no asm info for target " + TripleName,
Index: llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
===
--- llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
+++ llvm/unittests/DebugInfo/DWARF/CMakeLists.txt
@@ -22,3 +22,4 @@
   )
 
 target_link_libraries(DebugInfoDWARFTests PRIVATE LLVMTestingSupport)
+target_link_libraries(DebugInfoDWARFTests PUBLIC LLVMMCCommandFlags)
Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -22,7 +22,7 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeWriterPass.h"
-#include "llvm/CodeGen/CommandFlags.inc"
+#include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/DataLayout.h"
@@ -471,16 +471,17 @@
StringRef FeaturesStr,
const TargetOptions ) {
   std::string Error;
-  const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
-

[PATCH] D75572: [Sema][SVE] Reject sizeof and alignof for sizeless types

2020-03-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

The planned changes to RequireCompleteType should catch this, right?  If we 
want a specialized diagnostic for sizeless types in RequireCompleteType, we 
should probably just pass it to RequireCompleteType.  (Otherwise, you'll end up 
with the "wrong" diagnostic in templates.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75572/new/

https://reviews.llvm.org/D75572



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


[PATCH] D75479: [clangd] go-to-def on names in comments etc that are used nearby.

2020-03-03 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks for putting this together, this is really neat and will indeed 
complement D72874  nicely!

I have one high-level comment about the interface, the rest are nits.




Comment at: clang-tools-extra/clangd/XRefs.cpp:337
+  const SourceManager  = TB.sourceManager();
+  auto Pos = SM.getDecomposedLoc(SpellingLoc);
+  llvm::StringRef Code = SM.getBufferData(Pos.first);

nit: I think separate names for the `FileID` and the position would read better



Comment at: clang-tools-extra/clangd/XRefs.cpp:369
+  auto Consider = [&](const syntax::Token ) {
+if(!(Tok.kind() == tok::identifier && Tok.text(SM) == Word))
+  return false;

nit: space after `if`



Comment at: clang-tools-extra/clangd/XRefs.h:56
 
+// If SpellingLoc points at a "word" that does not correspond to an expanded
+// token (e.g. in a comment, a string, or a PP disabled region), then try to

Do we want to bake this condition into the interface of this function, or would 
it be more appropriate to just tell the caller whether it's a real identifier 
token or not?

In particular, given our [plan for handling some dependent 
cases](https://reviews.llvm.org/D72874#1901722), the caller may want to do 
something along the lines of `if (notRealIdentifier || isDependent) { /* use 
the textual heuristic */ }`.



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:871
+TEST(LocateSymbol, NearbyIdentifier) {
+  const char *Tests[] = {
+R"cpp(

Tangentially related, but what do you think about the issue I raised in [this 
mailing list 
thread](https://lists.llvm.org/pipermail/clangd-dev/2019-November/000579.html) 
about testcase style?



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:903
+R"cpp(
+  // prefer nearest occurrence
+  int hello;

// (taking into account the penalty for going backwards)



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:930
+llvm::Optional Nearby;
+if (const auto*Tok = findNearbyIdentifier(
+cantFail(sourceLocationInMainFile(SM, T.point())), AST.getTokens()))

nit: space after `*`



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:937
+else
+  EXPECT_THAT(Nearby, T.range()) << Test;
+  }

`EXPECT_EQ`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75479/new/

https://reviews.llvm.org/D75479



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


[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 248059.
PaulkaToast marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75332/new/

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc.
+   #include// Allowed because it is provided by the compiler.
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc.
+
+
+This check is necesary because accidentally including sytem libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose ``dirent`` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-restrict-system-libc-headers `_,

[clang] ad18665 - PR45087: Fix check for emptiness when determining whether a trivial copy

2020-03-03 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-03-03T15:57:48-08:00
New Revision: ad18665e377824fd545ca81117b4953e60e2823c

URL: 
https://github.com/llvm/llvm-project/commit/ad18665e377824fd545ca81117b4953e60e2823c
DIFF: 
https://github.com/llvm/llvm-project/commit/ad18665e377824fd545ca81117b4953e60e2823c.diff

LOG: PR45087: Fix check for emptiness when determining whether a trivial copy
operation needs to read from its operand.

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 9a31b64eedda..1028ab96bfd2 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3047,15 +3047,22 @@ static void expandArray(APValue , unsigned Index) 
{
 /// is trivial. Note that this is never true for a union type with fields
 /// (because the copy always "reads" the active member) and always true for
 /// a non-class type.
+static bool isReadByLvalueToRvalueConversion(const CXXRecordDecl *RD);
 static bool isReadByLvalueToRvalueConversion(QualType T) {
   CXXRecordDecl *RD = T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
-  if (!RD || (RD->isUnion() && !RD->field_empty()))
-return true;
+  return !RD || isReadByLvalueToRvalueConversion(RD);
+}
+static bool isReadByLvalueToRvalueConversion(const CXXRecordDecl *RD) {
+  // FIXME: A trivial copy of a union copies the object representation, even if
+  // the union is empty.
+  if (RD->isUnion())
+return !RD->field_empty();
   if (RD->isEmpty())
 return false;
 
   for (auto *Field : RD->fields())
-if (isReadByLvalueToRvalueConversion(Field->getType()))
+if (!Field->isUnnamedBitfield() &&
+isReadByLvalueToRvalueConversion(Field->getType()))
   return true;
 
   for (auto  : RD->bases())
@@ -5460,22 +5467,6 @@ static bool HandleUnionActiveMemberChange(EvalInfo 
, const Expr *LHSExpr,
   return true;
 }
 
-/// Determine if a class has any fields that might need to be copied by a
-/// trivial copy or move operation.
-static bool hasFields(const CXXRecordDecl *RD) {
-  if (!RD || RD->isEmpty())
-return false;
-  for (auto *FD : RD->fields()) {
-if (FD->isUnnamedBitfield())
-  continue;
-return true;
-  }
-  for (auto  : RD->bases())
-if (hasFields(Base.getType()->getAsCXXRecordDecl()))
-  return true;
-  return false;
-}
-
 namespace {
 typedef SmallVector ArgVector;
 }
@@ -5546,7 +5537,8 @@ static bool HandleFunctionCall(SourceLocation CallLoc,
   const CXXMethodDecl *MD = dyn_cast(Callee);
   if (MD && MD->isDefaulted() &&
   (MD->getParent()->isUnion() ||
-   (MD->isTrivial() && hasFields(MD->getParent() {
+   (MD->isTrivial() &&
+isReadByLvalueToRvalueConversion(MD->getParent() {
 assert(This &&
(MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()));
 LValue RHS;
@@ -5633,7 +5625,8 @@ static bool HandleConstructorCall(const Expr *E, const 
LValue ,
   // actually read them.
   if (Definition->isDefaulted() && Definition->isCopyOrMoveConstructor() &&
   (Definition->getParent()->isUnion() ||
-   (Definition->isTrivial() && hasFields(Definition->getParent() {
+   (Definition->isTrivial() &&
+isReadByLvalueToRvalueConversion(Definition->getParent() {
 LValue RHS;
 RHS.setFrom(Info.Ctx, ArgValues[0]);
 return handleLValueToRValueConversion(

diff  --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 44b636a5b808..4c0cf109bee0 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -600,6 +600,10 @@ namespace CopyCtor {
   constexpr B c = b;
   static_assert(c.arr[2] == 3, "");
   static_assert(c.arr[7] == 0, "");
+
+  // OK: the copy ctor for X doesn't read any members.
+  struct X { struct Y {} y; } x1;
+  constexpr X x2 = x1;
 }
 
 constexpr int selfref[2][2][2] = {



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


[PATCH] D75486: [SVE] Make CompositeType not inherit from Type

2020-03-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

It's possible to mess with the way "cast<>" actually casts values by 
specializing the function template in question.  That, plus an appropriate 
classof implementations, should allow you to avoid the whole CompositeType::get 
thing.  See, for example, 
https://github.com/llvm/llvm-project/blob/8cf76e913b867a98a9843aa1b3d782632ed5d930/clang/include/clang/AST/DeclBase.h#L2490
 .

That said, both CompositeType and SequentialType are pretty useless.  
CompositeType especially: really, code dealing with it wants to answer one of 
two question: "is it legal to GEP index into this type", or "is it legal to 
extractvalue index into this type".  I tried to quickly throw together a patch 
to get rid of CompositeType, and it was roughly 100 lines changed.  I'll post 
something soon.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75486/new/

https://reviews.llvm.org/D75486



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


[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a subscriber: juliehockett.
MaskRay added a comment.

In D75332#1904264 , @PaulkaToast wrote:

> In D75332#1903570 , @MaskRay wrote:
>
> > > `RestrictSystemLibcHeadersCheck`
> >
> > As I commented previously, I think the checker name should be generalized, 
> > as it does not need to be coupled with llvm-libc. Other projects may have 
> > similar needs. For example, they don't want to accidentally include a 
> > system zlib.h -> they may ship a bundled zlib (say, in third_party/zlib/).
> >
> > Maybe `misc/` (or `portability/`) is more suitable?
>
>
> This is a simple check made precisely for llvm libc's use-case and doesn't 
> require a human maintained list. As I mentioned, if a more 
> general/configurable check is desired then porting out the 
> fuchsia-restrict-system-includes would make more sense as it already 
> implements white-lists and would handle the situation you described.




1. D43778  fuchsia-restrict-system-includes
2. This patch llvmlibc-restrict-system-libc-headers
3. The zlib use case I mentioned.

I think we should consider generalizing the existing 
fuchsia-restrict-system-includes (I did not know it). +@juliehockett

Fuchsia and llvm-libc developers can use a config once the general checker is 
ready.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75332/new/

https://reviews.llvm.org/D75332



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


[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst:18
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose `dirent` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime

Please use double-ticks for language constructs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75332/new/

https://reviews.llvm.org/D75332



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


[clang] bdad0a1 - PR45083: Mark statement expressions as being dependent if they appear in

2020-03-03 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-03-03T15:20:40-08:00
New Revision: bdad0a1b79273733df9acc1be4e992fa5d70ec56

URL: 
https://github.com/llvm/llvm-project/commit/bdad0a1b79273733df9acc1be4e992fa5d70ec56
DIFF: 
https://github.com/llvm/llvm-project/commit/bdad0a1b79273733df9acc1be4e992fa5d70ec56.diff

LOG: PR45083: Mark statement expressions as being dependent if they appear in
dependent contexts.

We previously assumed they were neither value- nor
instantiation-dependent under any circumstances, which would lead to
crashes and other misbehavior.

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaTemplate/dependent-expr.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index fcdb0b992134..87f9b883486a 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3960,14 +3960,14 @@ class StmtExpr : public Expr {
   Stmt *SubStmt;
   SourceLocation LParenLoc, RParenLoc;
 public:
-  // FIXME: Does type-dependence need to be computed 
diff erently?
-  // FIXME: Do we need to compute instantiation instantiation-dependence for
-  // statements? (ugh!)
   StmtExpr(CompoundStmt *substmt, QualType T,
-   SourceLocation lp, SourceLocation rp) :
+   SourceLocation lp, SourceLocation rp, bool InDependentContext) :
+// Note: we treat a statement-expression in a dependent context as always
+// being value- and instantiation-dependent. This matches the behavior of
+// lambda-expressions and GCC.
 Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
- T->isDependentType(), false, false, false),
-SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
+ T->isDependentType(), InDependentContext, InDependentContext, false),
+SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) {}
 
   /// Build an empty statement expression.
   explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2304a9718567..5739808753e3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4964,7 +4964,7 @@ class Sema final {
 LabelDecl *TheDecl);
 
   void ActOnStartStmtExpr();
-  ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
+  ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt,
SourceLocation RPLoc); // "({..})"
   // Handle the final expression in a statement expression.
   ExprResult ActOnStmtExprResult(ExprResult E);

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 52288318337d..0cf00f6ca15b 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6631,8 +6631,9 @@ ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) {
   if (Err)
 return std::move(Err);
 
-  return new (Importer.getToContext()) StmtExpr(
-  ToSubStmt, ToType, ToLParenLoc, ToRParenLoc);
+  return new (Importer.getToContext())
+  StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
+   E->isInstantiationDependent());
 }
 
 ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) {

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 584de6b87d90..b038e6935d87 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2655,7 +2655,8 @@ Parser::ParseParenExpression(ParenParseOption , 
bool stopIfCastExpr,
 
   // If the substmt parsed correctly, build the AST node.
   if (!Stmt.isInvalid()) {
-Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.get(), Tok.getLocation());
+Result = Actions.ActOnStmtExpr(getCurScope(), OpenLoc, Stmt.get(),
+   Tok.getLocation());
   } else {
 Actions.ActOnStmtExprError();
   }

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f50a77a40510..1870e440199d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13911,9 +13911,8 @@ void Sema::ActOnStmtExprError() {
   PopExpressionEvaluationContext();
 }
 
-ExprResult
-Sema::ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
-SourceLocation RPLoc) { // "({..})"
+ExprResult Sema::ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt,
+   SourceLocation RPLoc) { // "({..})"
   assert(SubStmt && isa(SubStmt) && "Invalid action 
invocation!");
   CompoundStmt *Compound = cast(SubStmt);
 
@@ -13942,9 +13941,18 @@ Sema::ActOnStmtExpr(SourceLocation LPLoc, Stmt 
*SubStmt,
 }
   }
 
+  bool IsDependentContext = false;
+  if (S)
+

[PATCH] D75486: [SVE] Make CompositeType not inherit from Type

2020-03-03 Thread Christopher Tetreault via Phabricator via cfe-commits
ctetreau updated this revision to Diff 248050.
ctetreau added a comment.

Cleaned up code, resolved clang-format lints


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75486/new/

https://reviews.llvm.org/D75486

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/unittests/CodeGen/CodeGenExternalTest.cpp
  llvm/include/llvm/IR/Constants.h
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/include/llvm/IR/GetElementPtrTypeIterator.h
  llvm/lib/Analysis/BasicAliasAnalysis.cpp
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/FuzzMutate/Operations.cpp
  llvm/lib/IR/ConstantFold.cpp
  llvm/lib/IR/Constants.cpp
  llvm/lib/IR/Core.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Linker/IRMover.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp
  llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
  llvm/lib/Transforms/IPO/GlobalOpt.cpp
  llvm/lib/Transforms/IPO/StripSymbols.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/lib/Transforms/Utils/FunctionComparator.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3130,7 +3130,7 @@
   unsigned N = 1;
   Type *EltTy = T;
 
-  while (isa(EltTy)) {
+  while (CompositeType::is(EltTy)) {
 if (auto *ST = dyn_cast(EltTy)) {
   // Check that struct is homogeneous.
   for (const auto *Ty : ST->elements())
@@ -3139,7 +3139,7 @@
   N *= ST->getNumElements();
   EltTy = *ST->element_begin();
 } else {
-  auto *SeqT = cast(EltTy);
+  auto *SeqT = cast(CompositeType::get(EltTy));
   N *= SeqT->getNumElements();
   EltTy = SeqT->getElementType();
 }
Index: llvm/lib/Transforms/Utils/FunctionComparator.cpp
===
--- llvm/lib/Transforms/Utils/FunctionComparator.cpp
+++ llvm/lib/Transforms/Utils/FunctionComparator.cpp
@@ -478,8 +478,8 @@
 
   case Type::ArrayTyID:
   case Type::VectorTyID: {
-auto *STyL = cast(TyL);
-auto *STyR = cast(TyR);
+auto *STyL = cast(CompositeType::get(TyL));
+auto *STyR = cast(CompositeType::get(TyR));
 if (STyL->getNumElements() != STyR->getNumElements())
   return cmpNumbers(STyL->getNumElements(), STyR->getNumElements());
 return cmpTypes(STyL->getElementType(), STyR->getElementType());
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -3511,7 +3511,8 @@
   (DL.getTypeAllocSize(Ty) - Offset) < Size)
 return nullptr;
 
-  if (SequentialType *SeqTy = dyn_cast(Ty)) {
+  if (SequentialType *SeqTy =
+  dyn_cast_or_null(CompositeType::get(Ty, false))) {
 Type *ElementTy = SeqTy->getElementType();
 uint64_t ElementSize = DL.getTypeAllocSize(ElementTy);
 uint64_t NumSkippedElements = Offset / ElementSize;
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1934,7 +1934,7 @@
 if (J > 0) {
   if (J == 1) {
 CurTy = Op1->getSourceElementType();
-  } else if (auto *CT = dyn_cast(CurTy)) {
+  } else if (auto *CT = CompositeType::get(CurTy, false)) {
 CurTy = CT->getTypeAtIndex(Op1->getOperand(J));
   } else {
 CurTy = nullptr;
Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2427,10 +2427,10 @@
 // to a getelementptr X, 0, 0, 0...  turn it into the appropriate gep.
 // This can enhance SROA and other transforms that want type-safe pointers.
 unsigned NumZeros = 0;
-while (SrcElTy != DstElTy &&
-   isa(SrcElTy) && !SrcElTy->isPointerTy() &&
+while (SrcElTy != DstElTy && CompositeType::is(SrcElTy) &&
+   !SrcElTy->isPointerTy() &&
SrcElTy->getNumContainedTypes() /* not "{}" */) {
-  SrcElTy = cast(SrcElTy)->getTypeAtIndex(0U);
+  SrcElTy = CompositeType::get(SrcElTy)->getTypeAtIndex(0U);
   ++NumZeros;
 }
 
Index: llvm/lib/Transforms/IPO/StripSymbols.cpp

[PATCH] D62962: Clang implementation of sizeless types

2020-03-03 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a comment.

In D62962#1887242 , @efriedma wrote:

> Can you make a list of the complete stack of patches here?


Sorry for the slow reply, I was out last week.  I've updated the stack for this 
revision: the only parent patch is D62961 .  
As you'll have noticed from the spam (sorry), I've also uploaded the start of 
an alternative series of patches that achieve the same thing.  The original 
series (this one) started by making the SVE types incomplete and then enabled 
things that are actually valid for SVE types.  The new series instead starts 
from the status quo, where we accept all valid code and lots of invalid code.  
It then gradually forbids all the known invalid uses.  The new series also 
avoids the "definite/indefinite" classification and just sticks to 
sized/sizeless and complete/incomplete.

The start of the new stack is D75570  and the 
current end is D75573 , but the full series 
currently has 23 patches.  All patches but the last one are in a similar style 
to D75572  and D75573 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62962/new/

https://reviews.llvm.org/D62962



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


[PATCH] D72874: [clangd] Add a textual fallback for go-to-definition

2020-03-03 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked 6 inline comments as done.
nridge added a comment.

I'm posting some partial responses because I have some questions (really just 
one, about fuzzy matching).

In general the comments seem reasonable and I plan to address all of them.

(I've marked some comments as done because I've addressed them locally. I'm not 
uploading a revised patch yet because it wouldn't be very interesting.)




Comment at: clang-tools-extra/clangd/XRefs.cpp:226
+
+std::vector navigationFallback(ParsedAST ,
+  const SymbolIndex *Index,

sammccall wrote:
> this function should have a high-level comment describing the strategy and 
> the limitations (e.g. idea of extending it to resolve nearby matching tokens).
> 
> A name like `locateSymbolNamedTextuallyAt` would better describe what this 
> does, rather than what its caller does.
> 
> I would strongly consider exposing this function publicly for the detailed 
> tests, and only smoke-testing it through `locateSymbolAt`. Having to break 
> the AST in tests or otherwise rely on the "primary" logic not working is 
> brittle and hard to verify.
> I would strongly consider exposing this function publicly for the detailed 
> tests, and only smoke-testing it through locateSymbolAt. Having to break the 
> AST in tests or otherwise rely on the "primary" logic not working is brittle 
> and hard to verify.

I was going to push back against this, but I ended up convincing myself that 
your suggestion is better :)

For the record, the consideration that convinced me was:

Suppose in the future we add fancier AST-based logic that handles a case like 
`T().foo()` (for example, by surveying types for which `T` is actually 
substituted, and offering `foo()` inside those types). If all we're testing is 
"navigation works for this case" rather than "navigation works for this case 
//via the AST-based mechanism//", we could regress the AST logic but have our 
test still pass because the testcase is simple enough that the text-based 
navigation fallback (that we're adding here) works as well.



Comment at: clang-tools-extra/clangd/XRefs.cpp:252
+  Index->fuzzyFind(Req, [&](const Symbol ) {
+auto Loc = symbolToLocation(Sym, MainFilePath);
+if (!Loc) {

sammccall wrote:
> I'm not sure why we're using SymbolToLocation here:
>  - Main file URI check: the `Symbol` has URIs. They need to be canonicalized 
> to file URIs before comparison. This allows checking both decl and def 
> location.
>  - PreferredDeclaration and Definition can be more easily set directly from 
> the `Symbol`
Well the `Symbol` has `SymbolLocation`s and we need protocol `Location`s, so we 
have to use something to convert them. Other places that perform such 
conversion use `symbolToLocation()`, so I reused it.

But you're right that `symbolToLocation()` also has some "pick the definition 
or the declaration" logic which is less appropriate here. I can factor out the 
`SymbolLocation` --> `Location` conversion logic from `symbolToLocation()`, and 
just use that here.



Comment at: clang-tools-extra/clangd/XRefs.cpp:258
+
+// For now, only consider exact name matches, including case.
+// This is to avoid too many false positives.

sammccall wrote:
> I wouldn't bother qualifying this as "for now". Any code is subject to change 
> in the future, but requiring an exact name match for index-based results 
> seems more like a design decision than a fixme.
Do we want to rule out the possibility of handling typos in an identifier name 
in a comment (in cases where we have high confidence in the match, e.g. a long 
/ unique name, small edit distance, only one potential match) in the future?

This is also relevant to whether we want to keep the `FuzzyMatcher` or not.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72874/new/

https://reviews.llvm.org/D72874



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


[PATCH] D75574: RFC: Implement objc_direct_protocol attribute to remove protocol metadata

2020-03-03 Thread Nathan Lanza via Phabricator via cfe-commits
lanza created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Motivated by the new objc_direct attribute, this change aims to limit
metadata generation from Protocols that the programmer knows isn't
going to be used at runtime. This attribute simply causes the frontend
to not generate any protocol metadata entries (e.g. OBJC_CLASS_NAME,
_OBJC_$_PROTOCOL_INSTANCE_METHDOS, _OBJC_PROTOCOL, etc) for a protocol
marked with `__attribute__((objc_direct))`.

There are a few APIs used to retrieve a protocol at runtime.
`@protocol(SomeProtocol)` will now error out of the requested protocol
is marked with attribute. `objc_getProtocol` will returl `NULL` which
is consistent with the behavior of a non-existing protocol.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75574

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/ObjCRuntime.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/test/CodeGenObjC/static-protocol.m

Index: clang/test/CodeGenObjC/static-protocol.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/static-protocol.m
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -o - \
+// RUN: | FileCheck %s
+// RUN: not %clang_cc1 -emit-llvm -fobjc-arc -triple x86_64-apple-darwin10 %s -DPROTOEXPR -o - 2>&1 \
+// RUN: | FileCheck -check-prefix=PROTOEXPR %s
+
+__attribute__((objc_root_class))
+@interface Root
+@end
+@implementation Root
+@end
+
+// Confirm that we're not emitting protocol information for the
+// CHECK-NOT: OBJC_CLASS_NAME{{.*}}StaticProtocol
+// CHECK-NOT: _OBJC_$_PROTOCOL_INSTANCE_METHODS_StaticProtocol
+// CHECK-NOT: _OBJC_$_PROTOCOL_CLASS_METHODS_StaticProtocol
+// CHECK-NOT: _OBJC_PROTOCOL_$_StaticProtocol
+// CHECK-NOT: _OBJC_LABEL_PROTOCOL_$_StaticProtocol
+// CHECK-NOT: _OBJC_CLASS_PROTOCOLS_$_StaticImplementer
+// CHECK-NOT: @llvm.compiler.used {{.*}}StaticProtocol
+__attribute__((objc_static_protocol))
+@protocol StaticProtocol
+- (void)doThing;
++ (void)doClassThing;
+@end
+// CHECK: @"_OBJC_METACLASS_RO_$_StaticImplementer" {{.*}} %struct._objc_protocol_list* null
+// CHECK: @"_OBJC_CLASS_RO_$_StaticImplementer" {{.*}} %struct._objc_protocol_list* null
+@interface StaticImplementer : Root 
+- (void)doThing;
++ (void)doClassThing;
+@end
+
+@implementation StaticImplementer
+- (void)doThing {}
++ (void)doClassThing {}
+@end
+
+void useStatic(StaticImplementer *si) {
+  [si doThing];
+  [StaticImplementer doClassThing];
+
+#ifdef PROTOEXPR
+// PROTOEXPR: can't use a protocol declared 'objc_static_protocol' in a @protocol expression
+  Protocol* p = @protocol(StaticProtocol);
+#endif
+}
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -1280,6 +1280,8 @@
 Diag(ProtoLoc, diag::err_undeclared_protocol) << ProtocolId;
 return true;
   }
+  if (PDecl->isStaticProtocol())
+Diag(ProtoLoc, diag::err_objc_static_protocol_in_protocol_expr) << PDecl;
   if (!PDecl->hasDefinition()) {
 Diag(ProtoLoc, diag::err_atprotocol_protocol) << PDecl;
 Diag(PDecl->getLocation(), diag::note_entity_declared_at) << PDecl;
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2604,6 +2604,15 @@
 D->addAttr(newAttr);
 }
 
+static void handleObjCStaticProtocolAttr(Sema , Decl *D,
+ const ParsedAttr ) {
+  if (S.getLangOpts().ObjCRuntime.allowsStaticProtocols()) {
+handleSimpleAttribute(S, D, AL);
+  } else {
+S.Diag(AL.getLoc(), diag::warn_objc_static_protocol_ignored) << AL;
+  }
+}
+
 static void handleObjCDirectAttr(Sema , Decl *D, const ParsedAttr ) {
   // objc_direct cannot be set on methods declared in the context of a protocol
   if (isa(D->getDeclContext())) {
@@ -7095,6 +7104,9 @@
   case ParsedAttr::AT_ObjCDirect:
 handleObjCDirectAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_ObjCStaticProtocol:
+handleObjCStaticProtocolAttr(S, D, AL);
+break;
   case ParsedAttr::AT_ObjCDirectMembers:
 handleObjCDirectMembersAttr(S, D, AL);
 handleSimpleAttribute(S, D, AL);
Index: clang/lib/CodeGen/CGObjCMac.cpp
===
--- clang/lib/CodeGen/CGObjCMac.cpp
+++ clang/lib/CodeGen/CGObjCMac.cpp
@@ -3031,7 +3031,8 @@
   // it now. Otherwise do nothing, the protocol objects are lazily
   // emitted.
   if (Protocols.count(PD->getIdentifier()))
-GetOrEmitProtocol(PD);
+if (!PD->isStaticProtocol())
+  

[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast added a comment.

In D75332#1903570 , @MaskRay wrote:

> > `RestrictSystemLibcHeadersCheck`
>
> As I commented previously, I think the checker name should be generalized, as 
> it does not need to be coupled with llvm-libc. Other projects may have 
> similar needs. For example, they don't want to accidentally include a system 
> zlib.h -> they may ship a bundled zlib (say, in third_party/zlib/).
>
> Maybe `misc/` (or `portability/`) is more suitable?


This is a simple check made precisely for llvm libc's use-case and doesn't 
require a human maintained list. As I mentioned, if a more general/configurable 
check is desired then porting out the fuchsia-restrict-system-includes would 
make more sense as it already implements white-lists and would handle the 
situation you described.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75332/new/

https://reviews.llvm.org/D75332



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


[PATCH] D75332: [clang-tidy] Add module for llvm-libc and restrict-system-libc-header-check.

2020-03-03 Thread Paula Toth via Phabricator via cfe-commits
PaulkaToast updated this revision to Diff 248044.
PaulkaToast marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75332/new/

https://reviews.llvm.org/D75332

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidyForceLinker.h
  clang-tools-extra/clang-tidy/llvmlibc/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvmlibc/LLVMLibcTidyModule.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
  
clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t
+
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdio.h not allowed
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header stdlib.h not allowed
+#include "string.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system libc header string.h not allowed
+#include "stdatomic.h"
+#include 
+// Compiler provided headers should not throw warnings.
Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc-restrict-system-libc-headers-transitive.cpp
@@ -0,0 +1,6 @@
+// RUN: %check_clang_tidy %s llvmlibc-restrict-system-libc-headers %t \
+// RUN:   -- -header-filter=.* \
+// RUN:   -- -I %S/Inputs/llvmlibc
+
+#include "transitive.h"
+// CHECK-MESSAGES: :1:1: warning: system libc header math.h not allowed, transitively included from {{.*}}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/llvmlibc/transitive.h
@@ -0,0 +1 @@
+#include 
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -68,6 +68,7 @@
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
+``llvmlibc-``  Checks related to the LLVM-libc coding standards.
 ``misc-``  Checks that we didn't have a better category for.
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
Index: clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvmlibc-restrict-system-libc-headers.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - llvmlibc-restrict-system-libc-headers
+
+llvmlibc-restrict-system-libc-headers
+=
+
+Finds includes of system libc headers not provided by the compiler within
+llvm-libc implementations.
+
+.. code-block:: c++
+
+   #include // Not allowed because it is part of system libc.
+   #include// Allowed because it is provided by the compiler.
+   #include "internal/stdio.h"   // Allowed because it is NOT part of system libc.
+
+
+This check is necesary because accidentally including sytem libc headers can
+lead to subtle and hard to detect bugs. For example consider a system libc
+whose `dirent` struct has slightly different field ordering than llvm-libc.
+While this will compile successfully, this can cause issues during runtime
+because they are ABI incompatible.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -187,6 +187,7 @@
`llvm-prefer-isa-or-dyn-cast-in-conditionals `_, "Yes"
`llvm-prefer-register-over-unsigned `_, "Yes"
`llvm-twine-local `_, "Yes"
+   `llvmlibc-restrict-system-libc-headers `_,

[PATCH] D75573: [Sema][SVE] Reject aligned/_Alignas for sizeless types

2020-03-03 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: sdesmalen, efriedma, rovka, rjmccall.
Herald added subscribers: cfe-commits, psnobl, rkruppe, tschuett.
Herald added a project: clang.

A previous patch rejected alignof for sizeless types.  This patch
extends that to cover the "aligned" attribute and _Alignas.  Since
sizeless types are not meant to be used for long-term data, cannot
be used in aggregates, and cannot have static storage duration,
there shouldn't be any need to fiddle with their alignment.

Like with alignof, this is a conservative position that can be
relaxed in future if it turns out to be too restrictive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75573

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -63,6 +63,9 @@
   svint8_t local_int8;
   svint16_t local_int16;
 
+  svint8_t __attribute__((aligned)) aligned_int8_1; // expected-error 
{{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
+  svint8_t __attribute__((aligned(4))) aligned_int8_2; // expected-error 
{{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
+  svint8_t _Alignas(int) aligned_int8_3; // expected-error {{'_Alignas' 
attribute cannot be applied to sizeless type 'svint8_t'}}
   int _Alignas(svint8_t) aligned_int; // expected-error {{invalid application 
of 'alignof' to sizeless type 'svint8_t'}}
 
   // Using pointers to sizeless data isn't wrong here, but because the
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -54,6 +54,9 @@
   svint8_t local_int8;
   svint16_t local_int16;
 
+  svint8_t __attribute__((aligned)) aligned_int8_1; // expected-error 
{{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
+  svint8_t __attribute__((aligned(4))) aligned_int8_2; // expected-error 
{{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
+  svint8_t _Alignas(int) aligned_int8_3; // expected-error {{'_Alignas' 
attribute cannot be applied to sizeless type 'svint8_t'}}
   int _Alignas(svint8_t) aligned_int; // expected-error {{invalid application 
of 'alignof' to sizeless type 'svint8_t'}}
 
   // Using pointers to sizeless data isn't wrong here, but because the
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3868,6 +3868,7 @@
   //   not specify an alignment that is less strict than the alignment that
   //   would otherwise be required for the entity being declared.
   AlignedAttr *AlignasAttr = nullptr;
+  AlignedAttr *LastAlignedAttr = nullptr;
   unsigned Align = 0;
   for (auto *I : D->specific_attrs()) {
 if (I->isAlignmentDependent())
@@ -3875,9 +3876,13 @@
 if (I->isAlignas())
   AlignasAttr = I;
 Align = std::max(Align, I->getAlignment(Context));
+LastAlignedAttr = I;
   }
 
-  if (AlignasAttr && Align) {
+  if (Align && DiagTy->isSizelessType()) {
+Diag(LastAlignedAttr->getLocation(), diag::err_attribute_sizeless_type)
+  << LastAlignedAttr << DiagTy;
+  } else if (AlignasAttr && Align) {
 CharUnits RequestedAlign = Context.toCharUnitsFromBits(Align);
 CharUnits NaturalAlign = Context.getTypeAlignInChars(UnderlyingTy);
 if (NaturalAlign > RequestedAlign)
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2801,6 +2801,8 @@
   "redeclaration has different alignment requirement (%1 vs %0)">;
 def err_alignas_underaligned : Error<
   "requested alignment is less than minimum alignment of %1 for type %0">;
+def err_attribute_sizeless_type : Error<
+  "%0 attribute cannot be applied to sizeless type %1">;
 def err_attribute_argument_n_type : Error<
   "%0 attribute requires parameter %1 to be %select{int or bool|an integer "
   "constant|a string|an identifier}2">;


Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -63,6 +63,9 @@
   svint8_t local_int8;
   svint16_t local_int16;
 
+  svint8_t __attribute__((aligned)) aligned_int8_1; // expected-error {{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
+  svint8_t __attribute__((aligned(4))) aligned_int8_2; // expected-error {{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
+  svint8_t _Alignas(int) aligned_int8_3; // 

[PATCH] D75571: [Sema][SVE] Add tests for valid and invalid type usage

2020-03-03 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: sdesmalen, efriedma, rovka, rjmccall.
Herald added subscribers: cfe-commits, psnobl, jfb, rkruppe, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: clang.
rsandifo-arm added a child revision: D75572: [Sema][SVE] Reject sizeof and 
alignof for sizeless types.

This patch adds C and C++ tests for various uses of SVE types.
The tests cover valid uses that are already (correctly) accepted and
invalid uses that are already (correctly) rejected.  Later patches
will expand the tests as they fix other cases.[*]

Some of the tests for invalid uses aren't obviously related to
scalable vectors.  Part of the reason for having them is to make
sure that the quality of the error message doesn't regress once/if
the types are treated as incomplete types.

[X] These later patches all fix invalid uses that are being incorrectly 
accepted.  I don't know of any cases in which valid uses are being incorrectly 
rejected.  In other words, this series is all about diagnosing invalid code 
rather than enabling something new.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75571

Files:
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -0,0 +1,447 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++98 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=gnu++98 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++11 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=gnu++11 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++14 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=gnu++14 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++17 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=gnu++17 %s
+
+namespace std { struct type_info; }
+
+typedef __SVInt8_t svint8_t;
+typedef __SVInt16_t svint16_t;
+
+svint8_t *global_int8_ptr;
+extern svint8_t *extern_int8_ptr;
+static svint8_t *static_int8_ptr;
+
+typedef svint8_t int8_typedef;
+typedef svint8_t *int8_ptr_typedef;
+
+void pass_int8(svint8_t); // expected-note {{no known conversion}}
+
+svint8_t return_int8();
+
+typedef svint8_t vec_int8_a __attribute__((vector_size(64))); // expected-error {{invalid vector element type}}
+typedef svint8_t vec_int8_b __attribute__((ext_vector_type(4))); // expected-error {{invalid vector element type}}
+
+void dump(const volatile void *);
+
+void overf(svint8_t);
+void overf(svint16_t);
+
+void overf8(svint8_t); // expected-note + {{not viable}}
+void overf8(int); // expected-note + {{not viable}}
+
+void overf16(svint16_t); // expected-note + {{not viable}}
+void overf16(int); // expected-note + {{not viable}}
+
+void varargs(int, ...);
+
+void unused() {
+  svint8_t unused_int8; // expected-warning {{unused}}
+}
+
+struct incomplete_struct *incomplete_ptr;
+
+void func(int sel) {
+  svint8_t local_int8;
+  svint16_t local_int16;
+
+  // Using pointers to sizeless data isn't wrong here, but because the
+  // type is incomplete, it doesn't provide any alignment guarantees.
+  _Static_assert(__atomic_is_lock_free(1, _int8) == __atomic_is_lock_free(1, incomplete_ptr), "");
+  _Static_assert(__atomic_is_lock_free(2, _int8) == __atomic_is_lock_free(2, incomplete_ptr), ""); // expected-error {{static_assert expression is not an integral constant expression}}
+  _Static_assert(__atomic_always_lock_free(1, _int8) == __atomic_always_lock_free(1, incomplete_ptr), "");
+
+  local_int8; // expected-warning {{expression result unused}}
+
+  (void)local_int8;
+
+  local_int8, 0; // expected-warning + {{expression result unused}}
+
+  0, local_int8; // expected-warning + {{expression result unused}}
+
+  svint8_t init_int8 = local_int8;
+  svint8_t bad_init_int8 = for; // expected-error {{expected expression}}
+
+#if __cplusplus >= 201103L
+  int empty_brace_init_int = {};
+#else
+  int empty_brace_init_int = {}; // expected-error {{scalar initializer cannot be empty}}
+#endif
+
+  const svint8_t const_int8 = local_int8; // expected-note {{declared const here}}
+  const svint8_t uninit_const_int8; // expected-error {{default initialization of an 

[PATCH] D75563: [clang][Parse] properly parse asm-qualifiers, asm inline

2020-03-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/Parser/asm-qualifiers.c:20
+
+void combinations(void) {
+  asm volatile inline("");

nathanchance wrote:
> I'm probably being dense but what is intended to be tested differently 
> between `combinations` and `permutations`? I assume the order of the 
> qualifiers? Wouldn't it just be better to merge `combinations` into 
> `permutations` or was there some deeper reasoning for the 
> compartmentalization?
`combinations` tests a combination of different `asm-qualifiers` together. 
`permutations` are just permutations of the combinations that have not been 
tested above. I may not even have my nomenclature correct.  Shall I combine 
them?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75563/new/

https://reviews.llvm.org/D75563



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


[PATCH] D75570: [AST][SVE] Add new Type queries for sizeless types

2020-03-03 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm added a comment.

At the moment the queries just return true for SVE types, so an obvious 
alternative would be to check specifically for SVE types.  The sizeless type 
concept is more general than that though.  E.g. my understanding from:

  https://gcc.gnu.org/ml/gcc/2019-11/msg00092.html

is that the RVV folks intend to use this too (both for clang and gcc).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75570/new/

https://reviews.llvm.org/D75570



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


[PATCH] D75572: [Sema][SVE] Reject sizeof and alignof for sizeless types

2020-03-03 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: sdesmalen, efriedma, rovka, rjmccall.
Herald added subscribers: cfe-commits, psnobl, rkruppe, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: clang.
rsandifo-arm added parent revisions: D75570: [AST][SVE] Add new Type queries 
for sizeless types, D75571: [Sema][SVE] Add tests for valid and invalid type 
usage.

clang current accepts:

  void foo1(__SVInt8_t *x, __SVInt8_t *y) { *x = *y; }
  void foo2(__SVInt8_t *x, __SVInt8_t *y) {
memcpy(y, x, sizeof(__SVInt8_t));
  }

The first function is valid ACLE code and generates correct LLVM IR.
The second function is invalid ACLE code and generates a zero-length
memcpy.

The patch means that we diagnose the problem in the second case,
rather than silently generating incorrect code.

There's no similar wrong-code bug for alignof.  However, the SVE ACLE
conservatively treats alignof in the same way as sizeof, just as the
C++ standard does for incomplete types.  The idea is that layout of
sizeless types is an implementation property and isn't defined at
the language level.

We could relax the alignof rules in future if they turn out to be
too restrictive.  It would be harder to go the other way though,
and forbid alignof after previously treating it as valid.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75572

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/aarch64-sve-types.c
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -19,6 +19,20 @@
 typedef svint8_t int8_typedef;
 typedef svint8_t *int8_ptr_typedef;
 
+int sizeof_int8 = sizeof(svint8_t); // expected-error {{invalid application of 'sizeof' to sizeless type 'svint8_t'}}
+int sizeof_int8_var = sizeof(*extern_int8_ptr); // expected-error {{invalid application of 'sizeof' to sizeless type 'svint8_t'}}
+int sizeof_int8_var_ptr = sizeof(extern_int8_ptr);
+
+#if __cplusplus >= 201103L
+int alignof_int8 = alignof(svint8_t); // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}}
+int alignof_int8_var = alignof(*extern_int8_ptr); // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}} expected-warning {{GNU extension}}
+int alignof_int8_var_ptr = alignof(extern_int8_ptr); // expected-warning {{GNU extension}}
+#else
+int alignof_int8 = _Alignof(svint8_t); // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}}
+int alignof_int8_var = _Alignof(*extern_int8_ptr); // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}} expected-warning {{GNU extension}}
+int alignof_int8_var_ptr = _Alignof(extern_int8_ptr); // expected-warning {{GNU extension}}
+#endif
+
 void pass_int8(svint8_t); // expected-note {{no known conversion}}
 
 svint8_t return_int8();
@@ -49,6 +63,8 @@
   svint8_t local_int8;
   svint16_t local_int16;
 
+  int _Alignas(svint8_t) aligned_int; // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}}
+
   // Using pointers to sizeless data isn't wrong here, but because the
   // type is incomplete, it doesn't provide any alignment guarantees.
   _Static_assert(__atomic_is_lock_free(1, _int8) == __atomic_is_lock_free(1, incomplete_ptr), "");
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -15,6 +15,14 @@
 typedef svint8_t int8_typedef;
 typedef svint8_t *int8_ptr_typedef;
 
+int sizeof_int8 = sizeof(svint8_t); // expected-error {{invalid application of 'sizeof' to sizeless type 'svint8_t'}}
+int sizeof_int8_var = sizeof(*extern_int8_ptr); // expected-error {{invalid application of 'sizeof' to sizeless type 'svint8_t'}}
+int sizeof_int8_var_ptr = sizeof(extern_int8_ptr);
+
+int alignof_int8 = _Alignof(svint8_t); // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}}
+int alignof_int8_var = _Alignof(*extern_int8_ptr); // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}} expected-warning {{GNU extension}}
+int alignof_int8_var_ptr = _Alignof(extern_int8_ptr); // expected-warning {{GNU extension}}
+
 void pass_int8(svint8_t); // expected-note {{passing argument to parameter here}}
 
 svint8_t return_int8();
@@ -46,6 +54,8 @@
   svint8_t local_int8;
   svint16_t local_int16;
 
+  int _Alignas(svint8_t) aligned_int; // expected-error {{invalid application of 'alignof' to sizeless type 'svint8_t'}}
+
   // Using pointers to sizeless data isn't wrong here, but because the
   // type is incomplete, it doesn't provide any alignment guarantees.
   _Static_assert(__atomic_is_lock_free(1, _int8) == __atomic_is_lock_free(1, incomplete_ptr), 

[PATCH] D75570: [AST][SVE] Add new Type queries for sizeless types

2020-03-03 Thread Richard Sandiford via Phabricator via cfe-commits
rsandifo-arm created this revision.
rsandifo-arm added reviewers: sdesmalen, efriedma, rovka, rjmccall.
Herald added subscribers: cfe-commits, psnobl, rkruppe, kristof.beyls, 
tschuett, mgorny.
Herald added a reviewer: rengolin.
Herald added a project: clang.
rsandifo-arm added a comment.
rsandifo-arm added a child revision: D75572: [Sema][SVE] Reject sizeof and 
alignof for sizeless types.

At the moment the queries just return true for SVE types, so an obvious 
alternative would be to check specifically for SVE types.  The sizeless type 
concept is more general than that though.  E.g. my understanding from:

  https://gcc.gnu.org/ml/gcc/2019-11/msg00092.html

is that the RVV folks intend to use this too (both for clang and gcc).


One of the defining features of the SVE ACLE types is that they
are "sizeless"; see the SVE ACLE spec:

  https://developer.arm.com/docs/100987//arm-c-language-extensions-for-sve

or the email message:

  http://lists.llvm.org/pipermail/cfe-dev/2019-June/062523.html

for a fuller definition of what that means.

This patch adds two associated type queries:

- isSizelessBuiltinType asks specifically about types that are built into 
clang.  It is effectively an enum range check.

- isSizelessType instead tests for any type that has the "sizeless" type 
property.  At the moment it only returns true for the built-in types, but it 
seems better not to hard-code that assumption throughout the codebase.  (E.g. 
we could in principle support some form of user-defined sizeless types in 
future.  Even if that seems unlikely and never actually happens, the 
possibility at least exists.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75570

Files:
  clang/include/clang/AST/CanonicalType.h
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/SizelessTypesTest.cpp

Index: clang/unittests/AST/SizelessTypesTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/SizelessTypesTest.cpp
@@ -0,0 +1,83 @@
+//===- unittests/AST/SizelessTypesTest.cpp --- Sizeless type tests ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file contains tests for clang::Type queries related to sizeless types.
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+
+struct SizelessTypeTester : public ::testing::Test {
+  // Declare an incomplete structure type.
+  std::unique_ptr AST =
+tooling::buildASTFromCodeWithArgs("struct foo;",
+  {"-target", "aarch64-linux-gnu"});
+  ASTContext  = AST->getASTContext();
+  TranslationUnitDecl  = *Ctx.getTranslationUnitDecl();
+  TypeDecl *Foo = cast(TU.lookup(("foo")).front());
+  const Type *FooTy = Foo->getTypeForDecl();
+};
+
+TEST_F(SizelessTypeTester, TestSizelessBuiltin) {
+  ASSERT_TRUE(Ctx.SveInt8Ty->isSizelessBuiltinType());
+  ASSERT_TRUE(Ctx.SveInt16Ty->isSizelessBuiltinType());
+  ASSERT_TRUE(Ctx.SveInt32Ty->isSizelessBuiltinType());
+  ASSERT_TRUE(Ctx.SveInt64Ty->isSizelessBuiltinType());
+
+  ASSERT_TRUE(Ctx.SveUint8Ty->isSizelessBuiltinType());
+  ASSERT_TRUE(Ctx.SveUint16Ty->isSizelessBuiltinType());
+  ASSERT_TRUE(Ctx.SveUint32Ty->isSizelessBuiltinType());
+  ASSERT_TRUE(Ctx.SveUint64Ty->isSizelessBuiltinType());
+
+  ASSERT_TRUE(Ctx.SveFloat16Ty->isSizelessBuiltinType());
+  ASSERT_TRUE(Ctx.SveFloat32Ty->isSizelessBuiltinType());
+  ASSERT_TRUE(Ctx.SveFloat64Ty->isSizelessBuiltinType());
+
+  ASSERT_TRUE(Ctx.SveBoolTy->isSizelessBuiltinType());
+
+  ASSERT_FALSE(Ctx.VoidTy->isSizelessBuiltinType());
+  ASSERT_FALSE(Ctx.PseudoObjectTy->isSizelessBuiltinType());
+  ASSERT_FALSE(FooTy->isSizelessBuiltinType());
+
+  ASSERT_FALSE(Ctx.getPointerType(Ctx.SveBoolTy)->isSizelessBuiltinType());
+  ASSERT_FALSE(Ctx.getLValueReferenceType(Ctx.SveBoolTy)->
+   isSizelessBuiltinType());
+  ASSERT_FALSE(Ctx.getRValueReferenceType(Ctx.SveBoolTy)->
+   isSizelessBuiltinType());
+}
+
+TEST_F(SizelessTypeTester, TestSizeless) {
+  ASSERT_TRUE(Ctx.SveInt8Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveInt64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveUint8Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint16Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint32Ty->isSizelessType());
+  ASSERT_TRUE(Ctx.SveUint64Ty->isSizelessType());
+
+  ASSERT_TRUE(Ctx.SveFloat16Ty->isSizelessType());
+  

[PATCH] D75569: New ClangTidy check for methods marked __attribute__((unavailable)) that do not override a method from a superclass.

2020-03-03 Thread Michael Wyman via Phabricator via cfe-commits
mwyman created this revision.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.

Such method declarations don't provide any benefit, as even without the 
declaration the compiler would complain about calling the method as it doesn't 
exist.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75569

Files:
  clang-tools-extra/clang-tidy/objc/CMakeLists.txt
  clang-tools-extra/clang-tidy/objc/MethodUnavailableNotOverrideCheck.cpp
  clang-tools-extra/clang-tidy/objc/MethodUnavailableNotOverrideCheck.h
  clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/objc-method-unavailable-not-override.rst
  
clang-tools-extra/test/clang-tidy/checkers/objc-method-unavailable-not-override.m

Index: clang-tools-extra/test/clang-tidy/checkers/objc-method-unavailable-not-override.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/objc-method-unavailable-not-override.m
@@ -0,0 +1,41 @@
+// RUN: %check_clang_tidy %s objc-method-unavailable-not-override %t
+
+__attribute__((objc_root_class))
+@interface Object
+- (instancetype)init;
+@end
+
+@interface MyObject : Object
+- (instancetype)init __attribute__((unavailable));
+- (instancetype)initWithInt:(int)anInt;
+
+- (void)methodA __attribute__((unavailable));
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: method 'methodA' is marked unavailable but does not override a superclass method [objc-method-unavailable-not-override]
+
+// Verify the check catches the unavailable attribute when a message is provided.
+- (void)methodB __attribute__((unavailable("use methodD")));
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: method 'methodB' is marked unavailable but does not override a superclass method [objc-method-unavailable-not-override]
+
+#define NS_UNAVAILABLE __attribute__((unavailable))
+
+// Verify the check works with macros declaring the unavailable attribute.
+- (void)methodC NS_UNAVAILABLE;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: method 'methodC' is marked unavailable but does not override a superclass method [objc-method-unavailable-not-override]
+@end
+
+
+@implementation MyObject
+
+- (instancetype)initWithInt:(int)anInt {
+  return 0;
+}
+
+// Should not flag implementations for methods declared unavailable; sometimes
+// implemementations are provided that assert, to catch such codepaths that
+// lead to those calls during development.
+- (void)methodA {}
+
+@end
+
+// Verify that fixes exist to delete entire method declarations:
+// CHECK-FIXES: {{^\s*$}}
Index: clang-tools-extra/docs/clang-tidy/checks/objc-method-unavailable-not-override.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/objc-method-unavailable-not-override.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - objc-method-unavailable-not-override
+
+objc-method-unavailable-not-override
+
+
+Checks that a method marked with __attribute__((unavailable)) is overriding
+a method declaration from a superclass. That declaration can usually be
+deleted entirely.
+
+.. code-block:: objc
+
+   @interface ClassA : NSObject
+   // Neither ClassA nor any superclasses define method -foo.
+   @end
+
+   @interface ClassB : ClassA
+   - (void)foo __attribute__((unavailable));
+   @end
+
+Suggests a fix to remove the method declaration entirely.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -236,6 +236,7 @@
`objc-avoid-nserror-init `_,
`objc-dealloc-in-category `_,
`objc-forbidden-subclassing `_,
+   `objc-method-unavailable-not-override `_, "Yes"
`objc-missing-hash `_,
`objc-property-declaration `_, "Yes"
`objc-super-self `_, "Yes"
@@ -283,7 +284,7 @@
`readability-redundant-member-init `_, "Yes"
`readability-redundant-preprocessor `_,
`readability-redundant-smartptr-get `_, "Yes"
-   `readability-redundant-string-cstr `_,
+   `readability-redundant-string-cstr `_, "Yes"
`readability-redundant-string-init `_, "Yes"
`readability-simplify-boolean-expr `_, "Yes"
`readability-simplify-subscript-expr `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -98,6 +98,12 @@
 
   Finds recursive functions and diagnoses them.
 
+- New :doc:`objc-method-unavailable-not-override
+  ` check.
+
+  Finds methods marked unavailable that do not override any method from a
+  superclass.
+
 New check aliases
 ^
 
@@ -115,7 +121,7 @@
 ^^
 
 - 

[PATCH] D75473: [clang-format] parse C# object initialisers

2020-03-03 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 248039.
jbcoe added a comment.

Remove code without test coverage.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75473/new/

https://reviews.llvm.org/D75473

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -546,6 +546,14 @@
  Colour = Colours.Yellow,
  } };)",
Style);
+
+  // Lambdas can be supplied as initialiser arguments.
+  verifyFormat(R"(//
+private Transformer _transformer = new X.Y {
+Filler = (Shape shape) => { return new Transform.Fill(shape, RED); },
+Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); },
+};)",
+   Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNamedArguments) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1632,6 +1632,17 @@
   // FIXME: Once we have an expression parser in the UnwrappedLineParser,
   // replace this by using parseAssigmentExpression() inside.
   do {
+if (Style.isCSharp()) {
+  if (FormatTok->is(TT_JsFatArrow)) {
+nextToken();
+// Fat arrows can be followed by simple expressions or by child blocks
+// in curly braces.
+if (FormatTok->is(tok::l_brace)) {
+  parseChildBlock();
+  continue;
+}
+  }
+}
 if (Style.Language == FormatStyle::LK_JavaScript) {
   if (FormatTok->is(Keywords.kw_function) ||
   FormatTok->startsSequence(Keywords.kw_async, Keywords.kw_function)) {
@@ -1955,7 +1966,7 @@
  DeclarationScopeStack.size() > 1);
 parseBlock(/*MustBeDeclaration=*/true, AddLevel);
 // Munch the semicolon after a namespace. This is more common than one 
would
-// think. Puttin the semicolon into its own line is very ugly.
+// think. Putting the semicolon into its own line is very ugly.
 if (FormatTok->Tok.is(tok::semi))
   nextToken();
 addUnwrappedLine();
@@ -1966,6 +1977,19 @@
 void UnwrappedLineParser::parseNew() {
   assert(FormatTok->is(tok::kw_new) && "'new' expected");
   nextToken();
+
+  if (Style.isCSharp()) {
+do {
+  if (FormatTok->is(tok::l_brace))
+parseBracedList();
+
+  if (FormatTok->isOneOf(tok::semi, tok::comma))
+return;
+
+  nextToken();
+} while (!eof());
+  }
+
   if (Style.Language != FormatStyle::LK_Java)
 return;
 


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -546,6 +546,14 @@
  Colour = Colours.Yellow,
  } };)",
Style);
+
+  // Lambdas can be supplied as initialiser arguments.
+  verifyFormat(R"(//
+private Transformer _transformer = new X.Y {
+Filler = (Shape shape) => { return new Transform.Fill(shape, RED); },
+Scaler = (Shape shape) => { return new Transform.Resize(shape, 0.1); },
+};)",
+   Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNamedArguments) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1632,6 +1632,17 @@
   // FIXME: Once we have an expression parser in the UnwrappedLineParser,
   // replace this by using parseAssigmentExpression() inside.
   do {
+if (Style.isCSharp()) {
+  if (FormatTok->is(TT_JsFatArrow)) {
+nextToken();
+// Fat arrows can be followed by simple expressions or by child blocks
+// in curly braces.
+if (FormatTok->is(tok::l_brace)) {
+  parseChildBlock();
+  continue;
+}
+  }
+}
 if (Style.Language == FormatStyle::LK_JavaScript) {
   if (FormatTok->is(Keywords.kw_function) ||
   FormatTok->startsSequence(Keywords.kw_async, Keywords.kw_function)) {
@@ -1955,7 +1966,7 @@
  DeclarationScopeStack.size() > 1);
 parseBlock(/*MustBeDeclaration=*/true, AddLevel);
 // Munch the semicolon after a namespace. This is more common than one would
-// think. Puttin the semicolon into its own line is very ugly.
+// think. Putting the semicolon into its own line is very ugly.
 if (FormatTok->Tok.is(tok::semi))
   nextToken();
 addUnwrappedLine();
@@ -1966,6 +1977,19 @@
 void UnwrappedLineParser::parseNew() {
   assert(FormatTok->is(tok::kw_new) && "'new' expected");
   nextToken();
+
+  if (Style.isCSharp()) {
+do {
+  

[PATCH] D75473: [clang-format] parse C# object initialisers

2020-03-03 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe marked an inline comment as done.
jbcoe added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1978
+  if (FormatTok->is(tok::l_paren))
+parseParens();
+

krasimir wrote:
> I don't understand why this is needed, and removing this `if` does not cause 
> any tests to fail.
> Please add a test case that will fail if we remove this `if`, or consider 
> removing otherwise.
I'll remove this for now and put together a follow up patch with test cases for 
more obscure object initializer use cases.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75473/new/

https://reviews.llvm.org/D75473



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


[PATCH] D75517: [clang-format] Do not format C# array subscript operators as attributes

2020-03-03 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG736fef97c7ac: [clang-format] Do not format C# array 
subscript operators as attributes (authored by Jonathan Coe 
jb...@google.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75517/new/

https://reviews.llvm.org/D75517

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -628,5 +628,13 @@
Style); // An array of a nullable type.
 }
 
+TEST_F(FormatTestCSharp, CSharpArraySubscripts) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  // Do not format array subscript operators as attributes.
+  verifyFormat(R"(if (someThings[index].Contains(myThing)) {)", Style);
+  verifyFormat(R"(if (someThings[i][j][k].Contains(myThing)) {)", Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -369,6 +369,17 @@
 if (!Style.isCSharp())
   return false;
 
+// `identifier[i]` is not an attribute.
+if (Tok.Previous && Tok.Previous->is(tok::identifier))
+  return false;
+
+// Chains [] in of `identifier[i][j][k]` are not attributes.
+if (Tok.Previous && Tok.Previous->is(tok::r_square)) {
+  auto *MatchingParen = Tok.Previous->MatchingParen;
+  if (!MatchingParen || MatchingParen->is(TT_ArraySubscriptLSquare))
+return false;
+}
+
 const FormatToken *AttrTok = Tok.Next;
 if (!AttrTok)
   return false;


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -628,5 +628,13 @@
Style); // An array of a nullable type.
 }
 
+TEST_F(FormatTestCSharp, CSharpArraySubscripts) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  // Do not format array subscript operators as attributes.
+  verifyFormat(R"(if (someThings[index].Contains(myThing)) {)", Style);
+  verifyFormat(R"(if (someThings[i][j][k].Contains(myThing)) {)", Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -369,6 +369,17 @@
 if (!Style.isCSharp())
   return false;
 
+// `identifier[i]` is not an attribute.
+if (Tok.Previous && Tok.Previous->is(tok::identifier))
+  return false;
+
+// Chains [] in of `identifier[i][j][k]` are not attributes.
+if (Tok.Previous && Tok.Previous->is(tok::r_square)) {
+  auto *MatchingParen = Tok.Previous->MatchingParen;
+  if (!MatchingParen || MatchingParen->is(TT_ArraySubscriptLSquare))
+return false;
+}
+
 const FormatToken *AttrTok = Tok.Next;
 if (!AttrTok)
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75395: [clang][Modules] Add -fsystem-module flag

2020-03-03 Thread Michael Spencer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG27a3ecee4558: [clang][Modules] Add -fsystem-module flag 
(authored by Bigcheese).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75395/new/

https://reviews.llvm.org/D75395

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Modules/fsystem-module.m


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep 
"-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1905,6 +1905,11 @@
   Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
   Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
   Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
+  Opts.IsSystemModule = Args.hasArg(OPT_fsystem_module);
+
+  if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 
   Opts.CodeCompleteOpts.IncludeMacros
 = Args.hasArg(OPT_code_completion_macros);
@@ -2061,12 +2066,16 @@
 DashX = IK;
 }
 
+bool IsSystem = false;
+
 // The -emit-module action implicitly takes a module map.
 if (Opts.ProgramAction == frontend::GenerateModule &&
-IK.getFormat() == InputKind::Source)
+IK.getFormat() == InputKind::Source) {
   IK = IK.withFormat(InputKind::ModuleMap);
+  IsSystem = Opts.IsSystemModule;
+}
 
-Opts.Inputs.emplace_back(std::move(Inputs[i]), IK);
+Opts.Inputs.emplace_back(std::move(Inputs[i]), IK, IsSystem);
   }
 
   return DashX;
Index: clang/include/clang/Frontend/FrontendOptions.h
===
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -297,6 +297,9 @@
   /// Should a temporary file be used during compilation.
   unsigned UseTemporary : 1;
 
+  /// When using -emit-module, treat the modulemap as a system module.
+  unsigned IsSystemModule : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1445,6 +1445,8 @@
 def fmodule_name : Separate<["-"], "fmodule-name">, Alias;
 def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group, Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
   HelpText<"Load this module map file">;


Index: clang/test/Modules/fsystem-module.m
===
--- /dev/null
+++ clang/test/Modules/fsystem-module.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep "-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers
Index: 

[PATCH] D75465: [clang-format] Do not merge target-name and : for C# attributes

2020-03-03 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG900dee8c8e03: [clang-format] Do not merge target-name and : 
for C# attributes (authored by Jonathan Coe jb...@google.com).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75465/new/

https://reviews.llvm.org/D75465

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp

Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -384,11 +384,11 @@
 
 if (!AttrTok)
   return false;
-
-// Move past the end of ']'.
+
+// Allow an attribute to be the only content of a file.
 AttrTok = AttrTok->Next;
 if (!AttrTok)
-  return false;
+  return true;
 
 // Limit this to being an access modifier that follows.
 if (AttrTok->isOneOf(tok::kw_public, tok::kw_private, tok::kw_protected,
@@ -460,7 +460,7 @@
  Contexts.back().InCpp11AttributeSpecifier;
 
 // Treat C# Attributes [STAThread] much like C++ attributes [[...]].
-bool IsCSharp11AttributeSpecifier =
+bool IsCSharpAttributeSpecifier =
 isCSharpAttributeSpecifier(*Left) ||
 Contexts.back().InCSharpAttributeSpecifier;
 
@@ -469,7 +469,8 @@
 bool StartsObjCMethodExpr =
 !IsCppStructuredBinding && !InsideInlineASM && !CppArrayTemplates &&
 Style.isCpp() && !IsCpp11AttributeSpecifier &&
-Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&
+!IsCSharpAttributeSpecifier && Contexts.back().CanBeExpression &&
+Left->isNot(TT_LambdaLSquare) &&
 !CurrentToken->isOneOf(tok::l_brace, tok::r_square) &&
 (!Parent ||
  Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
@@ -496,7 +497,7 @@
   } else if (Style.isCpp() && Contexts.back().ContextKind == tok::l_brace &&
  Parent && Parent->isOneOf(tok::l_brace, tok::comma)) {
 Left->Type = TT_DesignatedInitializerLSquare;
-  } else if (IsCSharp11AttributeSpecifier) {
+  } else if (IsCSharpAttributeSpecifier) {
 Left->Type = TT_AttributeSquare;
   } else if (CurrentToken->is(tok::r_square) && Parent &&
  Parent->is(TT_TemplateCloser)) {
@@ -559,13 +560,13 @@
 
 Contexts.back().ColonIsObjCMethodExpr = StartsObjCMethodExpr;
 Contexts.back().InCpp11AttributeSpecifier = IsCpp11AttributeSpecifier;
-Contexts.back().InCSharpAttributeSpecifier = IsCSharp11AttributeSpecifier;
+Contexts.back().InCSharpAttributeSpecifier = IsCSharpAttributeSpecifier;
 
 while (CurrentToken) {
   if (CurrentToken->is(tok::r_square)) {
 if (IsCpp11AttributeSpecifier)
   CurrentToken->Type = TT_AttributeSquare;
-if (IsCSharp11AttributeSpecifier)
+if (IsCSharpAttributeSpecifier)
   CurrentToken->Type = TT_AttributeSquare;
 else if (((CurrentToken->Next &&
CurrentToken->Next->is(tok::l_paren)) ||
@@ -777,6 +778,10 @@
   break;
 }
   } else if (Style.isCSharp()) {
+if (Contexts.back().InCSharpAttributeSpecifier) {
+  Tok->Type = TT_AttributeColon;
+  break;
+}
 if (Contexts.back().ContextKind == tok::l_paren) {
   Tok->Type = TT_CSharpNamedArgumentColon;
   break;
@@ -2922,6 +2927,10 @@
 if (Left.is(TT_JsFatArrow) || Right.is(TT_JsFatArrow))
   return true;
 
+// No spaces around attribute target colons
+if (Left.is(TT_AttributeColon) || Right.is(TT_AttributeColon))
+  return false;
+
 // space between type and variable e.g. Dictionary foo;
 if (Left.is(TT_TemplateCloser) && Right.is(TT_StartOfName))
   return true;
@@ -3550,8 +3559,8 @@
   const FormatToken  = *Right.Previous;
   // Language-specific stuff.
   if (Style.isCSharp()) {
-if (Left.is(TT_CSharpNamedArgumentColon) ||
-Right.is(TT_CSharpNamedArgumentColon))
+if (Left.isOneOf(TT_CSharpNamedArgumentColon, TT_AttributeColon) ||
+Right.isOneOf(TT_CSharpNamedArgumentColon, TT_AttributeColon))
   return false;
   } else if (Style.Language == FormatStyle::LK_Java) {
 if (Left.isOneOf(Keywords.kw_throws, Keywords.kw_extends,
Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -55,7 +55,6 @@
   bool tryMergeCSharpDoubleQuestion();
   bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
-  bool tryMergeCSharpAttributeAndTarget();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- 

[clang] 736fef9 - [clang-format] Do not format C# array subscript operators as attributes

2020-03-03 Thread Jonathan Coe via cfe-commits

Author: Jonathan Coe
Date: 2020-03-03T22:21:33Z
New Revision: 736fef97c7ac4113388fc56db10c599fb4d2f074

URL: 
https://github.com/llvm/llvm-project/commit/736fef97c7ac4113388fc56db10c599fb4d2f074
DIFF: 
https://github.com/llvm/llvm-project/commit/736fef97c7ac4113388fc56db10c599fb4d2f074.diff

LOG: [clang-format] Do not format C# array subscript operators as attributes

Summary:
Fix misidentification of C# array subscript operators.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index a074d54fd44c..493454eb2239 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -369,6 +369,17 @@ class AnnotatingParser {
 if (!Style.isCSharp())
   return false;
 
+// `identifier[i]` is not an attribute.
+if (Tok.Previous && Tok.Previous->is(tok::identifier))
+  return false;
+
+// Chains [] in of `identifier[i][j][k]` are not attributes.
+if (Tok.Previous && Tok.Previous->is(tok::r_square)) {
+  auto *MatchingParen = Tok.Previous->MatchingParen;
+  if (!MatchingParen || MatchingParen->is(TT_ArraySubscriptLSquare))
+return false;
+}
+
 const FormatToken *AttrTok = Tok.Next;
 if (!AttrTok)
   return false;

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 6251f97b8e0b..ad849f2dbdf7 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -628,5 +628,13 @@ TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Style); // An array of a nullable type.
 }
 
+TEST_F(FormatTestCSharp, CSharpArraySubscripts) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  // Do not format array subscript operators as attributes.
+  verifyFormat(R"(if (someThings[index].Contains(myThing)) {)", Style);
+  verifyFormat(R"(if (someThings[i][j][k].Contains(myThing)) {)", Style);
+}
+
 } // namespace format
 } // end namespace clang



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


[PATCH] D75563: [clang][Parse] properly parse asm-qualifiers, asm inline

2020-03-03 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added inline comments.



Comment at: clang/test/Parser/asm-qualifiers.c:20
+
+void combinations(void) {
+  asm volatile inline("");

I'm probably being dense but what is intended to be tested differently between 
`combinations` and `permutations`? I assume the order of the qualifiers? 
Wouldn't it just be better to merge `combinations` into `permutations` or was 
there some deeper reasoning for the compartmentalization?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75563/new/

https://reviews.llvm.org/D75563



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


[PATCH] D75215: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-03-03 Thread Amy Huang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b3b21f02588: [DebugInfo] Fix for adding returns cxx 
udt option to functions in CodeView. (authored by akhuang).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75215/new/

https://reviews.llvm.org/D75215

Files:
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/function-options.ll

Index: llvm/test/DebugInfo/COFF/function-options.ll
===
--- llvm/test/DebugInfo/COFF/function-options.ll
+++ llvm/test/DebugInfo/COFF/function-options.ll
@@ -4,7 +4,6 @@
 ; Command to generate function-options.ll
 ; $ clang++ function-options.cpp -S -emit-llvm -g -gcodeview -o function-options.ll
 ;
-;
 ; #define DEFINE_FUNCTION(T) \
 ;   T Func_##T(T ) { return arg; }
 ;
@@ -32,7 +31,11 @@
 ; class DClass : public BClass {}; // Note: MSVC yields one compiler-generated ctor for DClass while clang doesn't.
 ; DEFINE_FUNCTION(DClass); // Expect: FO = CxxReturnUdt
 ;
-; class FClass { static int x; };
+; class FClass {
+;   static int x;
+;   AClass Member_AClass(AClass &);
+;   BClass Member_BClass(BClass &);
+; };
 ; DEFINE_FUNCTION(FClass); // Expect FO = None
 ; 
 ; struct AStruct {};
@@ -54,7 +57,7 @@
 ; CHECK: CodeViewTypes [
 ; CHECK:   Section: .debug$T ({{.*}})
 ; CHECK:   Magic: 0x4
-; CHECK:   Procedure ([[SP1:.*]]) {
+; CHECK:   Procedure ([[SP_A:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: AClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -66,10 +69,10 @@
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: AClass (AClass&) ([[SP1]])
+; CHECK: FunctionType: AClass (AClass&) ([[SP_A]])
 ; CHECK: Name: Func_AClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP2:.*]]) {
+; CHECK:   Procedure ([[SP_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: BClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -79,11 +82,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (BClass&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF1:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: BClass ({{.*}})
-; CHECK: ThisType: BClass* const ({{.*}})
+; CHECK: ThisType: BClass* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x2)
 ; CHECK:   Constructor (0x2)
@@ -97,17 +100,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Private (0x1)
-; CHECK:   Type: void BClass::() ([[MF1]])
+; CHECK:   Type: void BClass::() ([[CTOR_B]])
 ; CHECK:   Name: BClass
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: BClass (BClass&) ([[SP2]])
+; CHECK: FunctionType: BClass (BClass&) ([[SP_B]])
 ; CHECK: Name: Func_BClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP3:.*]]) {
+; CHECK:   Procedure ([[SP_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: C1Class ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -116,11 +119,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (C1Class&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF2:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: C1Class ({{.*}})
-; CHECK: ThisType: C1Class* const ({{.*}})
+; CHECK: ThisType: C1Class* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x0)
 ; CHECK: ]
@@ -133,17 +136,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Public (0x3)
-; CHECK:   Type: void C1Class::() ([[MF2]])
+; CHECK:   Type: void C1Class::() ([[CTOR_C1]])
 ; CHECK:   Name: C1Class
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: C1Class (C1Class&) ([[SP3]])
+; CHECK: FunctionType: C1Class (C1Class&) ([[SP_C1]])
 ; CHECK: Name: Func_C1Class
 ; CHECK:   }
-; CHECK:   Procedure ([[SP4:.*]]) {
+; CHECK:   Procedure ([[SP_C2:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: C2Class ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -153,11 +156,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (C2Class&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF3:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_C2:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION 

[PATCH] D75563: [clang][Parse] properly parse asm-qualifiers, asm inline

2020-03-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 248027.
nickdesaulniers added a comment.

- make sure to initialize GNUAsmQualifiers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75563/new/

https://reviews.llvm.org/D75563

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseStmtAsm.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/test/Parser/asm-qualifiers.c

Index: clang/test/Parser/asm-qualifiers.c
===
--- /dev/null
+++ clang/test/Parser/asm-qualifiers.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify %s
+
+void qualifiers(void) {
+  asm("");
+  asm volatile("");
+  asm inline("");
+  asm goto("" foo);
+foo:;
+}
+
+void underscores(void) {
+  __asm__("");
+  __asm__ __volatile__("");
+  __asm__ __inline__("");
+  // Note: goto is not supported with underscore prefix+suffix.
+  __asm__ goto("" foo);
+foo:;
+}
+
+void combinations(void) {
+  asm volatile inline("");
+  asm volatile goto("" foo);
+  asm inline goto("" foo);
+  asm volatile inline goto("" foo);
+foo:;
+}
+
+void permutations(void) {
+  asm inline volatile("");
+  asm goto volatile("");
+  asm goto inline("");
+  asm inline goto volatile("" foo);
+  asm inline volatile goto("" foo);
+  asm goto inline volatile("" foo);
+  asm goto volatile inline("" foo);
+foo:;
+}
+
+void duplicates(void) {
+  asm volatile volatile(""); // expected-error {{duplicate asm qualifier volatile}}
+  __asm__ __volatile__ __volatile__(""); // expected-error {{duplicate asm qualifier volatile}}
+  asm inline inline(""); // expected-error {{duplicate asm qualifier inline}}
+  __asm__ __inline__ __inline__(""); // expected-error {{duplicate asm qualifier inline}}
+  asm goto goto("" foo); // expected-error {{duplicate asm qualifier goto}}
+  __asm__ goto goto("" foo); // expected-error {{duplicate asm qualifier goto}}
+foo:;
+}
Index: clang/lib/Sema/DeclSpec.cpp
===
--- clang/lib/Sema/DeclSpec.cpp
+++ clang/lib/Sema/DeclSpec.cpp
@@ -589,6 +589,16 @@
   llvm_unreachable("Unknown typespec!");
 }
 
+const char *DeclSpec::getSpecifierName(AQ A) {
+  switch (A) {
+case DeclSpec::AQ_unspecified: return "unspecified";
+case DeclSpec::AQ_volatile: return "volatile";
+case DeclSpec::AQ_inline: return "inline";
+case DeclSpec::AQ_goto: return "goto";
+  }
+  llvm_unreachable("Unknown GNUAsmQualifier!");
+}
+
 bool DeclSpec::SetStorageClassSpec(Sema , SCS SC, SourceLocation Loc,
const char *,
unsigned ,
@@ -938,6 +948,12 @@
   llvm_unreachable("Unknown type qualifier!");
 }
 
+bool DeclSpec::SetGNUAsmQual(AQ A, SourceLocation Loc) {
+  bool IsInvalid = GNUAsmQualifiers & A;
+  GNUAsmQualifiers |= A;
+  return IsInvalid;
+}
+
 bool DeclSpec::setFunctionSpecInline(SourceLocation Loc, const char *,
  unsigned ) {
   // 'inline inline' is ok.  However, since this is likely not what the user
Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -684,13 +684,42 @@
 ClobberRefs, Exprs, EndLoc);
 }
 
+/// ParseGNUAsmQualifierListOpt - Parse a GNU extended asm qualifier list.
+///   asm-qualifiers:
+/// volatile
+/// inline
+/// goto
+void Parser::ParseGNUAsmQualifierListOpt(DeclSpec ) {
+  SourceLocation EndLoc;
+  while (1) {
+SourceLocation Loc = Tok.getLocation();
+DeclSpec::AQ AQ = DeclSpec::AQ_unspecified;
+
+if (Tok.getKind() == tok::kw_volatile)
+  AQ = DeclSpec::AQ_volatile;
+else if (Tok.getKind() == tok::kw_inline)
+  AQ = DeclSpec::AQ_inline;
+else if (Tok.getKind() == tok::kw_goto)
+  AQ = DeclSpec::AQ_goto;
+else {
+  if (EndLoc.isValid())
+DS.SetRangeEnd(EndLoc);
+  return;
+}
+if (DS.SetGNUAsmQual(AQ, Loc))
+  Diag(Loc, diag::err_asm_duplicate_qual)
+  << DeclSpec::getSpecifierName(AQ);
+EndLoc = ConsumeToken();
+  }
+}
+
 /// ParseAsmStatement - Parse a GNU extended asm statement.
 ///   asm-statement:
 /// gnu-asm-statement
 /// ms-asm-statement
 ///
 /// [GNU] gnu-asm-statement:
-/// 'asm' type-qualifier[opt] '(' asm-argument ')' ';'
+/// 'asm' asm-qualifier[opt] '(' asm-argument ')' ';'
 ///
 /// [GNU] asm-argument:
 /// asm-string-literal
@@ -713,6 +742,7 @@
   }
 
   DeclSpec DS(AttrFactory);
+  ParseGNUAsmQualifierListOpt(DS);
   SourceLocation Loc = Tok.getLocation();
   ParseTypeQualifierListOpt(DS, 

[PATCH] D75215: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-03-03 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 248025.
akhuang added a comment.

remove tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75215/new/

https://reviews.llvm.org/D75215

Files:
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/function-options.ll

Index: llvm/test/DebugInfo/COFF/function-options.ll
===
--- llvm/test/DebugInfo/COFF/function-options.ll
+++ llvm/test/DebugInfo/COFF/function-options.ll
@@ -4,7 +4,6 @@
 ; Command to generate function-options.ll
 ; $ clang++ function-options.cpp -S -emit-llvm -g -gcodeview -o function-options.ll
 ;
-;
 ; #define DEFINE_FUNCTION(T) \
 ;   T Func_##T(T ) { return arg; }
 ;
@@ -32,7 +31,11 @@
 ; class DClass : public BClass {}; // Note: MSVC yields one compiler-generated ctor for DClass while clang doesn't.
 ; DEFINE_FUNCTION(DClass); // Expect: FO = CxxReturnUdt
 ;
-; class FClass { static int x; };
+; class FClass {
+;   static int x;
+;   AClass Member_AClass(AClass &);
+;   BClass Member_BClass(BClass &);
+; };
 ; DEFINE_FUNCTION(FClass); // Expect FO = None
 ; 
 ; struct AStruct {};
@@ -54,7 +57,7 @@
 ; CHECK: CodeViewTypes [
 ; CHECK:   Section: .debug$T ({{.*}})
 ; CHECK:   Magic: 0x4
-; CHECK:   Procedure ([[SP1:.*]]) {
+; CHECK:   Procedure ([[SP_A:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: AClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -66,10 +69,10 @@
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: AClass (AClass&) ([[SP1]])
+; CHECK: FunctionType: AClass (AClass&) ([[SP_A]])
 ; CHECK: Name: Func_AClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP2:.*]]) {
+; CHECK:   Procedure ([[SP_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: BClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -79,11 +82,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (BClass&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF1:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: BClass ({{.*}})
-; CHECK: ThisType: BClass* const ({{.*}})
+; CHECK: ThisType: BClass* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x2)
 ; CHECK:   Constructor (0x2)
@@ -97,17 +100,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Private (0x1)
-; CHECK:   Type: void BClass::() ([[MF1]])
+; CHECK:   Type: void BClass::() ([[CTOR_B]])
 ; CHECK:   Name: BClass
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: BClass (BClass&) ([[SP2]])
+; CHECK: FunctionType: BClass (BClass&) ([[SP_B]])
 ; CHECK: Name: Func_BClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP3:.*]]) {
+; CHECK:   Procedure ([[SP_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: C1Class ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -116,11 +119,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (C1Class&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF2:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: C1Class ({{.*}})
-; CHECK: ThisType: C1Class* const ({{.*}})
+; CHECK: ThisType: C1Class* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x0)
 ; CHECK: ]
@@ -133,17 +136,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Public (0x3)
-; CHECK:   Type: void C1Class::() ([[MF2]])
+; CHECK:   Type: void C1Class::() ([[CTOR_C1]])
 ; CHECK:   Name: C1Class
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: C1Class (C1Class&) ([[SP3]])
+; CHECK: FunctionType: C1Class (C1Class&) ([[SP_C1]])
 ; CHECK: Name: Func_C1Class
 ; CHECK:   }
-; CHECK:   Procedure ([[SP4:.*]]) {
+; CHECK:   Procedure ([[SP_C2:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: C2Class ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -153,11 +156,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (C2Class&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF3:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_C2:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: C2Class ({{.*}})
-; CHECK: ThisType: C2Class* 

[clang] 900dee8 - [clang-format] Do not merge target-name and : for C# attributes

2020-03-03 Thread Jonathan Coe via cfe-commits

Author: Jonathan Coe
Date: 2020-03-03T22:17:25Z
New Revision: 900dee8c8e03abc5a566e22b4f5499ecdc960803

URL: 
https://github.com/llvm/llvm-project/commit/900dee8c8e03abc5a566e22b4f5499ecdc960803
DIFF: 
https://github.com/llvm/llvm-project/commit/900dee8c8e03abc5a566e22b4f5499ecdc960803.diff

LOG: [clang-format] Do not merge target-name and : for C# attributes

Summary:
Re-use token type `TT_AttributeColon` for C# attribute target colons.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: MyDeveloperDay, cfe-commits

Tags: #clang-format, #clang

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

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 8fa78b773e5e..9e081e1495d0 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -76,8 +76,6 @@ void FormatTokenLexer::tryMergePreviousTokens() {
 return;
 
   if (Style.isCSharp()) {
-if (tryMergeCSharpAttributeAndTarget())
-  return;
 if (tryMergeCSharpKeywordVariables())
   return;
 if (tryMergeCSharpStringLiteral())
@@ -284,34 +282,6 @@ const llvm::StringSet<> 
FormatTokenLexer::CSharpAttributeTargets = {
 "param","property", "return", "type",
 };
 
-bool FormatTokenLexer::tryMergeCSharpAttributeAndTarget() {
-  // Treat '[assembly:' and '[field:' as tokens in their own right.
-  if (Tokens.size() < 3)
-return false;
-
-  auto  = *(Tokens.end() - 3);
-  auto  = *(Tokens.end() - 2);
-  auto  = *(Tokens.end() - 1);
-
-  if (!SquareBracket->Tok.is(tok::l_square))
-return false;
-
-  if (CSharpAttributeTargets.find(Target->TokenText) ==
-  CSharpAttributeTargets.end())
-return false;
-
-  if (!Colon->Tok.is(tok::colon))
-return false;
-
-  SquareBracket->TokenText =
-  StringRef(SquareBracket->TokenText.begin(),
-Colon->TokenText.end() - SquareBracket->TokenText.begin());
-  SquareBracket->ColumnWidth += (Target->ColumnWidth + Colon->ColumnWidth);
-  Tokens.erase(Tokens.end() - 2);
-  Tokens.erase(Tokens.end() - 1);
-  return true;
-}
-
 bool FormatTokenLexer::tryMergeCSharpDoubleQuestion() {
   if (Tokens.size() < 2)
 return false;

diff  --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index e5726fe18111..192e26a10d4a 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -55,7 +55,6 @@ class FormatTokenLexer {
   bool tryMergeCSharpDoubleQuestion();
   bool tryMergeCSharpNullConditional();
   bool tryTransformCSharpForEach();
-  bool tryMergeCSharpAttributeAndTarget();
 
   bool tryMergeTokens(ArrayRef Kinds, TokenType NewType);
 

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 35e0b423cfc4..a074d54fd44c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -384,11 +384,11 @@ class AnnotatingParser {
 
 if (!AttrTok)
   return false;
-
-// Move past the end of ']'.
+
+// Allow an attribute to be the only content of a file.
 AttrTok = AttrTok->Next;
 if (!AttrTok)
-  return false;
+  return true;
 
 // Limit this to being an access modifier that follows.
 if (AttrTok->isOneOf(tok::kw_public, tok::kw_private, tok::kw_protected,
@@ -460,7 +460,7 @@ class AnnotatingParser {
  Contexts.back().InCpp11AttributeSpecifier;
 
 // Treat C# Attributes [STAThread] much like C++ attributes [[...]].
-bool IsCSharp11AttributeSpecifier =
+bool IsCSharpAttributeSpecifier =
 isCSharpAttributeSpecifier(*Left) ||
 Contexts.back().InCSharpAttributeSpecifier;
 
@@ -469,7 +469,8 @@ class AnnotatingParser {
 bool StartsObjCMethodExpr =
 !IsCppStructuredBinding && !InsideInlineASM && !CppArrayTemplates &&
 Style.isCpp() && !IsCpp11AttributeSpecifier &&
-Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&
+!IsCSharpAttributeSpecifier && Contexts.back().CanBeExpression &&
+Left->isNot(TT_LambdaLSquare) &&
 !CurrentToken->isOneOf(tok::l_brace, tok::r_square) &&
 (!Parent ||
  Parent->isOneOf(tok::colon, tok::l_square, tok::l_paren,
@@ -496,7 +497,7 @@ class AnnotatingParser {
   } else if (Style.isCpp() && Contexts.back().ContextKind == tok::l_brace 
&&
  Parent && Parent->isOneOf(tok::l_brace, tok::comma)) {
 Left->Type = TT_DesignatedInitializerLSquare;
-  } else if (IsCSharp11AttributeSpecifier) {
+  } else if (IsCSharpAttributeSpecifier) {
 Left->Type = TT_AttributeSquare;
   } else if (CurrentToken->is(tok::r_square) && Parent &&
  

[clang] 27a3ece - [clang][Modules] Add -fsystem-module flag

2020-03-03 Thread Michael Spencer via cfe-commits

Author: Michael Spencer
Date: 2020-03-03T14:14:24-08:00
New Revision: 27a3ecee45584f6e78b4674ebbbe5554faad

URL: 
https://github.com/llvm/llvm-project/commit/27a3ecee45584f6e78b4674ebbbe5554faad
DIFF: 
https://github.com/llvm/llvm-project/commit/27a3ecee45584f6e78b4674ebbbe5554faad.diff

LOG: [clang][Modules] Add -fsystem-module flag

The -fsystem-module flag is used when explicitly building a module. It
forces the module to be treated as a system module. This is used when
converting an implicit build to an explicit build to match the
systemness the implicit build would have had for a given module.

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

Added: 
clang/test/Modules/fsystem-module.m

Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/FrontendOptions.h
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f1801e3e89e7..2aaf85434214 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1445,6 +1445,8 @@ def fmodule_name_EQ : Joined<["-"], "fmodule-name=">, 
Group,
 def fmodule_name : Separate<["-"], "fmodule-name">, Alias;
 def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
   Flags<[CC1Option]>, Alias;
+def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group, Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
   HelpText<"Load this module map file">;

diff  --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 2adc6319810c..66fec6436a40 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -297,6 +297,9 @@ class FrontendOptions {
   /// Should a temporary file be used during compilation.
   unsigned UseTemporary : 1;
 
+  /// When using -emit-module, treat the modulemap as a system module.
+  unsigned IsSystemModule : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 8638d4300b21..48c65aded817 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1905,6 +1905,11 @@ static InputKind ParseFrontendArgs(FrontendOptions 
, ArgList ,
   Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
   Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
   Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
+  Opts.IsSystemModule = Args.hasArg(OPT_fsystem_module);
+
+  if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
+Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
+   << "-emit-module";
 
   Opts.CodeCompleteOpts.IncludeMacros
 = Args.hasArg(OPT_code_completion_macros);
@@ -2061,12 +2066,16 @@ static InputKind ParseFrontendArgs(FrontendOptions 
, ArgList ,
 DashX = IK;
 }
 
+bool IsSystem = false;
+
 // The -emit-module action implicitly takes a module map.
 if (Opts.ProgramAction == frontend::GenerateModule &&
-IK.getFormat() == InputKind::Source)
+IK.getFormat() == InputKind::Source) {
   IK = IK.withFormat(InputKind::ModuleMap);
+  IsSystem = Opts.IsSystemModule;
+}
 
-Opts.Inputs.emplace_back(std::move(Inputs[i]), IK);
+Opts.Inputs.emplace_back(std::move(Inputs[i]), IK, IsSystem);
   }
 
   return DashX;

diff  --git a/clang/test/Modules/fsystem-module.m 
b/clang/test/Modules/fsystem-module.m
new file mode 100644
index ..6ef91b762b0f
--- /dev/null
+++ b/clang/test/Modules/fsystem-module.m
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir %t.dir
+
+// -fsystem-module requires -emit-module
+// RUN: not %clang_cc1 -fsyntax-only -fsystem-module %s 2>&1 | grep 
"-emit-module"
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning.pcm
+
+// RUN: %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module
+
+// RUN: not %clang_cc1 -fmodules -I %S/Inputs \
+// RUN:   -emit-module -fmodule-name=warning -pedantic -Werror \
+// RUN:   %S/Inputs/module.map -o %t.dir/warning-system.pcm -fsystem-module \
+// RUN:   -Wsystem-headers



___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D75563: [clang][Parse] properly parse asm-qualifiers, asm inline

2020-03-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 248020.
nickdesaulniers added a comment.

- seems `arc diff` wiped out my previous changes...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75563/new/

https://reviews.llvm.org/D75563

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseStmtAsm.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/test/Parser/asm-qualifiers.c

Index: clang/test/Parser/asm-qualifiers.c
===
--- /dev/null
+++ clang/test/Parser/asm-qualifiers.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify %s
+
+void qualifiers(void) {
+  asm("");
+  asm volatile("");
+  asm inline("");
+  asm goto("" foo);
+foo:;
+}
+
+void underscores(void) {
+  __asm__("");
+  __asm__ __volatile__("");
+  __asm__ __inline__("");
+  // Note: goto is not supported with underscore prefix+suffix.
+  __asm__ goto("" foo);
+foo:;
+}
+
+void combinations(void) {
+  asm volatile inline("");
+  asm volatile goto("" foo);
+  asm inline goto("" foo);
+  asm volatile inline goto("" foo);
+foo:;
+}
+
+void permutations(void) {
+  asm inline volatile("");
+  asm goto volatile("");
+  asm goto inline("");
+  asm inline goto volatile("" foo);
+  asm inline volatile goto("" foo);
+  asm goto inline volatile("" foo);
+  asm goto volatile inline("" foo);
+foo:;
+}
+
+void duplicates(void) {
+  asm volatile volatile(""); // expected-error {{duplicate asm qualifier volatile}}
+  __asm__ __volatile__ __volatile__(""); // expected-error {{duplicate asm qualifier volatile}}
+  asm inline inline(""); // expected-error {{duplicate asm qualifier inline}}
+  __asm__ __inline__ __inline__(""); // expected-error {{duplicate asm qualifier inline}}
+  asm goto goto("" foo); // expected-error {{duplicate asm qualifier goto}}
+  __asm__ goto goto("" foo); // expected-error {{duplicate asm qualifier goto}}
+foo:;
+}
Index: clang/lib/Sema/DeclSpec.cpp
===
--- clang/lib/Sema/DeclSpec.cpp
+++ clang/lib/Sema/DeclSpec.cpp
@@ -589,6 +589,16 @@
   llvm_unreachable("Unknown typespec!");
 }
 
+const char *DeclSpec::getSpecifierName(AQ A) {
+  switch (A) {
+case DeclSpec::AQ_unspecified: return "unspecified";
+case DeclSpec::AQ_volatile: return "volatile";
+case DeclSpec::AQ_inline: return "inline";
+case DeclSpec::AQ_goto: return "goto";
+  }
+  llvm_unreachable("Unknown GNUAsmQualifier!");
+}
+
 bool DeclSpec::SetStorageClassSpec(Sema , SCS SC, SourceLocation Loc,
const char *,
unsigned ,
@@ -938,6 +948,12 @@
   llvm_unreachable("Unknown type qualifier!");
 }
 
+bool DeclSpec::SetGNUAsmQual(AQ A, SourceLocation Loc) {
+  bool IsInvalid = GNUAsmQualifiers & A;
+  GNUAsmQualifiers |= A;
+  return IsInvalid;
+}
+
 bool DeclSpec::setFunctionSpecInline(SourceLocation Loc, const char *,
  unsigned ) {
   // 'inline inline' is ok.  However, since this is likely not what the user
Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -684,13 +684,42 @@
 ClobberRefs, Exprs, EndLoc);
 }
 
+/// ParseGNUAsmQualifierListOpt - Parse a GNU extended asm qualifier list.
+///   asm-qualifiers:
+/// volatile
+/// inline
+/// goto
+void Parser::ParseGNUAsmQualifierListOpt(DeclSpec ) {
+  SourceLocation EndLoc;
+  while (1) {
+SourceLocation Loc = Tok.getLocation();
+DeclSpec::AQ AQ = DeclSpec::AQ_unspecified;
+
+if (Tok.getKind() == tok::kw_volatile)
+  AQ = DeclSpec::AQ_volatile;
+else if (Tok.getKind() == tok::kw_inline)
+  AQ = DeclSpec::AQ_inline;
+else if (Tok.getKind() == tok::kw_goto)
+  AQ = DeclSpec::AQ_goto;
+else {
+  if (EndLoc.isValid())
+DS.SetRangeEnd(EndLoc);
+  return;
+}
+if (DS.SetGNUAsmQual(AQ, Loc))
+  Diag(Loc, diag::err_asm_duplicate_qual)
+  << DeclSpec::getSpecifierName(AQ);
+EndLoc = ConsumeToken();
+  }
+}
+
 /// ParseAsmStatement - Parse a GNU extended asm statement.
 ///   asm-statement:
 /// gnu-asm-statement
 /// ms-asm-statement
 ///
 /// [GNU] gnu-asm-statement:
-/// 'asm' type-qualifier[opt] '(' asm-argument ')' ';'
+/// 'asm' asm-qualifier[opt] '(' asm-argument ')' ';'
 ///
 /// [GNU] asm-argument:
 /// asm-string-literal
@@ -713,6 +742,7 @@
   }
 
   DeclSpec DS(AttrFactory);
+  ParseGNUAsmQualifierListOpt(DS);
   SourceLocation Loc = Tok.getLocation();
   ParseTypeQualifierListOpt(DS, 

[PATCH] D75563: [clang][Parse] properly parse asm-qualifiers, asm inline

2020-03-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 248019.
nickdesaulniers added a comment.

- remove impossible case in ParseGNUAsmQualifierListOpt
- simplify SetGNUAsmQual
- fix typo in comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75563/new/

https://reviews.llvm.org/D75563

Files:
  clang/lib/Parse/ParseStmtAsm.cpp


Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -684,7 +684,7 @@
 ClobberRefs, Exprs, EndLoc);
 }
 
-/// ParseGNUAsmQualifierList - Parse a GNU extended asm qualifier list.
+/// ParseGNUAsmQualifierListOpt - Parse a GNU extended asm qualifier list.
 ///   asm-qualifiers:
 /// volatile
 /// inline


Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -684,7 +684,7 @@
 ClobberRefs, Exprs, EndLoc);
 }
 
-/// ParseGNUAsmQualifierList - Parse a GNU extended asm qualifier list.
+/// ParseGNUAsmQualifierListOpt - Parse a GNU extended asm qualifier list.
 ///   asm-qualifiers:
 /// volatile
 /// inline
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75215: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-03-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

lgtm, but please remove the clang test update from this patch, since it 
shouldn't pass yet.




Comment at: clang/test/CodeGenCXX/debug-info-flag-nontrivial.cpp:1
+// RUN: %clang_cc1 -emit-llvm -gcodeview -debug-info-kind=limited %s -o - | 
FileCheck %s
+// Test for NonTrivial flags in debug info.

This test shouldn't be part of the LLVM-only change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75215/new/

https://reviews.llvm.org/D75215



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


[PATCH] D75563: [clang][Parse] properly parse asm-qualifiers, asm inline

2020-03-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers created this revision.
nickdesaulniers added a reviewer: aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nickdesaulniers added a comment.

I still plan to add CodeGen support for `asm inline` before the next release, 
which should be as simple as emitting an additional `inlinehint`, but I'd like 
to save that for a follow up patch on top of this.


The parsing of GNU C extended asm statements was a little brittle and
had a few issues:

- It was using Parse::ParseTypeQualifierListOpt to parse the `volatile` 
qualifier.  That parser is really meant for TypeQualifiers; an asm statement 
doesn't really have a type qualifier. This is still maybe nice to have, but not 
necessary. We now can check for the `volatile` token by properly expanding the 
grammer, rather than abusing Parse::ParseTypeQualifierListOpt.
- The parsing of `goto` was position dependent, so `asm goto volatile` wouldn't 
parse. The qualifiers should be position independent to one another. Now they 
are.
- We would warn on duplicate `volatile`, but the parse error for duplicate 
`goto` was a generic parse error and wasn't clear.
- We need to add support for the recent GNU C extension `asm inline`. Adding 
support to the parser with the above issues highlighted the need for this 
refactoring.

Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75563

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseStmtAsm.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/test/Parser/asm-qualifiers.c

Index: clang/test/Parser/asm-qualifiers.c
===
--- /dev/null
+++ clang/test/Parser/asm-qualifiers.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify %s
+
+void qualifiers(void) {
+  asm("");
+  asm volatile("");
+  asm inline("");
+  asm goto("" foo);
+foo:;
+}
+
+void underscores(void) {
+  __asm__("");
+  __asm__ __volatile__("");
+  __asm__ __inline__("");
+  // Note: goto is not supported with underscore prefix+suffix.
+  __asm__ goto("" foo);
+foo:;
+}
+
+void combinations(void) {
+  asm volatile inline("");
+  asm volatile goto("" foo);
+  asm inline goto("" foo);
+  asm volatile inline goto("" foo);
+foo:;
+}
+
+void permutations(void) {
+  asm inline volatile("");
+  asm goto volatile("");
+  asm goto inline("");
+  asm inline goto volatile("" foo);
+  asm inline volatile goto("" foo);
+  asm goto inline volatile("" foo);
+  asm goto volatile inline("" foo);
+foo:;
+}
+
+void duplicates(void) {
+  asm volatile volatile(""); // expected-error {{duplicate asm qualifier volatile}}
+  __asm__ __volatile__ __volatile__(""); // expected-error {{duplicate asm qualifier volatile}}
+  asm inline inline(""); // expected-error {{duplicate asm qualifier inline}}
+  __asm__ __inline__ __inline__(""); // expected-error {{duplicate asm qualifier inline}}
+  asm goto goto("" foo); // expected-error {{duplicate asm qualifier goto}}
+  __asm__ goto goto("" foo); // expected-error {{duplicate asm qualifier goto}}
+foo:;
+}
Index: clang/lib/Sema/DeclSpec.cpp
===
--- clang/lib/Sema/DeclSpec.cpp
+++ clang/lib/Sema/DeclSpec.cpp
@@ -589,6 +589,16 @@
   llvm_unreachable("Unknown typespec!");
 }
 
+const char *DeclSpec::getSpecifierName(AQ A) {
+  switch (A) {
+case DeclSpec::AQ_unspecified: return "unspecified";
+case DeclSpec::AQ_volatile: return "volatile";
+case DeclSpec::AQ_inline: return "inline";
+case DeclSpec::AQ_goto: return "goto";
+  }
+  llvm_unreachable("Unknown GNUAsmQualifier!");
+}
+
 bool DeclSpec::SetStorageClassSpec(Sema , SCS SC, SourceLocation Loc,
const char *,
unsigned ,
@@ -938,6 +948,16 @@
   llvm_unreachable("Unknown type qualifier!");
 }
 
+bool DeclSpec::SetGNUAsmQual(AQ A, SourceLocation Loc) {
+  if (!(A == AQ_unspecified || A == AQ_volatile || A == AQ_inline ||
+A == AQ_goto) ||
+  GNUAsmQualifiers & A)
+return true;
+
+  GNUAsmQualifiers |= A;
+  return false;
+}
+
 bool DeclSpec::setFunctionSpecInline(SourceLocation Loc, const char *,
  unsigned ) {
   // 'inline inline' is ok.  However, since this is likely not what the user
Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -684,13 +684,43 @@
 ClobberRefs, Exprs, EndLoc);
 }
 
+/// ParseGNUAsmQualifierList - Parse a GNU extended asm qualifier list.
+///   asm-qualifiers:
+/// 

[PATCH] D75563: [clang][Parse] properly parse asm-qualifiers, asm inline

2020-03-03 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

I still plan to add CodeGen support for `asm inline` before the next release, 
which should be as simple as emitting an additional `inlinehint`, but I'd like 
to save that for a follow up patch on top of this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75563/new/

https://reviews.llvm.org/D75563



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


[PATCH] D75194: [clang-format] Do not merge very long C# automatic properties

2020-03-03 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

@krasimir, well I learned something new, so thanks for taking the time to 
explain that to help improve our understanding.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75194/new/

https://reviews.llvm.org/D75194



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


[PATCH] D72041: [clangd] Handle go-to-definition in macro invocations where the target appears in the expansion multiple times

2020-03-03 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
nridge marked 4 inline comments as done.
Closed by commit rGe70a9f385025: [clangd] Handle go-to-definition in macro 
invocations where the target appears… (authored by nridge).

Changed prior to commit:
  https://reviews.llvm.org/D72041?vs=247106=248005#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72041/new/

https://reviews.llvm.org/D72041

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -338,7 +338,18 @@
#define ADDRESSOF(X) 
int *j = ADDRESSOF(^i);
   )cpp",
-
+  R"cpp(// Macro argument appearing multiple times in expansion
+#define VALIDATE_TYPE(x) (void)x;
+#define ASSERT(expr)   \
+  do { \
+VALIDATE_TYPE(expr);   \
+if (!expr);\
+  } while (false)
+bool [[waldo]]() { return true; }
+void foo() {
+  ASSERT(wa^ldo());
+}
+  )cpp",
   R"cpp(// Symbol concatenated inside macro (not supported)
int *pi;
#define POINTER(X) p ## X;
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -415,7 +415,7 @@
 
 // Regression test: this used to match the injected X, not the outer X.
 TEST(SelectionTest, InjectedClassName) {
-  const char* Code = "struct ^X { int x; };";
+  const char *Code = "struct ^X { int x; };";
   auto AST = TestTU::withCode(Annotations(Code).code()).build();
   auto T = makeSelectionTree(Code, AST);
   ASSERT_EQ("CXXRecordDecl", nodeKind(T.commonAncestor())) << T;
@@ -508,7 +508,8 @@
 }
 
 TEST(SelectionTest, MacroArgExpansion) {
-  // If a macro arg is expanded several times, we consider them all selected.
+  // If a macro arg is expanded several times, we only consider the first one
+  // selected.
   const char *Case = R"cpp(
 int mul(int, int);
 #define SQUARE(X) mul(X, X);
@@ -517,15 +518,8 @@
   Annotations Test(Case);
   auto AST = TestTU::withCode(Test.code()).build();
   auto T = makeSelectionTree(Case, AST);
-  // Unfortunately, this makes the common ancestor the CallExpr...
-  // FIXME: hack around this by picking one?
-  EXPECT_EQ("CallExpr", T.commonAncestor()->kind());
-  EXPECT_FALSE(T.commonAncestor()->Selected);
-  EXPECT_EQ(2u, T.commonAncestor()->Children.size());
-  for (const auto* N : T.commonAncestor()->Children) {
-EXPECT_EQ("IntegerLiteral", N->kind());
-EXPECT_TRUE(N->Selected);
-  }
+  EXPECT_EQ("IntegerLiteral", T.commonAncestor()->kind());
+  EXPECT_TRUE(T.commonAncestor()->Selected);
 
   // Verify that the common assert() macro doesn't suffer from this.
   // (This is because we don't associate the stringified token with the arg).
@@ -542,7 +536,7 @@
 }
 
 TEST(SelectionTest, Implicit) {
-  const char* Test = R"cpp(
+  const char *Test = R"cpp(
 struct S { S(const char*); };
 int f(S);
 int x = f("^");
Index: clang-tools-extra/clangd/Selection.h
===
--- clang-tools-extra/clangd/Selection.h
+++ clang-tools-extra/clangd/Selection.h
@@ -64,6 +64,9 @@
 //
 // SelectionTree tries to behave sensibly in the presence of macros, but does
 // not model any preprocessor concepts: the output is a subset of the AST.
+// When a macro argument is specifically selected, only its first expansion is
+// selected in the AST. (Returning a selection forest is unreasonably difficult
+// for callers to handle correctly.)
 //
 // Comments, directives and whitespace are completely ignored.
 // Semicolons are also ignored, as the AST generally does not model them well.
@@ -127,15 +130,15 @@
 Selection Selected;
 // Walk up the AST to get the DeclContext of this Node,
 // which is not the node itself.
-const DeclContext& getDeclContext() const;
+const DeclContext () const;
 // Printable node kind, like "CXXRecordDecl" or "AutoTypeLoc".
 std::string kind() const;
 // If this node is a wrapper with no syntax (e.g. implicit cast), return
 // its contents. (If multiple wrappers are present, unwraps all of them).
-const Node& ignoreImplicit() const;
+const Node () const;
 // If this node is inside a wrapper with no syntax (e.g. implicit cast),
 // return that wrapper. (If multiple are present, unwraps all of them).
-const Node& outerImplicit() const;
+const Node () const;
   };
   // 

[PATCH] D75215: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-03-03 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked an inline comment as done.
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:989
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+if (!CXXRD->hasDefinition() ||

rnk wrote:
> I think this code block needs a comment about the behavior we are trying to 
> implement. It could be made CodeView-specific, but I don't see a strong 
> reason not to set these flags when emitting DWARF.
Yep, will add a comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75215/new/

https://reviews.llvm.org/D75215



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


[PATCH] D73649: [CodeComplete] Member completion for concept-constrained types.

2020-03-03 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks! Consider the patch "accepted" from my POV.

One last nit: please link to https://github.com/clangd/clangd/issues/261 in the 
commit message


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73649/new/

https://reviews.llvm.org/D73649



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


[PATCH] D75215: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-03-03 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 248001.
akhuang added a comment.

Splitting the forward declaration flag into a different review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75215/new/

https://reviews.llvm.org/D75215

Files:
  clang/test/CodeGenCXX/debug-info-flag-nontrivial.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/function-options.ll

Index: llvm/test/DebugInfo/COFF/function-options.ll
===
--- llvm/test/DebugInfo/COFF/function-options.ll
+++ llvm/test/DebugInfo/COFF/function-options.ll
@@ -1,10 +1,8 @@
-; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s
-; RUN: llc < %s | llvm-mc -filetype=obj --triple=x86_64-windows | llvm-readobj - --codeview | FileCheck %s
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
 ;
 ; Command to generate function-options.ll
 ; $ clang++ function-options.cpp -S -emit-llvm -g -gcodeview -o function-options.ll
 ;
-;
 ; #define DEFINE_FUNCTION(T) \
 ;   T Func_##T(T ) { return arg; }
 ;
@@ -32,7 +30,11 @@
 ; class DClass : public BClass {}; // Note: MSVC yields one compiler-generated ctor for DClass while clang doesn't.
 ; DEFINE_FUNCTION(DClass); // Expect: FO = CxxReturnUdt
 ;
-; class FClass { static int x; };
+; class FClass {
+;   static int x;
+;   AClass Member_AClass(AClass &);
+;   BClass Member_BClass(BClass &);
+; };
 ; DEFINE_FUNCTION(FClass); // Expect FO = None
 ; 
 ; struct AStruct {};
@@ -54,7 +56,7 @@
 ; CHECK: CodeViewTypes [
 ; CHECK:   Section: .debug$T ({{.*}})
 ; CHECK:   Magic: 0x4
-; CHECK:   Procedure ([[SP1:.*]]) {
+; CHECK:   Procedure ([[SP_A:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: AClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -66,10 +68,10 @@
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: AClass (AClass&) ([[SP1]])
+; CHECK: FunctionType: AClass (AClass&) ([[SP_A]])
 ; CHECK: Name: Func_AClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP2:.*]]) {
+; CHECK:   Procedure ([[SP_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: BClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -79,11 +81,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (BClass&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF1:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: BClass ({{.*}})
-; CHECK: ThisType: BClass* const ({{.*}})
+; CHECK: ThisType: BClass* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x2)
 ; CHECK:   Constructor (0x2)
@@ -97,17 +99,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Private (0x1)
-; CHECK:   Type: void BClass::() ([[MF1]])
+; CHECK:   Type: void BClass::() ([[CTOR_B]])
 ; CHECK:   Name: BClass
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: BClass (BClass&) ([[SP2]])
+; CHECK: FunctionType: BClass (BClass&) ([[SP_B]])
 ; CHECK: Name: Func_BClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP3:.*]]) {
+; CHECK:   Procedure ([[SP_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: C1Class ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -116,11 +118,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (C1Class&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF2:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: C1Class ({{.*}})
-; CHECK: ThisType: C1Class* const ({{.*}})
+; CHECK: ThisType: C1Class* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x0)
 ; CHECK: ]
@@ -133,17 +135,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Public (0x3)
-; CHECK:   Type: void C1Class::() ([[MF2]])
+; CHECK:   Type: void C1Class::() ([[CTOR_C1]])
 ; CHECK:   Name: C1Class
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: C1Class (C1Class&) ([[SP3]])
+; CHECK: FunctionType: C1Class (C1Class&) ([[SP_C1]])
 ; CHECK: Name: Func_C1Class
 ; CHECK:   }
-; CHECK:   Procedure ([[SP4:.*]]) {
+; CHECK:   Procedure ([[SP_C2:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: C2Class ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ 

[PATCH] D75538: [clang-tidy] Updated language supported restrictions on some checks

2020-03-03 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp:1
-// RUN: %check_clang_tidy -std=c++98 %s modernize-use-nullptr %t -- -- 
-Wno-non-literal-null-conversion
-//

njames93 wrote:
> alexfh wrote:
> > IIRC, some of the modernize- checks were meant to be useful to make the 
> > pre-C++11 code compile in C++11. This check is an example of this (maybe 
> > the only one?). Limiting the check to C++11 and deleting this test is a bit 
> > too radical.
> I'm lost, this check is all about replacing assignment of pointer to 0 with 
> `nullptr` a keyword which doesn't exist pre c++11, so this test case will 
> just result in invalid code. Or am I missing the point?
The idea, if I understand correctly, is that you start with C++98 code, apply 
modernize-* checks, and get C++11 code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75538/new/

https://reviews.llvm.org/D75538



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


[PATCH] D75215: [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-03-03 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 248003.
akhuang added a comment.

add back line in test that accidentally got deleted


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75215/new/

https://reviews.llvm.org/D75215

Files:
  clang/test/CodeGenCXX/debug-info-flag-nontrivial.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/function-options.ll

Index: llvm/test/DebugInfo/COFF/function-options.ll
===
--- llvm/test/DebugInfo/COFF/function-options.ll
+++ llvm/test/DebugInfo/COFF/function-options.ll
@@ -1,10 +1,10 @@
-; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s
-; RUN: llc < %s | llvm-mc -filetype=obj --triple=x86_64-windows | llvm-readobj - --codeview | FileCheck %s
+; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
+; RUN: llc < %s | llvm-mc -filetype=obj --triple=x86_64-windows | \
+; RUN:   llvm-readobj - --codeview | FileCheck %s
 ;
 ; Command to generate function-options.ll
 ; $ clang++ function-options.cpp -S -emit-llvm -g -gcodeview -o function-options.ll
 ;
-;
 ; #define DEFINE_FUNCTION(T) \
 ;   T Func_##T(T ) { return arg; }
 ;
@@ -32,7 +32,11 @@
 ; class DClass : public BClass {}; // Note: MSVC yields one compiler-generated ctor for DClass while clang doesn't.
 ; DEFINE_FUNCTION(DClass); // Expect: FO = CxxReturnUdt
 ;
-; class FClass { static int x; };
+; class FClass {
+;   static int x;
+;   AClass Member_AClass(AClass &);
+;   BClass Member_BClass(BClass &);
+; };
 ; DEFINE_FUNCTION(FClass); // Expect FO = None
 ; 
 ; struct AStruct {};
@@ -54,7 +58,7 @@
 ; CHECK: CodeViewTypes [
 ; CHECK:   Section: .debug$T ({{.*}})
 ; CHECK:   Magic: 0x4
-; CHECK:   Procedure ([[SP1:.*]]) {
+; CHECK:   Procedure ([[SP_A:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: AClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -66,10 +70,10 @@
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: AClass (AClass&) ([[SP1]])
+; CHECK: FunctionType: AClass (AClass&) ([[SP_A]])
 ; CHECK: Name: Func_AClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP2:.*]]) {
+; CHECK:   Procedure ([[SP_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: BClass ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -79,11 +83,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (BClass&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF1:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_B:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: BClass ({{.*}})
-; CHECK: ThisType: BClass* const ({{.*}})
+; CHECK: ThisType: BClass* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x2)
 ; CHECK:   Constructor (0x2)
@@ -97,17 +101,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Private (0x1)
-; CHECK:   Type: void BClass::() ([[MF1]])
+; CHECK:   Type: void BClass::() ([[CTOR_B]])
 ; CHECK:   Name: BClass
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: BClass (BClass&) ([[SP2]])
+; CHECK: FunctionType: BClass (BClass&) ([[SP_B]])
 ; CHECK: Name: Func_BClass
 ; CHECK:   }
-; CHECK:   Procedure ([[SP3:.*]]) {
+; CHECK:   Procedure ([[SP_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008)
 ; CHECK: ReturnType: C1Class ({{.*}})
 ; CHECK: CallingConvention: NearC (0x0)
@@ -116,11 +120,11 @@
 ; CHECK: NumParameters: 1
 ; CHECK: ArgListType: (C1Class&) ({{.*}})
 ; CHECK:   }
-; CHECK:   MemberFunction ([[MF2:.*]]) {
+; CHECK:   MemberFunction ([[CTOR_C1:.*]]) {
 ; CHECK: TypeLeafKind: LF_MFUNCTION (0x1009)
 ; CHECK: ReturnType: void (0x3)
 ; CHECK: ClassType: C1Class ({{.*}})
-; CHECK: ThisType: C1Class* const ({{.*}})
+; CHECK: ThisType: C1Class* {{.*}}
 ; CHECK: CallingConvention: NearC (0x0)
 ; CHECK: FunctionOptions [ (0x0)
 ; CHECK: ]
@@ -133,17 +137,17 @@
 ; CHECK: OneMethod {
 ; CHECK:   TypeLeafKind: LF_ONEMETHOD (0x1511)
 ; CHECK:   AccessSpecifier: Public (0x3)
-; CHECK:   Type: void C1Class::() ([[MF2]])
+; CHECK:   Type: void C1Class::() ([[CTOR_C1]])
 ; CHECK:   Name: C1Class
 ; CHECK: }
 ; CHECK:   }
 ; CHECK:   FuncId ({{.*}}) {
 ; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601)
 ; CHECK: ParentScope: 0x0
-; CHECK: FunctionType: C1Class (C1Class&) ([[SP3]])
+; CHECK: FunctionType: C1Class (C1Class&) ([[SP_C1]])
 ; CHECK: Name: Func_C1Class
 ; CHECK:   }
-; CHECK:   Procedure ([[SP4:.*]]) {
+; CHECK:   Procedure ([[SP_C2:.*]]) {
 ; CHECK: TypeLeafKind: 

[PATCH] D75560: Make Decl::setFromASTFile() public. (NFC)

2020-03-03 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl created this revision.
aprantl added reviewers: teemperor, rsmith, shafik.

This API is going to be used by LLDB to recreate owning module information for 
Decls deserializwed from DWARF.


https://reviews.llvm.org/D75560

Files:
  clang/include/clang/AST/DeclBase.h


Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -626,13 +626,15 @@
 setModuleOwnershipKind(ModuleOwnershipKind::ModulePrivate);
   }
 
+public:
+  void setFromASTFile() { FromASTFile = true; }
+
   /// Set the owning module ID.
   void setOwningModuleID(unsigned ID) {
 assert(isFromASTFile() && "Only works on a deserialized declaration");
 *((unsigned*)this - 2) = ID;
   }
 
-public:
   /// Determine the availability of the given declaration.
   ///
   /// This routine will determine the most restrictive availability of


Index: clang/include/clang/AST/DeclBase.h
===
--- clang/include/clang/AST/DeclBase.h
+++ clang/include/clang/AST/DeclBase.h
@@ -626,13 +626,15 @@
 setModuleOwnershipKind(ModuleOwnershipKind::ModulePrivate);
   }
 
+public:
+  void setFromASTFile() { FromASTFile = true; }
+
   /// Set the owning module ID.
   void setOwningModuleID(unsigned ID) {
 assert(isFromASTFile() && "Only works on a deserialized declaration");
 *((unsigned*)this - 2) = ID;
   }
 
-public:
   /// Determine the availability of the given declaration.
   ///
   /// This routine will determine the most restrictive availability of
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75292: [clangd] Remove vsc-extension-quickstart.md from the vscode-clangd plugin

2020-03-03 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 247996.
nridge added a comment.

Remove entire file


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75292/new/

https://reviews.llvm.org/D75292

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/vsc-extension-quickstart.md


Index: 
clang-tools-extra/clangd/clients/clangd-vscode/vsc-extension-quickstart.md
===
--- clang-tools-extra/clangd/clients/clangd-vscode/vsc-extension-quickstart.md
+++ /dev/null
@@ -1,33 +0,0 @@
-# Toy VS Code Extension for clangd
-
-## What's in the folder
-* This folder contains all of the files necessary for your extension
-* `package.json` - this is the manifest file in which you declare your 
extension and command.
-The sample plugin registers a command and defines its title and command name. 
With this information
-VS Code can show the command in the command palette. It doesn’t yet need to 
load the plugin.
-* `src/extension.ts` - this is the main file where you will provide the 
implementation of your command.
-The file exports one function, `activate`, which is called the very first time 
your extension is
-activated (in this case by executing the command). Inside the `activate` 
function we call `registerCommand`.
-We pass the function containing the implementation of the command as the 
second parameter to
-`registerCommand`.
-
-## Get up and running straight away
-* press `F5` to open a new window with your extension loaded
-* run your command from the command palette by pressing (`Ctrl+Shift+P` or 
`Cmd+Shift+P` on Mac) and typing `Hello World`
-* set breakpoints in your code inside `src/extension.ts` to debug your 
extension
-* find output from your extension in the debug console
-
-## Make changes
-* you can relaunch the extension from the debug toolbar after changing code in 
`src/extension.ts`
-* you can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with 
your extension to load your changes
-
-## Explore the API
-* you can open the full set of our API when you open the file 
`node_modules/vscode/vscode.d.ts`
-
-## Run tests
-* open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the 
launch configuration dropdown pick `Launch Tests`
-* press `F5` to run the tests in a new window with your extension loaded
-* see the output of the test result in the debug console
-* make changes to `test/extension.test.ts` or create new test files inside the 
`test` folder
-* by convention, the test runner will only consider files matching the 
name pattern `**.test.ts`
-* you can create folders inside the `test` folder to structure your tests 
any way you want
\ No newline at end of file


Index: clang-tools-extra/clangd/clients/clangd-vscode/vsc-extension-quickstart.md
===
--- clang-tools-extra/clangd/clients/clangd-vscode/vsc-extension-quickstart.md
+++ /dev/null
@@ -1,33 +0,0 @@
-# Toy VS Code Extension for clangd
-
-## What's in the folder
-* This folder contains all of the files necessary for your extension
-* `package.json` - this is the manifest file in which you declare your extension and command.
-The sample plugin registers a command and defines its title and command name. With this information
-VS Code can show the command in the command palette. It doesn’t yet need to load the plugin.
-* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
-The file exports one function, `activate`, which is called the very first time your extension is
-activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
-We pass the function containing the implementation of the command as the second parameter to
-`registerCommand`.
-
-## Get up and running straight away
-* press `F5` to open a new window with your extension loaded
-* run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`
-* set breakpoints in your code inside `src/extension.ts` to debug your extension
-* find output from your extension in the debug console
-
-## Make changes
-* you can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`
-* you can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes
-
-## Explore the API
-* you can open the full set of our API when you open the file `node_modules/vscode/vscode.d.ts`
-
-## Run tests
-* open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Launch Tests`
-* press `F5` to run the tests in a new window with your extension loaded
-* see the output of the test result in the debug console
-* make changes to `test/extension.test.ts` or create new test files inside the `test` folder
-* by convention, the test runner will only 

[PATCH] D75492: [clang-tidy]: modernize-use-using: don't diagnose typedefs in `extern "C"` DeclContexts

2020-03-03 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv planned changes to this revision.
george.burgess.iv added a comment.

I see -- that seems like a much broader change, but also probably worthwhile. I 
have a few ideas about how to tackle that; let me see what I can come up with 
locally.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75492/new/

https://reviews.llvm.org/D75492



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


[PATCH] D75561: Remove const qualifier from Modules returned by ExternalASTSource. (NFC)

2020-03-03 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl created this revision.
aprantl added reviewers: teemperor, rsmith, shafik.

This API is used by LLDB to attach owning module information to Declarations 
deserialized from DWARF.


https://reviews.llvm.org/D75561

Files:
  clang/include/clang/AST/ExternalASTSource.h
  clang/lib/AST/ExternalASTSource.cpp
  clang/lib/Serialization/ASTReader.cpp


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -8493,7 +8493,7 @@
 
 llvm::Optional
 ASTReader::getSourceDescriptor(unsigned ID) {
-  if (const Module *M = getSubmodule(ID))
+  if (Module *M = getSubmodule(ID))
 return ExternalASTSource::ASTSourceDescriptor(*M);
 
   // If there is only a single PCH, return it instead.
Index: clang/lib/AST/ExternalASTSource.cpp
===
--- clang/lib/AST/ExternalASTSource.cpp
+++ clang/lib/AST/ExternalASTSource.cpp
@@ -39,7 +39,7 @@
   return EK_ReplyHazy;
 }
 
-ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module )
+ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(Module )
   : Signature(M.Signature), ClangModule() {
   if (M.Directory)
 Path = M.Directory->getName();
Index: clang/include/clang/AST/ExternalASTSource.h
===
--- clang/include/clang/AST/ExternalASTSource.h
+++ clang/include/clang/AST/ExternalASTSource.h
@@ -173,7 +173,7 @@
 StringRef Path;
 StringRef ASTFile;
 ASTFileSignature Signature;
-const Module *ClangModule = nullptr;
+Module *ClangModule = nullptr;
 
   public:
 ASTSourceDescriptor() = default;
@@ -181,13 +181,13 @@
 ASTFileSignature Signature)
 : PCHModuleName(std::move(Name)), Path(std::move(Path)),
   ASTFile(std::move(ASTFile)), Signature(Signature) {}
-ASTSourceDescriptor(const Module );
+ASTSourceDescriptor(Module );
 
 std::string getModuleName() const;
 StringRef getPath() const { return Path; }
 StringRef getASTFile() const { return ASTFile; }
 ASTFileSignature getSignature() const { return Signature; }
-const Module *getModuleOrNull() const { return ClangModule; }
+Module *getModuleOrNull() const { return ClangModule; }
   };
 
   /// Return a descriptor for the corresponding module, if one exists.


Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -8493,7 +8493,7 @@
 
 llvm::Optional
 ASTReader::getSourceDescriptor(unsigned ID) {
-  if (const Module *M = getSubmodule(ID))
+  if (Module *M = getSubmodule(ID))
 return ExternalASTSource::ASTSourceDescriptor(*M);
 
   // If there is only a single PCH, return it instead.
Index: clang/lib/AST/ExternalASTSource.cpp
===
--- clang/lib/AST/ExternalASTSource.cpp
+++ clang/lib/AST/ExternalASTSource.cpp
@@ -39,7 +39,7 @@
   return EK_ReplyHazy;
 }
 
-ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module )
+ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(Module )
   : Signature(M.Signature), ClangModule() {
   if (M.Directory)
 Path = M.Directory->getName();
Index: clang/include/clang/AST/ExternalASTSource.h
===
--- clang/include/clang/AST/ExternalASTSource.h
+++ clang/include/clang/AST/ExternalASTSource.h
@@ -173,7 +173,7 @@
 StringRef Path;
 StringRef ASTFile;
 ASTFileSignature Signature;
-const Module *ClangModule = nullptr;
+Module *ClangModule = nullptr;
 
   public:
 ASTSourceDescriptor() = default;
@@ -181,13 +181,13 @@
 ASTFileSignature Signature)
 : PCHModuleName(std::move(Name)), Path(std::move(Path)),
   ASTFile(std::move(ASTFile)), Signature(Signature) {}
-ASTSourceDescriptor(const Module );
+ASTSourceDescriptor(Module );
 
 std::string getModuleName() const;
 StringRef getPath() const { return Path; }
 StringRef getASTFile() const { return ASTFile; }
 ASTFileSignature getSignature() const { return Signature; }
-const Module *getModuleOrNull() const { return ClangModule; }
+Module *getModuleOrNull() const { return ClangModule; }
   };
 
   /// Return a descriptor for the corresponding module, if one exists.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73649: [CodeComplete] Member completion for concept-constrained types.

2020-03-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 247993.
sammccall added a comment.

comment and tweak order of AccessOperator


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73649/new/

https://reviews.llvm.org/D73649

Files:
  clang/include/clang/Sema/Scope.h
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/concepts.cpp

Index: clang/test/CodeCompletion/concepts.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/concepts.cpp
@@ -0,0 +1,59 @@
+template  concept convertible_to = true;
+template  concept same_as = true;
+template  concept integral = true;
+
+template 
+concept W = requires(A a, B b) {
+  { b.www } noexcept -> integral;
+};
+
+template  concept X = requires(T t) {
+  t.xxx(42);
+  typename T::xxx_t;
+  T::xyz::member;
+};
+
+template 
+concept Y = requires(T t, U u) { t.yyy(u); };
+
+template 
+concept Z = requires(T t) {
+  { t.zzz() } -> same_as;
+  requires W;
+};
+
+// Concept constraints in all three slots require X, Y, Z, and ad-hoc stuff.
+template 
+requires Y && requires(T *t) { { t->aaa() } -> convertible_to; }
+void foo(T t) requires Z || requires(T ) { t.bbb(); t->bb(); } {
+  t.x;
+  t->x;
+  T::x;
+
+  // RUN: %clang_cc1 -std=c++2a -code-completion-with-fixits -code-completion-at=%s:29:5 %s \
+  // RUN: | FileCheck %s -check-prefix=DOT -implicit-check-not=xxx_t
+  // DOT: Pattern : [#convertible_to#]aaa()
+  // DOT: Pattern : bb() (requires fix-it: {{.*}} to "->")
+  // DOT: Pattern : bbb()
+  // DOT: Pattern : [#integral#]www
+  // DOT: Pattern : xxx(<#int#>)
+  // FIXME: it would be nice to have int instead of U here.
+  // DOT: Pattern : yyy(<#U#>)
+  // DOT: Pattern : [#int#]zzz()
+
+  // RUN: %clang_cc1 -std=c++2a -code-completion-with-fixits -code-completion-at=%s:30:6 %s \
+  // RUN: | FileCheck %s -check-prefix=ARROW -implicit-check-not=xxx_t
+  // ARROW: Pattern : [#convertible_to#]aaa() (requires fix-it: {{.*}} to ".")
+  // ARROW: Pattern : bb()
+  // ARROW: Pattern : bbb() (requires fix-it
+  // ARROW: Pattern : [#integral#]www (requires fix-it
+  // ARROW: Pattern : xxx(<#int#>) (requires fix-it
+  // ARROW: Pattern : yyy(<#U#>) (requires fix-it
+  // ARROW: Pattern : [#int#]zzz() (requires fix-it
+
+  // RUN: %clang_cc1 -std=c++2a -code-completion-with-fixits -code-completion-at=%s:31:6 %s \
+  // RUN: | FileCheck %s -check-prefix=COLONS -implicit-check-not=yyy
+  // COLONS: Pattern : xxx_t
+  // COLONS: Pattern : xyz
+}
+
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -9,6 +9,7 @@
 //  This file defines the code-completion semantic actions.
 //
 //===--===//
+#include "clang/AST/ASTConcept.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
@@ -16,8 +17,11 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/ExprConcepts.h"
 #include "clang/AST/ExprObjC.h"
+#include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/QualTypeNames.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/Specifiers.h"
@@ -4746,6 +4750,365 @@
   return nullptr;
 }
 
+namespace {
+// Collects completion-relevant information about a concept-constrainted type T.
+// In particular, examines the constraint expressions to find members of T.
+//
+// The design is very simple: we walk down each constraint looking for
+// expressions of the form T.foo().
+// If we're extra lucky, the return type is specified.
+// We don't do any clever handling of && or || in constraint expressions, we
+// take members from both branches.
+//
+// For example, given:
+//   template  concept X = requires (T t, string& s) { t.print(s); };
+//   template  void foo(U u) { u.^ }
+// We want to suggest the inferred member function 'print(string)'.
+// We see that u has type U, so X holds.
+// X requires t.print(s) to be valid, where t has type U (substituted for T).
+// By looking at the CallExpr we find the signature of print().
+//
+// While we tend to know in advance which kind of members (access via . -> ::)
+// we want, it's simpler just to gather them all and post-filter.
+//
+// FIXME: some of this machinery could be used for non-concept type-parms too,
+// enabling completion for type parameters based on other uses of that param.
+//
+// FIXME: there are other cases where a type can be constrained by a concept,
+// e.g. inside `if constexpr(ConceptSpecializationExpr) { ... }`
+class ConceptInfo {
+public:
+  // Describes a likely member of a type, inferred by concept constraints.
+  // Offered as a code completion for T. T-> and T:: contexts.
+  

[PATCH] D75517: [clang-format] Do not format C# array subscript operators as attributes

2020-03-03 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/TokenAnnotator.cpp:376
+
+// Chains [] in of `identifier[i][j][k]` are not attributes.
+if (Tok.Previous && Tok.Previous->is(tok::r_square)) {

nit: `// Chains of [] in ...`



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:626
+  // Do not format array subscript operators as attributes.
+  verifyFormat(R"(if (someThings[index].Contains(myThing)) {)", Style);
+  verifyFormat(R"(if (someThings[i][j][k].Contains(myThing)) {)", Style);

please add a `}` at the end of this examples so that the braces are balanced, 
otherwise the examples read as incomplete.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75517/new/

https://reviews.llvm.org/D75517



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


[PATCH] D75538: [clang-tidy] Updated language supported restrictions on some checks

2020-03-03 Thread Nathan James via Phabricator via cfe-commits
njames93 marked an inline comment as done.
njames93 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-use-nullptr-basic.cpp:1
-// RUN: %check_clang_tidy -std=c++98 %s modernize-use-nullptr %t -- -- 
-Wno-non-literal-null-conversion
-//

alexfh wrote:
> IIRC, some of the modernize- checks were meant to be useful to make the 
> pre-C++11 code compile in C++11. This check is an example of this (maybe the 
> only one?). Limiting the check to C++11 and deleting this test is a bit too 
> radical.
I'm lost, this check is all about replacing assignment of pointer to 0 with 
`nullptr` a keyword which doesn't exist pre c++11, so this test case will just 
result in invalid code. Or am I missing the point?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75538/new/

https://reviews.llvm.org/D75538



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


[PATCH] D73649: [CodeComplete] Member completion for concept-constrained types.

2020-03-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5006
+  if (/*Inserted*/ R.second ||
+  std::make_tuple(M.Operator, M.ArgTypes.hasValue(),
+  M.ResultType != nullptr) >

nridge wrote:
> So `Colons` is more info than `Arrow` which is more info than `Dot`? Is there 
> some intuition behind that?
no, it's basically arbitrary.
I don't think collisions between these are likely and worth dealing with 
carefully, but making the choice consistently seems worthwhile to me, in case 
someone ever has to debug it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73649/new/

https://reviews.llvm.org/D73649



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


[PATCH] D73649: [CodeComplete] Member completion for concept-constrained types.

2020-03-03 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4972
+
+// In T::foo::bar, `foo` must be a type.
+bool VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {

nridge wrote:
> sammccall wrote:
> > nridge wrote:
> > > It would be nice if the test exercised this case.
> > Oops, this was actually broken because VisitNestedNameSpecifier doesn't 
> > seem to be a thing :-(
> > Fixed to use TraverseNestedNameSpecifierLoc and added a test.
> > Oops, this was actually broken because VisitNestedNameSpecifier doesn't 
> > seem to be a thing :-(
> 
> (I suspected this, but the heavy macro usage in `RecursiveASTVisitor.h` made 
> me second-guess myself and think I was just overlooking a place that defines 
> `VisitNestedNameSpecifier`. I figured adding a test wouldn't hurt even if I'm 
> mistaken and the code works. :-))
(Tangentially related, but a C++ editor feature I sometimes wish existed was to 
show a (semantically-colored and navigation-feature-enabled) 
//post-preprocessing// view of a source file. (But not edit that view! That 
would be madness.) Something to add to the backlog, perhaps.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73649/new/

https://reviews.llvm.org/D73649



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


[clang-tools-extra] e70a9f3 - [clangd] Handle go-to-definition in macro invocations where the target appears in the expansion multiple times

2020-03-03 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2020-03-03T15:52:05-05:00
New Revision: e70a9f3850255cb610fc56a30dec6f52b9d734e9

URL: 
https://github.com/llvm/llvm-project/commit/e70a9f3850255cb610fc56a30dec6f52b9d734e9
DIFF: 
https://github.com/llvm/llvm-project/commit/e70a9f3850255cb610fc56a30dec6f52b9d734e9.diff

LOG: [clangd] Handle go-to-definition in macro invocations where the target 
appears in the expansion multiple times

Fixes https://github.com/clangd/clangd/issues/234

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, 
cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/Selection.cpp
clang-tools-extra/clangd/Selection.h
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index d1438d134e15..db96357083f6 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -52,8 +52,7 @@ using ast_type_traits::DynTypedNode;
 // On traversing an AST node, its token range is erased from the unclaimed set.
 // The tokens actually removed are associated with that node, and hit-tested
 // against the selection to determine whether the node is selected.
-template 
-class IntervalSet {
+template  class IntervalSet {
 public:
   IntervalSet(llvm::ArrayRef Range) { UnclaimedRanges.insert(Range); }
 
@@ -78,7 +77,7 @@ class IntervalSet {
   --Overlap.first;
   // ...unless B isn't selected at all.
   if (Overlap.first->end() <= Claim.begin())
-  ++Overlap.first;
+++Overlap.first;
 }
 if (Overlap.first == Overlap.second)
   return Out;
@@ -118,8 +117,7 @@ class IntervalSet {
   };
 
   // Disjoint sorted unclaimed ranges of expanded tokens.
-  std::set, RangeLess>
-  UnclaimedRanges;
+  std::set, RangeLess> UnclaimedRanges;
 };
 
 // Sentinel value for the selectedness of a node where we've seen no tokens 
yet.
@@ -148,11 +146,37 @@ bool shouldIgnore(const syntax::Token ) {
   return Tok.kind() == tok::comment || Tok.kind() == tok::semi;
 }
 
+// Determine whether 'Target' is the first expansion of the macro
+// argument whose top-level spelling location is 'SpellingLoc'.
+bool isFirstExpansion(FileID Target, SourceLocation SpellingLoc,
+  const SourceManager ) {
+  SourceLocation Prev = SpellingLoc;
+  while (true) {
+// If the arg is expanded multiple times, getMacroArgExpandedLocation()
+// returns the first expansion.
+SourceLocation Next = SM.getMacroArgExpandedLocation(Prev);
+// So if we reach the target, target is the first-expansion of the
+// first-expansion ...
+if (SM.getFileID(Next) == Target)
+  return true;
+
+// Otherwise, if the FileID stops changing, we've reached the innermost
+// macro expansion, and Target was on a 
diff erent branch.
+if (SM.getFileID(Next) == SM.getFileID(Prev))
+  return false;
+
+Prev = Next;
+  }
+  return false;
+}
+
 // SelectionTester can determine whether a range of tokens from the PP-expanded
 // stream (corresponding to an AST node) is considered selected.
 //
 // When the tokens result from macro expansions, the appropriate tokens in the
 // main file are examined (macro invocation or args). Similarly for #includes.
+// However, only the first expansion of a given spelled token is considered
+// selected.
 //
 // It tests each token in the range (not just the endpoints) as contiguous
 // expanded tokens may not have contiguous spellings (with macros).
@@ -260,9 +284,14 @@ class SelectionTester {
 // Handle tokens that were passed as a macro argument.
 SourceLocation ArgStart = SM.getTopMacroCallerLoc(StartLoc);
 if (SM.getFileID(ArgStart) == SelFile) {
-  SourceLocation ArgEnd = SM.getTopMacroCallerLoc(Batch.back().location());
-  return testTokenRange(SM.getFileOffset(ArgStart),
-SM.getFileOffset(ArgEnd));
+  if (isFirstExpansion(FID, ArgStart, SM)) {
+SourceLocation ArgEnd =
+SM.getTopMacroCallerLoc(Batch.back().location());
+return testTokenRange(SM.getFileOffset(ArgStart),
+  SM.getFileOffset(ArgEnd));
+  } else {
+/* fall through and treat as part of the macro body */
+  }
 }
 
 // Handle tokens produced by non-argument macro expansion.
@@ -346,7 +375,7 @@ std::string printNodeToString(const DynTypedNode , const 
PrintingPolicy ) {
 }
 #endif
 
-bool isImplicit(const Stmt* S) {
+bool isImplicit(const Stmt *S) {
   // Some Stmts are implicit and shouldn't be traversed, but there's no
   // "implicit" attribute on Stmt/Expr.
   // Unwrap implicit casts first if present (other nodes too?).
@@ -611,7 +640,7 @@ class 

[PATCH] D75223: [clang-offload-wrapper] Lower priority of __tgt_register_lib in favor of __tgt_register_requires

2020-03-03 Thread George Rokos via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfca49fe8e34f: [clang-offload-wrapper] Lower priority of 
__tgt_register_lib in favor of… (authored by grokos).

Changed prior to commit:
  https://reviews.llvm.org/D75223?vs=246870=247991#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75223/new/

https://reviews.llvm.org/D75223

Files:
  clang/test/Driver/clang-offload-wrapper.c
  clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp


Index: clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
===
--- clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
+++ clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
@@ -262,7 +262,12 @@
 Builder.CreateRetVoid();
 
 // Add this function to constructors.
-appendToGlobalCtors(M, Func, 0);
+// Set priority to 1 so that __tgt_register_lib is executed AFTER
+// __tgt_register_requires (we want to know what requirements have been
+// asked for before we load a libomptarget plugin so that by the time the
+// plugin is loaded it can report how many devices there are which can
+// satisfy these requirements).
+appendToGlobalCtors(M, Func, /*Priority*/ 1);
   }
 
   void createUnregisterFunction(GlobalVariable *BinDesc) {
@@ -283,7 +288,8 @@
 Builder.CreateRetVoid();
 
 // Add this function to global destructors.
-appendToGlobalDtors(M, Func, 0);
+// Match priority of __tgt_register_lib
+appendToGlobalDtors(M, Func, /*Priority*/ 1);
   }
 
 public:
Index: clang/test/Driver/clang-offload-wrapper.c
===
--- clang/test/Driver/clang-offload-wrapper.c
+++ clang/test/Driver/clang-offload-wrapper.c
@@ -39,8 +39,8 @@
 
 // CHECK-IR: [[DESC:@.+]] = internal constant [[DESCTY]] { i32 1, [[IMAGETY]]* 
getelementptr inbounds ([1 x [[IMAGETY]]], [1 x [[IMAGETY]]]* [[IMAGES]], i64 
0, i64 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }
 
-// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* 
}] [{ i32, void ()*, i8* } { i32 0, void ()* [[REGFN:@.+]], i8* null }]
-// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* 
}] [{ i32, void ()*, i8* } { i32 0, void ()* [[UNREGFN:@.+]], i8* null }]
+// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* 
}] [{ i32, void ()*, i8* } { i32 1, void ()* [[REGFN:@.+]], i8* null }]
+// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* 
}] [{ i32, void ()*, i8* } { i32 1, void ()* [[UNREGFN:@.+]], i8* null }]
 
 // CHECK-IR: define internal void [[REGFN]]()
 // CHECK-IR:   call void @__tgt_register_lib([[DESCTY]]* [[DESC]])


Index: clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
===
--- clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
+++ clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
@@ -262,7 +262,12 @@
 Builder.CreateRetVoid();
 
 // Add this function to constructors.
-appendToGlobalCtors(M, Func, 0);
+// Set priority to 1 so that __tgt_register_lib is executed AFTER
+// __tgt_register_requires (we want to know what requirements have been
+// asked for before we load a libomptarget plugin so that by the time the
+// plugin is loaded it can report how many devices there are which can
+// satisfy these requirements).
+appendToGlobalCtors(M, Func, /*Priority*/ 1);
   }
 
   void createUnregisterFunction(GlobalVariable *BinDesc) {
@@ -283,7 +288,8 @@
 Builder.CreateRetVoid();
 
 // Add this function to global destructors.
-appendToGlobalDtors(M, Func, 0);
+// Match priority of __tgt_register_lib
+appendToGlobalDtors(M, Func, /*Priority*/ 1);
   }
 
 public:
Index: clang/test/Driver/clang-offload-wrapper.c
===
--- clang/test/Driver/clang-offload-wrapper.c
+++ clang/test/Driver/clang-offload-wrapper.c
@@ -39,8 +39,8 @@
 
 // CHECK-IR: [[DESC:@.+]] = internal constant [[DESCTY]] { i32 1, [[IMAGETY]]* getelementptr inbounds ([1 x [[IMAGETY]]], [1 x [[IMAGETY]]]* [[IMAGES]], i64 0, i64 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }
 
-// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* [[REGFN:@.+]], i8* null }]
-// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* [[UNREGFN:@.+]], i8* null }]
+// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* [[REGFN:@.+]], i8* null }]
+// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* [[UNREGFN:@.+]], i8* null }]
 
 // CHECK-IR: define 

[PATCH] D75194: [clang-format] Do not merge very long C# automatic properties

2020-03-03 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Here's some empirical ideas about the approach: In clang-format, braces can be 
handled in two quite distinct ways, controlled by BraceBlockKind 
:
 BK_Block and BK_BracedInit.
BK_Block is for braces that open blocks that usually are at one level deeper 
and consist of a sequence of statements and other constructs.
BK_BracedInit is for initializer lists, dictionaries and other similar 
syntactics that are somewhat more appropriate to put together into a line.
The level of granularity of detailed formatting in clang-format is an unwrapped 
line, which is conceptually a sequence of tokens that "make sense together as a 
single line" (without going much into style details and ignoring column 
limits). Separate statements are for example put on separate unwrapped lines. 
The formatting information flowing between unwrapped lines includes just 
higher-level data such as the current nesting depth.
The brace detection is handled primarily in 
UnwrappedLineParser::calculateBraceTypes 
,
 which happens quite early during the parsing of the input sequence.

If an opening brace is marked BK_Block there, later the stuff between it and 
the matching closing brace is parsed as a block: multiple "statements" are put 
on their own unrwapped lines, inside the block.
If the brace is marked BK_BracedInit, the staff following it is parsed more 
like dictionary-struct-array-literal stuff, and importantly is kept on the same 
unwrapped line as the surrounding code (as a braced list may occur as a 
subexpression of a larger expression, and the formatting of the larger 
expression may depend non-trivially by the formatting of the braced list).

For example, consider the following pseudo-C-family fragment:

  % cat test.cc  
  
  int f() {
block_example {
  get;
  set;
};
  
int init_list_example({1, 2, {more}}, other);
  }

If we examine the parsed unwrapped lines (`clang-format -debug`), they look 
like:

  Line(0, FSC=0): int[T=81, OC=0] identifier[T=81, OC=4] l_paren[T=81, OC=5] 
r_paren[T=81, OC=6] l_brace[T=21, OC=8] 
  Line(1, FSC=0): identifier[T=81, OC=2] l_brace[T=21, OC=16] 
  Line(2, FSC=0): identifier[T=81, OC=4] semi[T=81, OC=7] 
  Line(2, FSC=0): identifier[T=81, OC=4] semi[T=81, OC=7] 
  Line(1, FSC=0): r_brace[T=81, OC=2] semi[T=81, OC=3] 
  Line(1, FSC=0): int[T=81, OC=2] identifier[T=81, OC=6] l_paren[T=81, OC=23] 
l_brace[T=81, OC=24] numeric_constant[T=81, OC=25] comma[T=81, OC=26] 
numeric_constant[T=81, OC=28] comma[T=81, OC=29] l_brace[T=81, OC=31] 
identifier[T=81, OC=32] r_brace[T=81, OC=36] r_brace[T=81, OC=37] comma[T=81, 
OC=38] identifier[T=81, OC=40] r_paren[T=81, OC=45] semi[T=81, OC=46] 
  Line(0, FSC=0): r_brace[T=81, OC=0] 
  Line(0, FSC=0): eof[T=81, OC=0] 

The block-like thing is put on separate lines at level 2; the braced-list-like 
thing is kept on the same unwrapped line.

Currently, C# auto property get/set "blocks" are parsed as BK_Block, hence the 
need to later merge lines using a heuristic.
If you could instead mark those as BK_BracedInit in `calculateBraceTypes`, that 
will have the effect of keeping them inline with the surrounding code and might 
produce good formatting of the whole line with a few tweaks.
There's another complication: syntactically in C++, a semicolon is very 
special. For example, C/C++ requires a semicolon after class declarations. 
There's a bunch of places in clang-formatthat use the presence of semicolons to 
determine "end of statement/end of line". So the semicolons in `{ get; set; }` 
might cause a bit of trouble and throw the parser off a bit. Fortunately, 
clang-format already has some code that deals with similar complications for 
javascript, where stuff like `X<{a: string; b: number}>` is correctly handled 
as a braced list, even in the presence of semicolons inside. You can look at 
how this is handled for inspiration (I'm not 100% sure these are the only 
places in code that contribute to the formatting of these constructs):

- in calculateBraceTypes here: 
https://github.com/llvm/llvm-project/blob/9f8a7e82b85078b5afbbc44429355f156e044205/clang/lib/Format/UnwrappedLineParser.cpp#L446
- and later in parseBracedList the semicolons are specially treated here: 
https://github.com/llvm/llvm-project/blob/9f8a7e82b85078b5afbbc44429355f156e044205/clang/lib/Format/UnwrappedLineParser.cpp#L1698

I hope this is helpful, but please take it with a grain of salt as I'm not very 
familiar with those parts of clang-format and am mostly poking around it and 
looking at how similar constructs for other languages are handled.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75194/new/


[PATCH] D75056: [Driver] Default to -fno-common for all targets

2020-03-03 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

Patch for the test-suite: D75557 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75056/new/

https://reviews.llvm.org/D75056



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


[PATCH] D75558: [clang-tidy] Update abseil-duration-unnecessary-conversion check to find more cases.

2020-03-03 Thread Hyrum Wright via Phabricator via cfe-commits
hwright created this revision.
hwright added reviewers: aaron.ballman, ymandel.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

This check now handles cases where there's a scalar multiplication happening 
between the two conversions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75558

Files:
  clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
  
clang-tools-extra/docs/clang-tidy/checks/abseil-duration-unnecessary-conversion.rst
  
clang-tools-extra/test/clang-tidy/checkers/abseil-duration-unnecessary-conversion.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/abseil-duration-unnecessary-conversion.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/abseil-duration-unnecessary-conversion.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/abseil-duration-unnecessary-conversion.cpp
@@ -100,6 +100,44 @@
   d2 = VALUE(d1);
 #undef VALUE
 
+  // Multiplication
+  d2 = absl::Nanoseconds(absl::ToDoubleNanoseconds(d1) * 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = d1 * 2
+  d2 = absl::Microseconds(absl::ToInt64Microseconds(d1) * 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = d1 * 2
+  d2 = absl::Milliseconds(absl::ToDoubleMilliseconds(d1) * 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = d1 * 2
+  d2 = absl::Seconds(absl::ToInt64Seconds(d1) * 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = d1 * 2
+  d2 = absl::Minutes(absl::ToDoubleMinutes(d1) * 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = d1 * 2
+  d2 = absl::Hours(absl::ToInt64Hours(d1) * 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = d1 * 2
+  d2 = absl::Nanoseconds(2 * absl::ToDoubleNanoseconds(d1));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = 2 * d1
+  d2 = absl::Microseconds(2 * absl::ToInt64Microseconds(d1));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = 2 * d1
+  d2 = absl::Milliseconds(2 * absl::ToDoubleMilliseconds(d1));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = 2 * d1
+  d2 = absl::Seconds(2 * absl::ToInt64Seconds(d1));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = 2 * d1
+  d2 = absl::Minutes(2 * absl::ToDoubleMinutes(d1));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = 2 * d1
+  d2 = absl::Hours(2 * absl::ToInt64Hours(d1));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: remove unnecessary absl::Duration conversions [abseil-duration-unnecessary-conversion]
+  // CHECK-FIXES: d2 = 2 * d1
+
   // These should not match
   d2 = absl::Seconds(absl::ToDoubleMilliseconds(d1));
   d2 = absl::Seconds(4);
@@ -108,4 +146,6 @@
   d2 = absl::Seconds(d1 / absl::Seconds(30));
   d2 = absl::Hours(absl::FDivDuration(d1, absl::Minutes(1)));
   d2 = absl::Milliseconds(absl::FDivDuration(d1, absl::Milliseconds(20)));
+  d2 = absl::Seconds(absl::ToInt64Milliseconds(d1) * 2);
+  d2 = absl::Milliseconds(absl::ToDoubleSeconds(d1) * 2);
 }
Index: clang-tools-extra/docs/clang-tidy/checks/abseil-duration-unnecessary-conversion.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/abseil-duration-unnecessary-conversion.rst
+++ clang-tools-extra/docs/clang-tidy/checks/abseil-duration-unnecessary-conversion.rst
@@ -40,6 +40,17 @@
   // Suggestion - Remove division and conversion
   absl::Duration d2 = d1;
 
+Unwrapping scalar operations:
+
+.. code-block:: c++
+
+  // Original - Multiplication by a scalar
+  absl::Duration d1;
+  absl::Duration d2 = absl::Seconds(absl::ToInt64Seconds(d1) * 2);
+
+  // Suggestion - Remove unnecessary conversion
+  absl::Duration d2 = d1 * 2;
+
 Note: Converting to an integer and back to an ``absl::Duration`` might be a
 truncating operation if the value is not aligned to the scale of conversion.
 In the rare case 

[PATCH] D73649: [CodeComplete] Member completion for concept-constrained types.

2020-03-03 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked 3 inline comments as done.
nridge added inline comments.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4856
+private:
+  // Infer members of T, given that the expression E (dependent on T) is true.
+  void believe(const Expr *E, const TemplateTypeParmType *T) {

sammccall wrote:
> nridge wrote:
> > "given that the expression E is valid"?
> E comes from concept constraints, we actually know that E is not only valid 
> but its value is exactly `true`.
> 
> In particular, knowing that E is *valid* doesn't tell us anything at all 
> about T if E is a ConceptSpecializationExpr like `Integral`, as we'd get 
> from a `requires Integral` clause or an `Integral auto foo` parameter. 
> (Note that `Integral` is a valid expression with the value 
> `false`)
You're totally right on this one, my bad! (When I wrote this, I imagined 
`believe()` being called on the expression inside an `ExprRequirement`, but 
that's not the case.)



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4901
+if (!Req->isDependent())
+  continue; // Can't tell us anything about T.
+if (auto *TR = llvm::dyn_cast(Req)) {

sammccall wrote:
> nridge wrote:
> > Are we sure a dependent requirement can't tell us anything about `T`?
> > 
> > For example, a constraint with a dependent return type requirement might 
> > still give us a useful member name and arguments. Even a call expression 
> > with dependent arguments could give us a useful member name.
> > 
> > Or am I misunderstanding what `Requirement::isDependent()` signifies?
> I think you're reading this backwards, a *non-dependent* requirement can't 
> tell us anything about T, because it doesn't depend on T!
> 
> This isn't terribly important except that it takes care of a few cases at 
> once (e.g. all requirements below must have an expr rather than an error, 
> because constraints with an error aren't dependent)
Indeed, I was reading this backwards. Makes sense now!



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4972
+
+// In T::foo::bar, `foo` must be a type.
+bool VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {

sammccall wrote:
> nridge wrote:
> > It would be nice if the test exercised this case.
> Oops, this was actually broken because VisitNestedNameSpecifier doesn't seem 
> to be a thing :-(
> Fixed to use TraverseNestedNameSpecifierLoc and added a test.
> Oops, this was actually broken because VisitNestedNameSpecifier doesn't seem 
> to be a thing :-(

(I suspected this, but the heavy macro usage in `RecursiveASTVisitor.h` made me 
second-guess myself and think I was just overlooking a place that defines 
`VisitNestedNameSpecifier`. I figured adding a test wouldn't hurt even if I'm 
mistaken and the code works. :-))



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:5006
+  if (/*Inserted*/ R.second ||
+  std::make_tuple(M.Operator, M.ArgTypes.hasValue(),
+  M.ResultType != nullptr) >

So `Colons` is more info than `Arrow` which is more info than `Dot`? Is there 
some intuition behind that?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73649/new/

https://reviews.llvm.org/D73649



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


[PATCH] D75556: [AST Matchers] Restrict `optionally` matcher to a single argument.

2020-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: sbenza, aaron.ballman.
Herald added a project: clang.

Currently, `optionally` can take multiple arguments, which commits it to a
particular strategy for those arguments (in this case, "for each"). We limit the
matcher to a single argument, which avoids any potential confusion and
simplifies the implementation. The user can retrieve multiple-argument
optionality, by explicitly using the desired operator (like `forEach`, `anyOf`,
`allOf`, etc.) with all children wrapped in `optionally`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75556

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2007,9 +2007,8 @@
 TEST(Optionally, SubmatchersDoNotMatch) {
   EXPECT_TRUE(matchAndVerifyResultFalse(
   "class A { int a; int b; };",
-  recordDecl(optionally(has(fieldDecl(hasName("c")).bind("v")),
-has(fieldDecl(hasName("d")).bind("v",
-  std::make_unique>("v")));
+  recordDecl(optionally(has(fieldDecl(hasName("c")).bind("c",
+  std::make_unique>("c")));
 }
 
 // Regression test.
@@ -2028,14 +2027,8 @@
 TEST(Optionally, SubmatchersMatch) {
   EXPECT_TRUE(matchAndVerifyResultTrue(
   "class A { int a; int c; };",
-  recordDecl(optionally(has(fieldDecl(hasName("a")).bind("v")),
-has(fieldDecl(hasName("b")).bind("v",
-  std::make_unique>("v", 1)));
-  EXPECT_TRUE(matchAndVerifyResultTrue(
-  "class A { int c; int b; };",
-  recordDecl(optionally(has(fieldDecl(hasName("c")).bind("v")),
-has(fieldDecl(hasName("b")).bind("v",
-  std::make_unique>("v", 2)));
+  recordDecl(optionally(has(fieldDecl(hasName("a")).bind("v",
+  std::make_unique>("v")));
 }
 
 TEST(IsTemplateInstantiation, MatchesImplicitClassTemplateInstantiation) {
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -346,18 +346,11 @@
 ASTMatchFinder *Finder,
 BoundNodesTreeBuilder *Builder,
 ArrayRef InnerMatchers) {
-  BoundNodesTreeBuilder Result;
-  bool Matched = false;
-  for (const DynTypedMatcher  : InnerMatchers) {
-BoundNodesTreeBuilder BuilderInner(*Builder);
-if (InnerMatcher.matches(DynNode, Finder, )) {
-  Matched = true;
-  Result.addMatch(BuilderInner);
-}
-  }
-  // If there were no matches, we can't assign to `*Builder`; we'd 
(incorrectly)
-  // clear it because `Result` is empty.
-  if (Matched)
+  if (InnerMatchers.size() != 1)
+return false;
+
+  BoundNodesTreeBuilder Result(*Builder);
+  if (InnerMatchers[0].matches(DynNode, Finder, ))
 *Builder = std::move(Result);
   return true;
 }
@@ -859,9 +852,8 @@
 const internal::VariadicOperatorMatcherFunc<
 2, std::numeric_limits::max()>
 allOf = {internal::DynTypedMatcher::VO_AllOf};
-const internal::VariadicOperatorMatcherFunc<
-1, std::numeric_limits::max()>
-optionally = {internal::DynTypedMatcher::VO_Optionally};
+const internal::VariadicOperatorMatcherFunc<1, 1> optionally = {
+internal::DynTypedMatcher::VO_Optionally};
 const internal::VariadicFunction, StringRef,
  internal::hasAnyNameFunc>
 hasAnyName = {};
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2612,9 +2612,7 @@
 /// member named "bar" in that class.
 ///
 /// Usable as: Any Matcher
-extern const internal::VariadicOperatorMatcherFunc<
-1, std::numeric_limits::max()>
-optionally;
+extern const internal::VariadicOperatorMatcherFunc<1, 1> optionally;
 
 /// Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
 ///


Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2007,9 +2007,8 @@
 TEST(Optionally, SubmatchersDoNotMatch) {
   EXPECT_TRUE(matchAndVerifyResultFalse(
   "class A { int a; int b; };",
-  recordDecl(optionally(has(fieldDecl(hasName("c")).bind("v")),
-has(fieldDecl(hasName("d")).bind("v",
-  std::make_unique>("v")));
+  

[PATCH] D75285: Mark restrict pointer or reference to const as invariant

2020-03-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D75285#1903611 , @yaxunl wrote:

> In D75285#1903444 , @rjmccall wrote:
>
> > That is not true for two reasons: first, `restrict` guarantees that the 
> > variable is not accessed through any non-derived l-value within its scope, 
> > and that would certainly include from other threads; and second, it is 
> > undefined behavior for two threads to access the same object without 
> > synchronizing anyway (unless they're both just reading from it).
>
>
> How about the cases where users cannot use restrict but they still want to 
> mark a pointer as invariant?


I'm not sure what cases those would be; I'm pretty sure that if memory is 
invariant then you can always use `restrict`.

> Or even though restrict is used but it is too complicated for alias analysis 
> to deduce invariance?

I asked before if there was a specific optimization problem you were trying to 
solve, and I still have that question.  It kindof feels like somebody's already 
decided that they don't want to use alias analysis for something, so now you're 
looking for ways to do it without alias analysis, even though alias analysis 
might be a satisfactory way of solving the problem.  `restrict` gives us a 
*lot* of informatiion; I'm sure there are places where we don't preserve it 
well enough to do some optimization, but that can be improved without needing a 
whole new language feature.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75285/new/

https://reviews.llvm.org/D75285



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


[clang] fca49fe - [clang-offload-wrapper] Lower priority of __tgt_register_lib in favor of __tgt_register_requires

2020-03-03 Thread George Rokos via cfe-commits

Author: George Rokos
Date: 2020-03-03T12:31:40-08:00
New Revision: fca49fe8e34f13632c42e68aad4b14e3e00bdcc8

URL: 
https://github.com/llvm/llvm-project/commit/fca49fe8e34f13632c42e68aad4b14e3e00bdcc8
DIFF: 
https://github.com/llvm/llvm-project/commit/fca49fe8e34f13632c42e68aad4b14e3e00bdcc8.diff

LOG: [clang-offload-wrapper] Lower priority of __tgt_register_lib in favor of 
__tgt_register_requires

Lower priority of __tgt_register_lib in order to make sure that 
__tgt_register_requires is called before loading a libomptarget plugin.
We want to know beforehand which requirements the user has asked for so that 
upon loading the plugin libomptarget can report how many devices there are that 
can satisfy these requirements.

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

Added: 


Modified: 
clang/test/Driver/clang-offload-wrapper.c
clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp

Removed: 




diff  --git a/clang/test/Driver/clang-offload-wrapper.c 
b/clang/test/Driver/clang-offload-wrapper.c
index c8c17bd8a514..9a36559e34dd 100644
--- a/clang/test/Driver/clang-offload-wrapper.c
+++ b/clang/test/Driver/clang-offload-wrapper.c
@@ -39,8 +39,8 @@
 
 // CHECK-IR: [[DESC:@.+]] = internal constant [[DESCTY]] { i32 1, [[IMAGETY]]* 
getelementptr inbounds ([1 x [[IMAGETY]]], [1 x [[IMAGETY]]]* [[IMAGES]], i64 
0, i64 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }
 
-// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* 
}] [{ i32, void ()*, i8* } { i32 0, void ()* [[REGFN:@.+]], i8* null }]
-// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* 
}] [{ i32, void ()*, i8* } { i32 0, void ()* [[UNREGFN:@.+]], i8* null }]
+// CHECK-IR: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* 
}] [{ i32, void ()*, i8* } { i32 1, void ()* [[REGFN:@.+]], i8* null }]
+// CHECK-IR: @llvm.global_dtors = appending global [1 x { i32, void ()*, i8* 
}] [{ i32, void ()*, i8* } { i32 1, void ()* [[UNREGFN:@.+]], i8* null }]
 
 // CHECK-IR: define internal void [[REGFN]]()
 // CHECK-IR:   call void @__tgt_register_lib([[DESCTY]]* [[DESC]])

diff  --git a/clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp 
b/clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
index c3863422adf6..78d96539f47e 100644
--- a/clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
+++ b/clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp
@@ -262,7 +262,12 @@ class BinaryWrapper {
 Builder.CreateRetVoid();
 
 // Add this function to constructors.
-appendToGlobalCtors(M, Func, 0);
+// Set priority to 1 so that __tgt_register_lib is executed AFTER
+// __tgt_register_requires (we want to know what requirements have been
+// asked for before we load a libomptarget plugin so that by the time the
+// plugin is loaded it can report how many devices there are which can
+// satisfy these requirements).
+appendToGlobalCtors(M, Func, /*Priority*/ 1);
   }
 
   void createUnregisterFunction(GlobalVariable *BinDesc) {
@@ -283,7 +288,8 @@ class BinaryWrapper {
 Builder.CreateRetVoid();
 
 // Add this function to global destructors.
-appendToGlobalDtors(M, Func, 0);
+// Match priority of __tgt_register_lib
+appendToGlobalDtors(M, Func, /*Priority*/ 1);
   }
 
 public:



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


[PATCH] D75223: [clang-offload-wrapper] Lower priority of __tgt_register_lib in favor of __tgt_register_requires

2020-03-03 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75223/new/

https://reviews.llvm.org/D75223



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


  1   2   3   >