r358898 - [sema][objc] Minor refactor to OverrideSearch. NFCI.

2019-04-22 Thread Matt Davis via cfe-commits
Author: mattd
Date: Mon Apr 22 09:04:44 2019
New Revision: 358898

URL: http://llvm.org/viewvc/llvm-project?rev=358898&view=rev
Log:
[sema][objc] Minor refactor to OverrideSearch. NFCI.

Summary:
* Removed a member that was only used during construction.
* Use range-based for iteration when accessing the result of the search.
* Require an `ObjCMethodDecl` reference upon construction of an
* Constify.

Reviewers: rjmccall

Reviewed By: rjmccall

Subscribers: llvm-commits

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

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

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=358898&r1=358897&r2=358898&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Apr 22 09:04:44 2019
@@ -4166,13 +4166,12 @@ namespace {
 /// overrides.
 class OverrideSearch {
 public:
-  Sema &S;
-  ObjCMethodDecl *Method;
+  const ObjCMethodDecl *Method;
   llvm::SmallSetVector Overridden;
   bool Recursive;
 
 public:
-  OverrideSearch(Sema &S, ObjCMethodDecl *method) : S(S), Method(method) {
+  OverrideSearch(Sema &S, const ObjCMethodDecl *method) : Method(method) {
 Selector selector = method->getSelector();
 
 // Bypass this search if we've never seen an instance/class method
@@ -4186,19 +4185,20 @@ public:
   if (it == S.MethodPool.end())
 return;
 }
-ObjCMethodList &list =
+const ObjCMethodList &list =
   method->isInstanceMethod() ? it->second.first : it->second.second;
 if (!list.getMethod()) return;
 
-ObjCContainerDecl *container
+const ObjCContainerDecl *container
   = cast(method->getDeclContext());
 
 // Prevent the search from reaching this container again.  This is
 // important with categories, which override methods from the
 // interface and each other.
-if (ObjCCategoryDecl *Category = dyn_cast(container)) {
+if (const ObjCCategoryDecl *Category =
+dyn_cast(container)) {
   searchFromContainer(container);
-  if (ObjCInterfaceDecl *Interface = Category->getClassInterface())
+  if (const ObjCInterfaceDecl *Interface = Category->getClassInterface())
 searchFromContainer(Interface);
 } else {
   searchFromContainer(container);
@@ -4210,7 +4210,7 @@ public:
   iterator end() const { return Overridden.end(); }
 
 private:
-  void searchFromContainer(ObjCContainerDecl *container) {
+  void searchFromContainer(const ObjCContainerDecl *container) {
 if (container->isInvalidDecl()) return;
 
 switch (container->getDeclKind()) {
@@ -4226,7 +4226,7 @@ private:
 }
   }
 
-  void searchFrom(ObjCProtocolDecl *protocol) {
+  void searchFrom(const ObjCProtocolDecl *protocol) {
 if (!protocol->hasDefinition())
   return;
 
@@ -4235,14 +4235,14 @@ private:
 search(protocol->getReferencedProtocols());
   }
 
-  void searchFrom(ObjCCategoryDecl *category) {
+  void searchFrom(const ObjCCategoryDecl *category) {
 // A method in a category declaration overrides declarations from
 // the main class and from protocols the category references.
 // The main class is handled in the constructor.
 search(category->getReferencedProtocols());
   }
 
-  void searchFrom(ObjCCategoryImplDecl *impl) {
+  void searchFrom(const ObjCCategoryImplDecl *impl) {
 // A method in a category definition that has a category
 // declaration overrides declarations from the category
 // declaration.
@@ -4252,12 +4252,12 @@ private:
 search(Interface);
 
 // Otherwise it overrides declarations from the class.
-} else if (ObjCInterfaceDecl *Interface = impl->getClassInterface()) {
+} else if (const auto *Interface = impl->getClassInterface()) {
   search(Interface);
 }
   }
 
-  void searchFrom(ObjCInterfaceDecl *iface) {
+  void searchFrom(const ObjCInterfaceDecl *iface) {
 // A method in a class declaration overrides declarations from
 if (!iface->hasDefinition())
   return;
@@ -4274,20 +4274,19 @@ private:
 search(iface->getReferencedProtocols());
   }
 
-  void searchFrom(ObjCImplementationDecl *impl) {
+  void searchFrom(const ObjCImplementationDecl *impl) {
 // A method in a class implementation overrides declarations from
 // the class interface.
-if (ObjCInterfaceDecl *Interface = impl->getClassInterface())
+if (const auto *Interface = impl->getClassInterface())
   search(Interface);
   }
 
   void search(const ObjCProtocolList &protocols) {
-for (ObjCProtocolList::iterator i = protocols.begin(), e = protocols.end();
- i != e; ++i)
-  search(*i);
+for (const auto *Proto : protocols)
+  search(Proto);
   }
 
-  void search(ObjCContainerDecl *container) {
+  void search(const ObjCContainerDecl *container) {
 // Check for a method in this container which 

r346146 - [AST] Get aliased type info from an aliased TemplateSpecialization.

2018-11-05 Thread Matt Davis via cfe-commits
Author: mattd
Date: Mon Nov  5 09:25:26 2018
New Revision: 346146

URL: http://llvm.org/viewvc/llvm-project?rev=346146&view=rev
Log:
[AST] Get aliased type info from an aliased TemplateSpecialization.

Summary:
Previously the TemplateSpecialization instance for 'template_alias', in the 
example below, returned the type info of the  canonical type (int).  This 
ignored the type alias if the template type happen to be aliased. 

Before this patch, the assert would trigger with an  alignment of 4:
```
typedef int __attribute__(( aligned( 16 ) )) aligned_int;
template < typename >
using template_alias = aligned_int;
static_assert( alignof( template_alias) == 16, "" );
```

This patch checks if the TemplateSpecialization type has an alias, and if so 
will return the type information for the aliased type, else the canonical 
type's info is returned (original behavior).  I believe that this is the 
desired behavior.  

Reviewers: aaron.ballman, rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/test/SemaCXX/alignof.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=346146&r1=346145&r2=346146&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Nov  5 09:25:26 2018
@@ -4901,7 +4901,9 @@ public:
 return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
   }
 
-  QualType desugar() const { return getCanonicalTypeInternal(); }
+  QualType desugar() const {
+return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();
+  }
 
   void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
 Profile(ID, Template, template_arguments(), Ctx);

Modified: cfe/trunk/test/SemaCXX/alignof.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/alignof.cpp?rev=346146&r1=346145&r2=346146&view=diff
==
--- cfe/trunk/test/SemaCXX/alignof.cpp (original)
+++ cfe/trunk/test/SemaCXX/alignof.cpp Mon Nov  5 09:25:26 2018
@@ -97,3 +97,8 @@ struct S {
   typedef __attribute__((aligned(N))) int Field[sizeof(N)]; // expected-error 
{{requested alignment is dependent but declaration is not dependent}}
 };
 }
+
+typedef int __attribute__((aligned(16))) aligned_int;
+template 
+using template_alias = aligned_int;
+static_assert(alignof(template_alias) == 16, "Expected alignment of 16" 
);


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


r342068 - [Diagnostic] Fix a warning typo. NFC.

2018-09-12 Thread Matt Davis via cfe-commits
Author: mattd
Date: Wed Sep 12 11:27:21 2018
New Revision: 342068

URL: http://llvm.org/viewvc/llvm-project?rev=342068&view=rev
Log:
[Diagnostic] Fix a warning typo. NFC.

s/aligment/alignment/


Modified:
cfe/trunk/docs/DiagnosticsReference.rst
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/Sema/Inputs/pragma-pack1.h
cfe/trunk/test/Sema/suspicious-pragma-pack.c

Modified: cfe/trunk/docs/DiagnosticsReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/DiagnosticsReference.rst?rev=342068&r1=342067&r2=342068&view=diff
==
--- cfe/trunk/docs/DiagnosticsReference.rst (original)
+++ cfe/trunk/docs/DiagnosticsReference.rst Wed Sep 12 11:27:21 2018
@@ -8637,9 +8637,9 @@ Also controls `-Wpragma-pack-suspicious-
 
 **Diagnostic text:**
 
-+---+
-|:warning:`warning:` |nbsp| :diagtext:`the current #pragma pack aligment value 
is modified in the included file`|
-+---+
+++
+|:warning:`warning:` |nbsp| :diagtext:`the current #pragma pack alignment 
value is modified in the included file`|
+++
 
 
+-+
 |:warning:`warning:` |nbsp| :diagtext:`unterminated '#pragma pack (push, ...)' 
at end of file`|

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=342068&r1=342067&r2=342068&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 12 11:27:21 
2018
@@ -774,7 +774,7 @@ def warn_pragma_pack_non_default_at_incl
   "members in the included file">, InGroup,
   DefaultIgnore;
 def warn_pragma_pack_modified_after_include : Warning<
-  "the current #pragma pack aligment value is modified in the included "
+  "the current #pragma pack alignment value is modified in the included "
   "file">, InGroup;
 def warn_pragma_pack_no_pop_eof : Warning<"unterminated "
   "'#pragma pack (push, ...)' at end of file">, InGroup;

Modified: cfe/trunk/test/Sema/Inputs/pragma-pack1.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/Inputs/pragma-pack1.h?rev=342068&r1=342067&r2=342068&view=diff
==
--- cfe/trunk/test/Sema/Inputs/pragma-pack1.h (original)
+++ cfe/trunk/test/Sema/Inputs/pragma-pack1.h Wed Sep 12 11:27:21 2018
@@ -16,7 +16,7 @@ struct ReceivesPragma { };
 #include "pragma-pack2.h"
 
 #ifdef SET_SECOND_HEADER
-// expected-warning@-3 {{the current #pragma pack aligment value is modified 
in the included file}}
+// expected-warning@-3 {{the current #pragma pack alignment value is modified 
in the included file}}
 #endif
 
 #ifdef PUSH_POP_FIRST_HEADER

Modified: cfe/trunk/test/Sema/suspicious-pragma-pack.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/suspicious-pragma-pack.c?rev=342068&r1=342067&r2=342068&view=diff
==
--- cfe/trunk/test/Sema/suspicious-pragma-pack.c (original)
+++ cfe/trunk/test/Sema/suspicious-pragma-pack.c Wed Sep 12 11:27:21 2018
@@ -38,7 +38,7 @@
 #include "pragma-pack1.h"
 
 #ifdef WARN_MODIFIED_HEADER
-// expected-warning@-3 {{the current #pragma pack aligment value is modified 
in the included file}}
+// expected-warning@-3 {{the current #pragma pack alignment value is modified 
in the included file}}
 #endif
 
 #ifdef PUSH_SET_HERE


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


r339201 - [analyzer] Avoid querying this-pointers for static-methods.

2018-08-07 Thread Matt Davis via cfe-commits
Author: mattd
Date: Tue Aug  7 16:13:28 2018
New Revision: 339201

URL: http://llvm.org/viewvc/llvm-project?rev=339201&view=rev
Log:
[analyzer] Avoid querying this-pointers for static-methods.

Summary:
The loop-widening code processes c++ methods looking for `this` pointers.  In
the case of static methods (which do not have `this` pointers), an assertion
was triggering.   This patch avoids trying to process `this` pointers for
static methods, and thus avoids triggering the assertion .


Reviewers: dcoughlin, george.karpenkov, NoQ

Reviewed By: NoQ

Subscribers: NoQ, xazax.hun, szepet, a.sidorin, mikhail.ramalho, cfe-commits

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

Added:
cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp?rev=339201&r1=339200&r2=339201&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/LoopWidening.cpp Tue Aug  7 16:13:28 2018
@@ -81,8 +81,10 @@ ProgramStateRef getWidenedLoopState(Prog
 
   // 'this' pointer is not an lvalue, we should not invalidate it. If the loop
   // is located in a method, constructor or destructor, the value of 'this'
-  // pointer shoule remain unchanged.
-  if (const CXXMethodDecl *CXXMD = dyn_cast(STC->getDecl())) {
+  // pointer should remain unchanged.  Ignore static methods, since they do not
+  // have 'this' pointers.
+  const CXXMethodDecl *CXXMD = dyn_cast(STC->getDecl());
+  if (CXXMD && !CXXMD->isStatic()) {
 const CXXThisRegion *ThisR = MRMgr.getCXXThisRegion(
 CXXMD->getThisType(STC->getAnalysisDeclContext()->getASTContext()),
 STC);

Added: cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp?rev=339201&view=auto
==
--- cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp (added)
+++ cfe/trunk/test/Analysis/loop-widening-ignore-static-methods.cpp Tue Aug  7 
16:13:28 2018
@@ -0,0 +1,12 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config 
widen-loops=true -analyzer-max-loop 2 %s
+// REQUIRES: asserts
+// expected-no-diagnostics
+//
+// This test checks that the loop-widening code ignores static methods.  If 
that is not the
+// case, then an assertion will trigger.
+
+class Test {
+  static void foo() {
+for (;;) {}
+  }
+};


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


r328712 - [Diag] Avoid emitting a redefinition note if no location is available.

2018-03-28 Thread Matt Davis via cfe-commits
Author: mattd
Date: Wed Mar 28 09:05:05 2018
New Revision: 328712

URL: http://llvm.org/viewvc/llvm-project?rev=328712&view=rev
Log:
[Diag] Avoid emitting a redefinition note if no location is available.

Summary:
The "previous definition is here" note is not helpful if there is no location 
information. The note will reference nothing in such a case. This patch first 
checks to see if there is location data, and if so the note diagnostic is 
emitted.

This fixes PR15409.  The issue in the first comment seems to already be 
resolved. This patch addresses the second example.

Reviewers: bruno, rsmith

Reviewed By: bruno

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/redefine_extname.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=328712&r1=328711&r2=328712&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 28 09:05:05 2018
@@ -4057,7 +4057,8 @@ void Sema::notePreviousDefinition(const
   }
 
   // Redefinition coming from different files or couldn't do better above.
-  Diag(Old->getLocation(), diag::note_previous_definition);
+  if (Old->getLocation().isValid())
+Diag(Old->getLocation(), diag::note_previous_definition);
 }
 
 /// We've just determined that \p Old and \p New both appear to be definitions

Modified: cfe/trunk/test/Sema/redefine_extname.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/redefine_extname.c?rev=328712&r1=328711&r2=328712&view=diff
==
--- cfe/trunk/test/Sema/redefine_extname.c (original)
+++ cfe/trunk/test/Sema/redefine_extname.c Wed Mar 28 09:05:05 2018
@@ -4,3 +4,4 @@
 #pragma redefine_extname foo_static bar_static
 static int foo_static() { return 1; } // expected-warning {{#pragma 
redefine_extname is applicable to external C declarations only; not applied to 
function 'foo_static'}}
 
+unsigned __int128_t; // expected-error {{redefinition of '__int128_t' as 
different kind of symbol}}


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


r325271 - [Test] Remove mangled name from test.

2018-02-15 Thread Matt Davis via cfe-commits
Author: mattd
Date: Thu Feb 15 09:55:52 2018
New Revision: 325271

URL: http://llvm.org/viewvc/llvm-project?rev=325271&view=rev
Log:
[Test] Remove mangled name from test.

This line is not needed in the test, and breaks Windows testing.
Fixes the test added in r325175.


Modified:
cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp

Modified: cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp?rev=325271&r1=325270&r2=325271&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp Thu Feb 15 
09:55:52 2018
@@ -15,7 +15,6 @@ void test() {
   }
 }
 
-// CHECK: define void @_Z4testv()
 // CHECK: call void @llvm.dbg.declare(metadata %struct.vec** {{.*}}, metadata 
![[RANGE1:[0-9]+]]
 // CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata 
![[BEGIN1:[0-9]+]]
 // CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata 
![[END1:[0-9]+]]


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


r325175 - [Debug] Annotate compiler generated range-for loop variables.

2018-02-14 Thread Matt Davis via cfe-commits
Author: mattd
Date: Wed Feb 14 13:22:11 2018
New Revision: 325175

URL: http://llvm.org/viewvc/llvm-project?rev=325175&view=rev
Log:
[Debug] Annotate compiler generated range-for loop variables.

Summary:
This change aims to simplify debugging by annotating the range-for loop 
artificial variables (range, begin, end) with the scope depth. 


Reviewers: rsmith, dblaikie

Reviewed By: dblaikie

Subscribers: dblaikie, cfe-commits

Tags: #debug-info

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

Added:
cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp
Modified:
cfe/trunk/include/clang/Sema/Scope.h
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp
cfe/trunk/test/CodeGenCXX/vla.cpp

Modified: cfe/trunk/include/clang/Sema/Scope.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=325175&r1=325174&r2=325175&view=diff
==
--- cfe/trunk/include/clang/Sema/Scope.h (original)
+++ cfe/trunk/include/clang/Sema/Scope.h Wed Feb 14 13:22:11 2018
@@ -259,6 +259,9 @@ public:
   Scope *getTemplateParamParent() { return TemplateParamParent; }
   const Scope *getTemplateParamParent() const { return TemplateParamParent; }
 
+  /// Returns the depth of this scope. The translation-unit has scope depth 0.
+  unsigned getDepth() const { return Depth; }
+
   /// Returns the number of function prototype scopes in this scope
   /// chain.
   unsigned getFunctionPrototypeDepth() const {

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=325175&r1=325174&r2=325175&view=diff
==
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Feb 14 13:22:11 2018
@@ -2025,7 +2025,7 @@ void NoteForRangeBeginEndFunction(Sema &
 
 /// Build a variable declaration for a for-range statement.
 VarDecl *BuildForRangeVarDecl(Sema &SemaRef, SourceLocation Loc,
-  QualType Type, const char *Name) {
+  QualType Type, StringRef Name) {
   DeclContext *DC = SemaRef.CurContext;
   IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name);
   TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc);
@@ -2094,10 +2094,12 @@ StmtResult Sema::ActOnCXXForRangeStmt(Sc
   }
 
   // Build  auto && __range = range-init
+  // Divide by 2, since the variables are in the inner scope (loop body).
+  const auto DepthStr = std::to_string(S->getDepth() / 2);
   SourceLocation RangeLoc = Range->getLocStart();
   VarDecl *RangeVar = BuildForRangeVarDecl(*this, RangeLoc,
Context.getAutoRRefDeductType(),
-   "__range");
+   std::string("__range") + DepthStr);
   if (FinishForRangeVarDecl(*this, RangeVar, Range, RangeLoc,
 diag::err_for_range_deduction_failure)) {
 LoopVar->setInvalidDecl();
@@ -2340,10 +2342,12 @@ Sema::BuildCXXForRangeStmt(SourceLocatio
   return StmtError();
 
 // Build auto __begin = begin-expr, __end = end-expr.
+// Divide by 2, since the variables are in the inner scope (loop body).
+const auto DepthStr = std::to_string(S->getDepth() / 2);
 VarDecl *BeginVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
- "__begin");
+ std::string("__begin") + 
DepthStr);
 VarDecl *EndVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
-   "__end");
+   std::string("__end") + DepthStr);
 
 // Build begin-expr and end-expr and attach to __begin and __end variables.
 ExprResult BeginExpr, EndExpr;

Added: cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp?rev=325175&view=auto
==
--- cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp Wed Feb 14 
13:22:11 2018
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+
+struct vec {
+  using itr = int*;
+  itr begin() { return nullptr; }
+  itr end() { return nullptr; }
+};
+
+void test() {
+  vec as, bs, cs;
+
+  for (auto a : as)
+for (auto b : bs)
+  for (auto c : cs) {
+  }
+}
+
+// CHECK: define void @_Z4testv()
+// CHECK: call void @llvm.dbg.declare(metadata %struct.vec** {{.*}}, metadata 
![[RANGE1:[0-9]+]]
+// CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata 
![[BEGIN1:[0-9]+]]
+// CHECK: call void @llvm.dbg

r324776 - [CodeGen] Use the zero initializer instead of storing an all zero representation.

2018-02-09 Thread Matt Davis via cfe-commits
Author: mattd
Date: Fri Feb  9 14:10:09 2018
New Revision: 324776

URL: http://llvm.org/viewvc/llvm-project?rev=324776&view=rev
Log:
[CodeGen] Use the zero initializer instead of storing an all zero 
representation.

Summary:
This change avoids the overhead of storing, and later crawling,
an initializer list of all zeros for arrays. When LLVM
visits this (llvm/IR/Constants.cpp) ConstantArray::getImpl()
it will scan the list looking for an array of all zero.

We can avoid the store, and short-cut the scan, by detecting
all zeros when clang builds-up the initialization representation.

This was brought to my attention when investigating PR36030


Reviewers: majnemer, rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CodeGen/array-init.c
Modified:
cfe/trunk/lib/CodeGen/CGExprConstant.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=324776&r1=324775&r2=324776&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Feb  9 14:10:09 2018
@@ -859,9 +859,10 @@ public:
 
 // Copy initializer elements.
 SmallVector Elts;
-Elts.reserve(NumInitableElts + NumElements);
+Elts.reserve(std::max(NumInitableElts, NumElements));
 
 bool RewriteType = false;
+bool AllNullValues = true;
 for (unsigned i = 0; i < NumInitableElts; ++i) {
   Expr *Init = ILE->getInit(i);
   llvm::Constant *C = Emitter.tryEmitPrivateForMemory(Init, EltType);
@@ -869,15 +870,22 @@ public:
 return nullptr;
   RewriteType |= (C->getType() != ElemTy);
   Elts.push_back(C);
+  if (AllNullValues && !C->isNullValue())
+AllNullValues = false;
 }
 
+// If all initializer elements are "zero," then avoid storing NumElements
+// instances of the zero representation.
+if (AllNullValues)
+  return llvm::ConstantAggregateZero::get(AType);
+
 RewriteType |= (fillC->getType() != ElemTy);
 Elts.resize(NumElements, fillC);
 
 if (RewriteType) {
   // FIXME: Try to avoid packing the array
   std::vector Types;
-  Types.reserve(NumInitableElts + NumElements);
+  Types.reserve(Elts.size());
   for (unsigned i = 0, e = Elts.size(); i < e; ++i)
 Types.push_back(Elts[i]->getType());
   llvm::StructType *SType = llvm::StructType::get(AType->getContext(),

Added: cfe/trunk/test/CodeGen/array-init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/array-init.c?rev=324776&view=auto
==
--- cfe/trunk/test/CodeGen/array-init.c (added)
+++ cfe/trunk/test/CodeGen/array-init.c Fri Feb  9 14:10:09 2018
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -O0 -triple x86_64-unknown-linux-gnu -emit-llvm -o - | 
FileCheck %s
+
+// CHECK: @{{.*}}.a1 = internal constant [5 x i32] [i32 0, i32 1, i32 2, i32 
0, i32 0]
+// CHECK: @{{.*}}.a2 = internal constant [5 x i32] zeroinitializer
+// CHECK: @{{.*}}.a3 = internal constant [5 x i32] zeroinitializer
+
+void testConstArrayInits(void)
+{
+  const int a1[5] = {0,1,2};
+  const int a2[5] = {0,0,0};
+  const int a3[5] = {0};
+}


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


r323577 - Always allow "#pragma region".

2018-01-26 Thread Matt Davis via cfe-commits
Author: mattd
Date: Fri Jan 26 16:25:29 2018
New Revision: 323577

URL: http://llvm.org/viewvc/llvm-project?rev=323577&view=rev
Log:
Always allow "#pragma region".

Summary:
Both MS and PS4 targets are capable of recognizing the
existence of:  #pragma region, #pragma endregion.

Since this pragma is only a hint for certain editors, and has no logic,
it seems helpful to permit this pragma in all cases, not just MS compatibility 
mode.



Reviewers: rnk, rsmith, majnemer

Reviewed By: majnemer

Subscribers: Quuxplusone, probinson, majnemer, cfe-commits

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

Added:
cfe/trunk/test/Frontend/region-pragmas.c
Modified:
cfe/trunk/lib/Lex/Pragma.cpp

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=323577&r1=323576&r2=323577&view=diff
==
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Fri Jan 26 16:25:29 2018
@@ -1776,13 +1776,15 @@ void Preprocessor::RegisterBuiltinPragma
   ModuleHandler->AddPragma(new PragmaModuleEndHandler());
   ModuleHandler->AddPragma(new PragmaModuleBuildHandler());
   ModuleHandler->AddPragma(new PragmaModuleLoadHandler());
+
+  // Add region pragmas.
+  AddPragmaHandler(new PragmaRegionHandler("region"));
+  AddPragmaHandler(new PragmaRegionHandler("endregion"));
 
   // MS extensions.
   if (LangOpts.MicrosoftExt) {
 AddPragmaHandler(new PragmaWarningHandler());
 AddPragmaHandler(new PragmaIncludeAliasHandler());
-AddPragmaHandler(new PragmaRegionHandler("region"));
-AddPragmaHandler(new PragmaRegionHandler("endregion"));
   }
 
   // Pragmas added by plugins

Added: cfe/trunk/test/Frontend/region-pragmas.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/region-pragmas.c?rev=323577&view=auto
==
--- cfe/trunk/test/Frontend/region-pragmas.c (added)
+++ cfe/trunk/test/Frontend/region-pragmas.c Fri Jan 26 16:25:29 2018
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -Wall -verify %s
+// expected-no-diagnostics
+
+#pragma region foo
+#pragma endregion foo


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