[PATCH] D45093: [AST] Fix -ast-print for _Bool when have diagnostics

2018-05-08 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 145711.
jdenny edited the summary of this revision.
jdenny added a comment.

Made the suggested changes.


https://reviews.llvm.org/D45093

Files:
  include/clang/Sema/Sema.h
  lib/Frontend/ASTConsumers.cpp
  lib/Sema/Sema.cpp
  test/Misc/ast-print-bool.c

Index: test/Misc/ast-print-bool.c
===
--- /dev/null
+++ test/Misc/ast-print-bool.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_INT \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-INT,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_INT -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-INT,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc++ \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-BOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc++ -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-BOOL
+
+#if DEF_BOOL_CBOOL
+# define bool _Bool
+#elif DEF_BOOL_INT
+# define bool int
+#endif
+
+// BOOL-AS-CBOOL: _Bool i;
+// BOOL-AS-INT:   int i;
+// BOOL-AS-BOOL:  bool i;
+bool i;
+
+#ifndef __cplusplus
+// CBOOL: _Bool j;
+_Bool j;
+#endif
+
+// Induce a diagnostic (and verify we actually managed to do so), which used to
+// permanently alter the -ast-print printing policy for _Bool.  How bool is
+// defined by the preprocessor is examined only once per compilation, when the
+// diagnostic is emitted, and it used to affect the entirety of -ast-print, so
+// test only one definition of bool per compilation.
+#if DIAG
+void fn() { 1; } // expected-warning {{expression result unused}}
+#else
+// expected-no-diagnostics
+#endif
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -52,8 +52,8 @@
 PrintingPolicy Sema::getPrintingPolicy(const ASTContext &Context,
const Preprocessor &PP) {
   PrintingPolicy Policy = Context.getPrintingPolicy();
-  // Our printing policy is copied over the ASTContext printing policy whenever
-  // a diagnostic is emitted, so recompute it.
+  // In diagnostics, we print _Bool as bool if the latter is defined as the
+  // former.
   Policy.Bool = Context.getLangOpts().Bool;
   if (!Policy.Bool) {
 if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
@@ -1284,7 +1284,8 @@
 }
   }
 
-  // Set up the context's printing policy based on our current state.
+  // Copy the diagnostic printing policy over the ASTContext printing policy.
+  // TODO: Stop doing that.  See: https://reviews.llvm.org/D45093#1090292
   Context.setPrintingPolicy(getPrintingPolicy());
 
   // Emit the diagnostic.
Index: lib/Frontend/ASTConsumers.cpp
===
--- lib/Frontend/ASTConsumers.cpp
+++ lib/Frontend/ASTConsumers.cpp
@@ -87,9 +87,10 @@
 << DC->getPrimaryContext() << "\n";
 } else
   Out << "Not a DeclContext\n";
-  } else if (OutputKind == Print)
-D->print(Out, /*Indentation=*/0, /*PrintInstantiation=*/true);
-  else if (OutputKind != None)
+  } else if (OutputKind == Print) {
+PrintingPolicy Policy(D->getASTContext().getLangOpts());
+D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true);
+  } else if (OutputKind != None)
 D->dump(Out, OutputKind == DumpFull);
 }
 
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -2111,12 +2111,12 @@
   void checkPartialSpecializationVisibility(SourceLocation Loc,
 NamedDecl *Spec);
 
-  /// \brief Retrieve a suitable printing policy.
+  /// \brief Retrieve a suitable printing policy for diagnostics.
   PrintingPolicy getPrintingPolicy() const {
 return getPrintingPolicy(Context, PP);
   }
 
-  /// \brief Retrieve a suitable printing policy.
+  /// \brief Retrieve a suitable printing policy for diagnostics.
   static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
   const Preprocessor &PP);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45463: [AST] Print correct tag decl for tag specifier

2018-05-10 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 146145.
jdenny edited the summary of this revision.
jdenny added a comment.

I've implemented the suggestion to use ElaboratedType.  See the last paragraph 
of the revised summary for details.

There might be trouble for CXPrintingPolicyProperty users.  That is, this patch 
shifts the semantics of IncludeTagDefinition away from the documented semantics 
and from what the name implies.  Then again, both were already misleading for a 
tag type without a member list (that is, definition).

I see a few possible paths:

1. Update the documentation for IncludeTagDefinition and assume the new 
behavior was the expected behavior all along.

2. #1 and rename IncludeTagDefinition to something like OwnedTagDeclaration.

3. Add OwnedTagDeclaration alongside IncludeTagDefinition.  
CXPrintingPolicyProperty users could set either.  We'd have to decide which 
would have precedence.  Internally, we would change Decl::printGroup to set 
OwnedTagDeclaration instead of IncludeTagDefinition, which otherwise would not 
be used internally.


https://reviews.llvm.org/D45463

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Sema/Sema.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/Misc/ast-print-enum-decl.c
  test/Misc/ast-print-record-decl.c

Index: test/Misc/ast-print-record-decl.c
===
--- /dev/null
+++ test/Misc/ast-print-record-decl.c
@@ -0,0 +1,251 @@
+// Check struct:
+//
+//   First check compiling and printing of this file.
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=struct -DBASES= -o - %s \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \
+//   RUN:   --input-file %t.c
+//
+//   Now check compiling and printing of the printed file.
+//
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.c
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.c
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -o - %t.c \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print %t.c \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s
+
+// Repeat for union:
+//
+//   First check compiling and printing of this file.
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=union -DBASES= -o - %s \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \
+//   RUN:   --input-file %t.c
+//
+//   Now check compiling and printing of the printed file.
+//
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.c
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.c
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -o - %t.c \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print %t.c \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s
+
+// Repeat for C++ (BASES helps ensure we're printing as C++ not as C):
+//
+//   First check compiling and printing of this file.
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=struct -DBASES=' : B' -o - \
+//   RUN:-xc++ %s \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
+//   RUN: > %t.cpp
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN:   -DBASES=' : B' %s --input-file %t.cpp
+//
+//   Now check compiling and printing of the printed file.
+//
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.cpp
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.cpp
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -o - %t.cpp \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print %t.cpp \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: -DBASES=' : B' %s
+
+// END.
+
+#ifndef KW
+# error KW undefined
+# define KW struct // help syntax checkers
+#endif
+
+#ifndef BASES
+# error BASES undefined
+# define BASES // help syntax checkers
+#endif
+
+struct B {};
+
+// CHECK-LABEL: defFirst
+void defFirst() {
+  // PRINT-NEXT: [[KW]]
+  // PRINT-DAG:  __attribute__((aligned(16)))
+  // PRINT-DAG:  __attribute__((deprecated("")))
+  // PRINT-NOT:  __attribute__
+  // PRINT-SAME: T[[BASES]] {
+  // PRINT-NEXT:   int i;
+  // PRINT-NEXT: } *p0;
+  // expected-warning@+2 {{'T' i

[PATCH] D45463: [AST] Print correct tag decl for tag specifier

2018-05-11 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 146351.
jdenny marked 10 inline comments as done.
jdenny edited the summary of this revision.
jdenny added a comment.

Made the suggested changes.  Thanks.


https://reviews.llvm.org/D45463

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Sema/Sema.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/DeclPrinter.cpp
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/Misc/ast-print-enum-decl.c
  test/Misc/ast-print-record-decl.c

Index: test/Misc/ast-print-record-decl.c
===
--- /dev/null
+++ test/Misc/ast-print-record-decl.c
@@ -0,0 +1,235 @@
+// Check struct:
+//
+//   First check compiling and printing of this file.
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=struct -DBASES= -o - %s \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \
+//   RUN:   --input-file %t.c
+//
+//   Now check compiling and printing of the printed file.
+//
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.c
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.c
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -o - %t.c \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print %t.c \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s
+
+// Repeat for union:
+//
+//   First check compiling and printing of this file.
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=union -DBASES= -o - %s \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \
+//   RUN:   --input-file %t.c
+//
+//   Now check compiling and printing of the printed file.
+//
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.c
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.c
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -o - %t.c \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print %t.c \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s
+
+// Repeat for C++ (BASES helps ensure we're printing as C++ not as C):
+//
+//   First check compiling and printing of this file.
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=struct -DBASES=' : B' -o - \
+//   RUN:-xc++ %s \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
+//   RUN: > %t.cpp
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN:   -DBASES=' : B' %s --input-file %t.cpp
+//
+//   Now check compiling and printing of the printed file.
+//
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.cpp
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.cpp
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -o - %t.cpp \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print %t.cpp \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: -DBASES=' : B' %s
+
+// END.
+
+#ifndef KW
+# error KW undefined
+# define KW struct // help syntax checkers
+#endif
+
+#ifndef BASES
+# error BASES undefined
+# define BASES // help syntax checkers
+#endif
+
+struct B {};
+
+// CHECK-LABEL: defFirst
+void defFirst() {
+  // PRINT-NEXT: [[KW]]
+  // PRINT-DAG:  __attribute__((aligned(16)))
+  // PRINT-DAG:  __attribute__((deprecated("")))
+  // PRINT-NOT:  __attribute__
+  // PRINT-SAME: T[[BASES]] {
+  // PRINT-NEXT:   int i;
+  // PRINT-NEXT: } *p0;
+  // expected-warning@+2 {{'T' is deprecated}}
+  // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}}
+  KW __attribute__((aligned(16))) __attribute__((deprecated(""))) T BASES {
+int i;
+  } *p0;
+
+  // PRINT-NEXT: [[KW]] T *p1;
+  KW T *p1; // expected-warning {{'T' is deprecated}}
+
+  // LLVM: store i64 16
+  long s0 = sizeof *p0;
+  // LLVM-NEXT: store i64 16
+  long s1 = sizeof *p1;
+}
+
+// CHECK-LABEL: defLast
+void defLast() {
+  // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T *p0;
+  KW __attribute__((aligned(16))) T *p0;
+
+  // PRINT-NEXT: [[KW]] __attribute__((deprecated(""))) T[[BASES]] {
+  // PRINT-NEXT:   int i;
+  // PRINT-NEXT: } *p1;
+  // expected-warning@+2 {{'T' is deprecated}}
+  // expected-note@+1 {{'T' has been explicitly marked deprecated here}}
+  KW __attribute__((deprecated(""))) T BASES { int i; } *p1;
+
+  //

[PATCH] D45463: [AST] Print correct tag decl for tag specifier

2018-05-11 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: lib/AST/DeclPrinter.cpp:218
 for (auto *A : Attrs) {
+  if (A->isInherited())
+continue;

I implemented inherited attribute suppression in this function with the 
expectation that the test suite would reveal a use case where that's wrong.  
However, the test suite behaved.  If you know of a use case, please let me know.


https://reviews.llvm.org/D45463



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


[PATCH] D45463: [AST] Print correct tag decl for tag specifier

2018-05-11 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D45463#1096406, @rsmith wrote:

> LGTM, thanks!


Thanks.  I'll remove the fixme as you asked.

A few comments ago , I mentioned that 
IncludeTagDefinition's documentation and name is drifting farther from its 
functionality.  Should we do something about that?


https://reviews.llvm.org/D45463



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


[PATCH] D45463: [AST] Print correct tag decl for tag specifier

2018-05-11 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D45463#1096629, @rsmith wrote:

> In https://reviews.llvm.org/D45463#1096499, @jdenny wrote:
>
> > A few comments ago , I mentioned 
> > that IncludeTagDefinition's documentation and name is drifting farther from 
> > its functionality.  Should we do something about that?
>
>
> I think we should deprecate that flag, and change it to have no effect. It is 
> an implementation detail of the AST printer and should never have been 
> exposed by libclang in the first place.


Thanks.  I'll address that in a separate patch then.


https://reviews.llvm.org/D45463



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


[PATCH] D45093: [AST] Fix -ast-print for _Bool when have diagnostics

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332275: [AST] Fix -ast-print for _Bool when have diagnostics 
(authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45093?vs=145711&id=146650#toc

Repository:
  rC Clang

https://reviews.llvm.org/D45093

Files:
  include/clang/Sema/Sema.h
  lib/Frontend/ASTConsumers.cpp
  lib/Sema/Sema.cpp
  test/Misc/ast-print-bool.c

Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -2113,12 +2113,12 @@
   void checkPartialSpecializationVisibility(SourceLocation Loc,
 NamedDecl *Spec);
 
-  /// Retrieve a suitable printing policy.
+  /// Retrieve a suitable printing policy for diagnostics.
   PrintingPolicy getPrintingPolicy() const {
 return getPrintingPolicy(Context, PP);
   }
 
-  /// Retrieve a suitable printing policy.
+  /// Retrieve a suitable printing policy for diagnostics.
   static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
   const Preprocessor &PP);
 
Index: test/Misc/ast-print-bool.c
===
--- test/Misc/ast-print-bool.c
+++ test/Misc/ast-print-bool.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_INT \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-INT,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_INT -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-INT,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc++ \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-BOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc++ -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-BOOL
+
+#if DEF_BOOL_CBOOL
+# define bool _Bool
+#elif DEF_BOOL_INT
+# define bool int
+#endif
+
+// BOOL-AS-CBOOL: _Bool i;
+// BOOL-AS-INT:   int i;
+// BOOL-AS-BOOL:  bool i;
+bool i;
+
+#ifndef __cplusplus
+// CBOOL: _Bool j;
+_Bool j;
+#endif
+
+// Induce a diagnostic (and verify we actually managed to do so), which used to
+// permanently alter the -ast-print printing policy for _Bool.  How bool is
+// defined by the preprocessor is examined only once per compilation, when the
+// diagnostic is emitted, and it used to affect the entirety of -ast-print, so
+// test only one definition of bool per compilation.
+#if DIAG
+void fn() { 1; } // expected-warning {{expression result unused}}
+#else
+// expected-no-diagnostics
+#endif
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -52,8 +52,8 @@
 PrintingPolicy Sema::getPrintingPolicy(const ASTContext &Context,
const Preprocessor &PP) {
   PrintingPolicy Policy = Context.getPrintingPolicy();
-  // Our printing policy is copied over the ASTContext printing policy whenever
-  // a diagnostic is emitted, so recompute it.
+  // In diagnostics, we print _Bool as bool if the latter is defined as the
+  // former.
   Policy.Bool = Context.getLangOpts().Bool;
   if (!Policy.Bool) {
 if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
@@ -1287,7 +1287,8 @@
 }
   }
 
-  // Set up the context's printing policy based on our current state.
+  // Copy the diagnostic printing policy over the ASTContext printing policy.
+  // TODO: Stop doing that.  See: https://reviews.llvm.org/D45093#1090292
   Context.setPrintingPolicy(getPrintingPolicy());
 
   // Emit the diagnostic.
Index: lib/Frontend/ASTConsumers.cpp
===
--- lib/Frontend/ASTConsumers.cpp
+++ lib/Frontend/ASTConsumers.cpp
@@ -87,9 +87,10 @@
 << DC->getPrimaryContext() << "\n";
 } else
   Out << "Not a DeclContext\n";
-  } else if (OutputKind == Print)
-D->print(Out, /*Indentation=*/0, /*PrintInstantiation=*/true);
-  else if (OutputKind != None)
+  } else if (OutputKind == Print) {
+PrintingPolicy Policy(D->getASTContext().getLangOpts());
+D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true);
+  } else if (OutputKind != None)
 D->dump(Out, OutputKind == DumpFull);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45463: [AST] Print correct tag decl for tag specifier

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332281: [AST] Print correct tag decl for tag specifier 
(authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45463?vs=146351&id=146658#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45463

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Sema/Sema.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/DeclPrinter.cpp
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/Misc/ast-print-enum-decl.c
  test/Misc/ast-print-record-decl.c

Index: include/clang/AST/ASTContext.h
===
--- include/clang/AST/ASTContext.h
+++ include/clang/AST/ASTContext.h
@@ -1419,8 +1419,8 @@
   QualType getParenType(QualType NamedType) const;
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
- NestedNameSpecifier *NNS,
- QualType NamedType) const;
+ NestedNameSpecifier *NNS, QualType NamedType,
+ TagDecl *OwnedTagDecl = nullptr) const;
   QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
 NestedNameSpecifier *NNS,
 const IdentifierInfo *Name,
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -56,6 +56,7 @@
 
 class ExtQuals;
 class QualType;
+class TagDecl;
 class Type;
 
 enum {
@@ -4865,14 +4866,18 @@
   /// The type that this qualified name refers to.
   QualType NamedType;
 
+  /// The (re)declaration of this tag type owned by this occurrence, or nullptr
+  /// if none.
+  TagDecl *OwnedTagDecl;
+
   ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
- QualType NamedType, QualType CanonType)
+ QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
 : TypeWithKeyword(Keyword, Elaborated, CanonType,
   NamedType->isDependentType(),
   NamedType->isInstantiationDependentType(),
   NamedType->isVariablyModifiedType(),
   NamedType->containsUnexpandedParameterPack()),
-  NNS(NNS), NamedType(NamedType) {
+  NNS(NNS), NamedType(NamedType), OwnedTagDecl(OwnedTagDecl) {
 assert(!(Keyword == ETK_None && NNS == nullptr) &&
"ElaboratedType cannot have elaborated type keyword "
"and name qualifier both null.");
@@ -4893,15 +4898,21 @@
   /// Returns whether this type directly provides sugar.
   bool isSugared() const { return true; }
 
+  /// Return the (re)declaration of this type owned by this occurrence of this
+  /// type, or nullptr if none.
+  TagDecl *getOwnedTagDecl() const { return OwnedTagDecl; }
+
   void Profile(llvm::FoldingSetNodeID &ID) {
-Profile(ID, getKeyword(), NNS, NamedType);
+Profile(ID, getKeyword(), NNS, NamedType, OwnedTagDecl);
   }
 
   static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
-  NestedNameSpecifier *NNS, QualType NamedType) {
+  NestedNameSpecifier *NNS, QualType NamedType,
+  TagDecl *OwnedTagDecl) {
 ID.AddInteger(Keyword);
 ID.AddPointer(NNS);
 NamedType.Profile(ID);
+ID.AddPointer(OwnedTagDecl);
   }
 
   static bool classof(const Type *T) {
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -1638,7 +1638,8 @@
   }
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
- const CXXScopeSpec &SS, QualType T);
+ const CXXScopeSpec &SS, QualType T,
+ TagDecl *OwnedTagDecl = nullptr);
 
   QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
   /// If AsUnevaluated is false, E is treated as though it were an evaluated
Index: test/Misc/ast-print-enum-decl.c
===
--- test/Misc/ast-print-enum-decl.c
+++ test/Misc/ast-print-enum-decl.c
@@ -0,0 +1,85 @@
+// First check compiling and printing of this file.
+//
+// RUN: %clang_cc1 -verify -ast-print %s > %t.c
+// RUN: FileCheck --check-prefixes=CHECK,PRINT %s --input-file %t.c
+//
+// Now check compiling and printing of the printed file.
+//
+// RUN: echo "// expected""-warning@* 6 {{'T' is deprecated}}" >> %t.c
+// RUN: echo "// expected""-note@* 6 {{'T' has been explicitly marked deprecated here}}" >> %t.c
+//
+// RUN: %clang_cc1 -verify -ast-print %t.c \
+// RUN: | FileCheck --check-prefixes=CHECK,PRINT %s
+
+// END.
+
+// CHECK-LABEL: defFirst
+void defFirst() {
+  // PRINT-NEXT: enum
+  /

[PATCH] D45463: [AST] Print correct tag decl for tag specifier

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jdenny marked an inline comment as done.
Closed by commit rL332281: [AST] Print correct tag decl for tag specifier 
(authored by jdenny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45463?vs=146351&id=146657#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45463

Files:
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/lib/AST/DeclPrinter.cpp
  cfe/trunk/lib/AST/TypePrinter.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/test/Misc/ast-print-enum-decl.c
  cfe/trunk/test/Misc/ast-print-record-decl.c

Index: cfe/trunk/include/clang/AST/ASTContext.h
===
--- cfe/trunk/include/clang/AST/ASTContext.h
+++ cfe/trunk/include/clang/AST/ASTContext.h
@@ -1419,8 +1419,8 @@
   QualType getParenType(QualType NamedType) const;
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
- NestedNameSpecifier *NNS,
- QualType NamedType) const;
+ NestedNameSpecifier *NNS, QualType NamedType,
+ TagDecl *OwnedTagDecl = nullptr) const;
   QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
 NestedNameSpecifier *NNS,
 const IdentifierInfo *Name,
Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -56,6 +56,7 @@
 
 class ExtQuals;
 class QualType;
+class TagDecl;
 class Type;
 
 enum {
@@ -4865,14 +4866,18 @@
   /// The type that this qualified name refers to.
   QualType NamedType;
 
+  /// The (re)declaration of this tag type owned by this occurrence, or nullptr
+  /// if none.
+  TagDecl *OwnedTagDecl;
+
   ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS,
- QualType NamedType, QualType CanonType)
+ QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
 : TypeWithKeyword(Keyword, Elaborated, CanonType,
   NamedType->isDependentType(),
   NamedType->isInstantiationDependentType(),
   NamedType->isVariablyModifiedType(),
   NamedType->containsUnexpandedParameterPack()),
-  NNS(NNS), NamedType(NamedType) {
+  NNS(NNS), NamedType(NamedType), OwnedTagDecl(OwnedTagDecl) {
 assert(!(Keyword == ETK_None && NNS == nullptr) &&
"ElaboratedType cannot have elaborated type keyword "
"and name qualifier both null.");
@@ -4893,15 +4898,21 @@
   /// Returns whether this type directly provides sugar.
   bool isSugared() const { return true; }
 
+  /// Return the (re)declaration of this type owned by this occurrence of this
+  /// type, or nullptr if none.
+  TagDecl *getOwnedTagDecl() const { return OwnedTagDecl; }
+
   void Profile(llvm::FoldingSetNodeID &ID) {
-Profile(ID, getKeyword(), NNS, NamedType);
+Profile(ID, getKeyword(), NNS, NamedType, OwnedTagDecl);
   }
 
   static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
-  NestedNameSpecifier *NNS, QualType NamedType) {
+  NestedNameSpecifier *NNS, QualType NamedType,
+  TagDecl *OwnedTagDecl) {
 ID.AddInteger(Keyword);
 ID.AddPointer(NNS);
 NamedType.Profile(ID);
+ID.AddPointer(OwnedTagDecl);
   }
 
   static bool classof(const Type *T) {
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -1638,7 +1638,8 @@
   }
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
- const CXXScopeSpec &SS, QualType T);
+ const CXXScopeSpec &SS, QualType T,
+ TagDecl *OwnedTagDecl = nullptr);
 
   QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
   /// If AsUnevaluated is false, E is treated as though it were an evaluated
Index: cfe/trunk/test/Misc/ast-print-record-decl.c
===
--- cfe/trunk/test/Misc/ast-print-record-decl.c
+++ cfe/trunk/test/Misc/ast-print-record-decl.c
@@ -0,0 +1,235 @@
+// Check struct:
+//
+//   First check compiling and printing of this file.
+//
+//   RUN: %clang -Xclang -verify -S -emit-llvm -DKW=struct -DBASES= -o - %s \
+//   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
+//
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct

[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 146668.
jdenny added a comment.

Rebased.  Ping.


https://reviews.llvm.org/D45465

Files:
  lib/AST/DeclPrinter.cpp
  test/Misc/ast-print-enum-decl.c
  test/Misc/ast-print-record-decl.c
  test/Sema/ast-print.c
  test/SemaCXX/ast-print.cpp

Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -214,10 +214,13 @@
 struct [[gnu::visibility("hidden")]] S;
 }
 
-// CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{};
+// CHECK:  struct CXXFunctionalCastExprPrint {
+// CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
 struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{};
 
-// CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{};
+// CHECK:  struct CXXTemporaryObjectExprPrint {
+// CHECK-NEXT:   CXXTemporaryObjectExprPrint();
+// CHECK-NEXT: } toe = CXXTemporaryObjectExprPrint{};
 struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{};
 
 namespace PR24872 {
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -83,8 +83,7 @@
   EnumWithAttributesFoo __attribute__((deprecated)),
   // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50
   EnumWithAttributesBar __attribute__((unavailable)) = 50
-  // CHECK-NEXT: };
-  // CHECK-NEXT: enum EnumWithAttributes *EnumWithAttributesPtr;
+  // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
 // FIXME: If enum is forward-declared at file scope, attributes are lost.
Index: test/Misc/ast-print-record-decl.c
===
--- test/Misc/ast-print-record-decl.c
+++ test/Misc/ast-print-record-decl.c
@@ -6,8 +6,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -18,7 +18,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \
+//   RUN: -DBASES= %s
 
 // Repeat for union:
 //
@@ -28,8 +29,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -40,7 +41,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \
+//   RUN: -DBASES= %s
 
 // Repeat for C++ (BASES helps ensure we're printing as C++ not as C):
 //
@@ -52,7 +54,7 @@
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
 //   RUN: > %t.cpp
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
@@ -64,7 +66,7 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.cpp \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN: -DBASES=' : B' %s
 
 // END.
@@ -153,25 +155,32 @@
   // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}}
   KW __attribute__((deprecated(""))) T *p0;
 
-  // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T[[BASES]] {
-  // PRINT-NEXT:   int i;
-  // PRINT-NEXT:   [[KW]] T *p2;
-  // PRINT-NEXT: } *p1;
-  KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}}
+  // PRINT-NEXT:  [[KW]] __attribute__((aligned(64))) T[[BASES]] {
+  // PRINT-NEXT:int i;
+  // PRINT-NEXT:[[KW]] T *p2;
+  // PRINT-NEXT:[[KW]] __attribute__((may_alias)) T *p3, *p4;
+  // PRINT-NEXT:  } *p1;
+  KW __attribute__(

[PATCH] D46846: [Attr] Fix printing attrs for enum forward decl at file scope

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: aaron.ballman, rsmith, hfinkel.

For example, given:

  enum __attribute__((deprecated)) T *p;

-ast-print produced:

  enum T *p;

The trouble was that the EnumDecl node was suppressed, as revealed by
-ast-dump.  The suppression of the EnumDecl was intentional in
r116122, but I don't understand why.  The suppression isn't needed for
the test suite to behave.


https://reviews.llvm.org/D46846

Files:
  lib/Sema/SemaDecl.cpp
  test/Sema/ast-print.c


Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field 
designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been 
explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is 
deprecated}}"
+// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been 
explicitly marked deprecated here}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been 
explicitly marked deprecated here}}"
 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
@@ -86,8 +88,7 @@
   // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note 
{{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
-// FIXME: If enum is forward-declared at file scope, attributes are lost.
-// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
+// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 
*EnumWithAttributes2Ptr;
 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked 
deprecated here}}
 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14273,7 +14273,6 @@
   // PrevDecl.
   TagDecl *New;
 
-  bool IsForwardReference = false;
   if (Kind == TTK_Enum) {
 // FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
 // enum X { A, B, C } D;D should chain to X.
@@ -14303,12 +14302,6 @@
 else if (getLangOpts().CPlusPlus)
   DiagID = diag::err_forward_ref_enum;
 Diag(Loc, DiagID);
-
-// If this is a forward-declared reference to an enumeration, make a
-// note of it; we won't actually be introducing the declaration into
-// the declaration context.
-if (TUK == TUK_Reference)
-  IsForwardReference = true;
   }
 }
 
@@ -14466,9 +14459,7 @@
 PushOnScopeChains(New, EnclosingScope, /* AddToContext = */ false);
   } else if (Name) {
 S = getNonFieldDeclScope(S);
-PushOnScopeChains(New, S, !IsForwardReference);
-if (IsForwardReference)
-  SearchDC->makeDeclVisibleInContext(New);
+PushOnScopeChains(New, S, true);
   } else {
 CurContext->addDecl(New);
   }


Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is deprecated}}"
+// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been explicitly marked deprecated here}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been explicitly marked deprecated here}}"
 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
@@ -86,8 +88,7 @@
   // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
-// FIXME: If enum is forward-declared at file scope, attributes are lost.
-// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
+// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 *EnumWithAttributes2Ptr;
 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked deprecated here}}
 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
Index: lib/Sema/SemaDecl.cpp
===

[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 146709.
jdenny marked 2 inline comments as done.
jdenny added a comment.

Made the suggested change.  Thanks!


https://reviews.llvm.org/D45465

Files:
  lib/AST/DeclPrinter.cpp
  test/Misc/ast-print-enum-decl.c
  test/Misc/ast-print-record-decl.c
  test/Sema/ast-print.c
  test/SemaCXX/ast-print.cpp

Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -214,10 +214,13 @@
 struct [[gnu::visibility("hidden")]] S;
 }
 
-// CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{};
+// CHECK:  struct CXXFunctionalCastExprPrint {
+// CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
 struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{};
 
-// CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{};
+// CHECK:  struct CXXTemporaryObjectExprPrint {
+// CHECK-NEXT:   CXXTemporaryObjectExprPrint();
+// CHECK-NEXT: } toe = CXXTemporaryObjectExprPrint{};
 struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{};
 
 namespace PR24872 {
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -83,8 +83,7 @@
   EnumWithAttributesFoo __attribute__((deprecated)),
   // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50
   EnumWithAttributesBar __attribute__((unavailable)) = 50
-  // CHECK-NEXT: };
-  // CHECK-NEXT: enum EnumWithAttributes *EnumWithAttributesPtr;
+  // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
 // FIXME: If enum is forward-declared at file scope, attributes are lost.
Index: test/Misc/ast-print-record-decl.c
===
--- test/Misc/ast-print-record-decl.c
+++ test/Misc/ast-print-record-decl.c
@@ -7,8 +7,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -19,7 +19,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \
+//   RUN: -DBASES= %s
 
 // Repeat for union:
 //
@@ -30,8 +31,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -42,7 +43,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \
+//   RUN: -DBASES= %s
 
 // Repeat for C++ (BASES helps ensure we're printing as C++ not as C):
 //
@@ -54,7 +56,7 @@
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
 //   RUN: > %t.cpp
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
@@ -66,7 +68,7 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.cpp \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN: -DBASES=' : B' %s
 
 // END.
@@ -155,25 +157,33 @@
   // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}}
   KW __attribute__((deprecated(""))) T *p0;
 
-  // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T[[BASES]] {
-  // PRINT-NEXT:   int i;
-  // PRINT-NEXT:   [[KW]] T *p2;
-  // PRINT-NEXT: } *p1;
-  KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}}
+  // PRINT-NEXT:  [[KW]] __attribute__((aligned(64))) T[[BASES]] {
+  // PRINT-NEXT:int i;
+  // PRINT-NEXT:[[KW]] T *p2;
+  // PRINT-NEXT:[[KW]] __attribute__((may_alias

[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D45465#1098710, @rsmith wrote:

> Looks good, thanks.


Thanks.

> It strikes me that this will still lead to inconsistencies. For example, I 
> expect this:
> 
>   struct A { struct B *a, *b; struct B *c, *d; };
> 
> 
> ... to print as:
> 
>   struct A {
> struct B *a, *b;
> struct B *c;
> struct B *d;
>   };
> 
> 
> ... where the first two are joined because their type owns a declaration of 
> `struct B`, and the second two are not joined because their type does not own 
> a declaration (it just has a reference to the already-existing declaration of 
> `struct B`). One (somewhat hacky) way to address this would be to compare the 
> starting source locations of a sequence of `DeclaratorDecl`s and group them 
> if it's the same.

While it would be nice to fix that, I'm not as concerned because, AFAICT, that 
doesn't ever change the semantics.


https://reviews.llvm.org/D45465



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


[PATCH] D45465: [AST] Fix printing tag decl groups in decl contexts

2018-05-14 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332314: [AST] Fix printing tag decl groups in decl contexts 
(authored by jdenny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45465?vs=146709&id=146727#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45465

Files:
  cfe/trunk/lib/AST/DeclPrinter.cpp
  cfe/trunk/test/Misc/ast-print-enum-decl.c
  cfe/trunk/test/Misc/ast-print-record-decl.c
  cfe/trunk/test/Sema/ast-print.c
  cfe/trunk/test/SemaCXX/ast-print.cpp

Index: cfe/trunk/test/Misc/ast-print-enum-decl.c
===
--- cfe/trunk/test/Misc/ast-print-enum-decl.c
+++ cfe/trunk/test/Misc/ast-print-enum-decl.c
@@ -83,3 +83,23 @@
   // PRINT-NEXT: enum T *p4;
   enum T *p4;
 }
+
+// Check that tag decl groups stay together in decl contexts.
+
+// PRINT-LABEL: enum DeclGroupAtFileScope {
+// PRINT-NEXT:DeclGroupAtFileScope0
+// PRINT-NEXT:  } *DeclGroupAtFileScopePtr;
+enum DeclGroupAtFileScope { DeclGroupAtFileScope0 } *DeclGroupAtFileScopePtr;
+
+// PRINT-LABEL: struct DeclGroupInMemberList
+struct DeclGroupInMemberList {
+  // PRINT-NEXT:  enum T1 {
+  // PRINT-NEXT:T10
+  // PRINT-NEXT:  } *p0;
+  enum T1 { T10 } *p0;
+  // PRINT-NEXT:  enum T2 {
+  // PRINT-NEXT:T20
+  // PRINT-NEXT:  } *p1, *p2;
+  enum T2 { T20 } *p1, *p2;
+  // PRINT-NEXT: };
+};
Index: cfe/trunk/test/Misc/ast-print-record-decl.c
===
--- cfe/trunk/test/Misc/ast-print-record-decl.c
+++ cfe/trunk/test/Misc/ast-print-record-decl.c
@@ -7,8 +7,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -19,7 +19,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=struct -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=struct \
+//   RUN: -DBASES= %s
 
 // Repeat for union:
 //
@@ -30,8 +31,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=union -DBASES= %s > %t.c
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s \
-//   RUN:   --input-file %t.c
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union -DBASES= \
+//   RUN:   %s --input-file %t.c
 //
 //   Now check compiling and printing of the printed file.
 //
@@ -42,7 +43,8 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.c \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT -DKW=union -DBASES= %s
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-C -DKW=union \
+//   RUN: -DBASES= %s
 
 // Repeat for C++ (BASES helps ensure we're printing as C++ not as C):
 //
@@ -54,7 +56,7 @@
 //
 //   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
 //   RUN: > %t.cpp
-//   RUN: FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
@@ -66,7 +68,7 @@
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
 //   RUN: %clang_cc1 -verify -ast-print %t.cpp \
-//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,CXX -DKW=struct \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN: -DBASES=' : B' %s
 
 // END.
@@ -155,25 +157,33 @@
   // expected-note@+1 2 {{'T' has been explicitly marked deprecated here}}
   KW __attribute__((deprecated(""))) T *p0;
 
-  // PRINT-NEXT: [[KW]] __attribute__((aligned(16))) T[[BASES]] {
-  // PRINT-NEXT:   int i;
-  // PRINT-NEXT:   [[KW]] T *p2;
-  // PRINT-NEXT: } *p1;
-  KW __attribute__((aligned(16))) T BASES { // expected-warning {{'T' is deprecated}}
+  // PRINT-NEXT:  [[KW]] __attribute__((aligned(64))) T[[BASES]] {
+  // PRINT-NEXT:int i;
+  // PRINT-NEXT:[[KW]] T *p2;
+  // PRINT-NEXT:[[KW]] __attribute__((may_alias)) T *p3;
+  // PRINT-NEXT:[[KW]] T *p4;
+  // PRINT-NEXT:  } *p1;
+  KW __attribute__((aligned(64))) T BASES { // expected-warning {{'T' is deprecated}}
 int i;
 KW T *p2;
+// FIXME: For C++, T at p3 loses aligned and deprecated, perhaps because
+// that RecordDecl isn't in the same redecl list.  Perhaps the redecl lists
+// are split here but not in C due to the different scoping rules in C++
+  

[PATCH] D46894: [Attr] Don't print implicit attributes

2018-05-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: aaron.ballman, rsmith, hfinkel.

Fixes bug reported at:

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180514/228390.html


https://reviews.llvm.org/D46894

Files:
  lib/AST/DeclPrinter.cpp
  test/Misc/ast-print-record-decl.c


Index: test/Misc/ast-print-record-decl.c
===
--- test/Misc/ast-print-record-decl.c
+++ test/Misc/ast-print-record-decl.c
@@ -54,20 +54,34 @@
 //   RUN:-DKW=struct -DBASES=' : B' -o - -xc++ %s \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
-//   RUN: %clang_cc1 -verify -triple x86_64-linux -ast-print -DKW=struct 
-DBASES=' : B' -xc++ %s \
-//   RUN: > %t.cpp
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
+//   RUN:> %t.cpp
 //   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
 //
-//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.cpp
-//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked 
deprecated here}}" >> %t.cpp
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" > %t.diags
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked 
deprecated here}}" >> %t.diags
+//   RUN: cat %t.diags >> %t.cpp
 //
 //   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm -o - 
%t.cpp \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
-//   RUN: %clang_cc1 -verify -triple x86_64-linux -ast-print %t.cpp \
+//   RUN: %clang_cc1 -verify -ast-print %t.cpp \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
+//   RUN: -DBASES=' : B' %s
+//
+//   Make sure implicit attributes aren't printed.  See comments in inMemberPtr
+//   for details.
+//
+//   RUN: %clang_cc1 -triple i686-pc-win32 -verify -ast-print -DKW=struct \
+//   RUN:-DBASES=' : B' -xc++ %s > %t.cpp
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
+//   RUN:   -DBASES=' : B' %s --input-file %t.cpp
+//
+//   RUN: cat %t.diags >> %t.cpp
+//   RUN: %clang_cc1 -triple i686-pc-win32 -verify -ast-print %t.cpp \
 //   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN: -DBASES=' : B' %s
 
@@ -236,6 +250,9 @@
 #ifdef __cplusplus
 // PRINT-CXX-LABEL: inMemberPtr
 void inMemberPtr() {
+  // Under windows, the implicit attribute __single_inheritance used to print
+  // between KW and T1 here, but that wasn't faithful to the original source.
+  //
   // PRINT-CXX-NEXT: [[KW]] T1 {
   // PRINT-CXX-NEXT:   int i;
   // PRINT-CXX-NEXT: };
Index: lib/AST/DeclPrinter.cpp
===
--- lib/AST/DeclPrinter.cpp
+++ lib/AST/DeclPrinter.cpp
@@ -215,7 +215,7 @@
   if (D->hasAttrs()) {
 AttrVec &Attrs = D->getAttrs();
 for (auto *A : Attrs) {
-  if (A->isInherited())
+  if (A->isInherited() || A->isImplicit())
 continue;
   switch (A->getKind()) {
 #define ATTR(X)


Index: test/Misc/ast-print-record-decl.c
===
--- test/Misc/ast-print-record-decl.c
+++ test/Misc/ast-print-record-decl.c
@@ -54,20 +54,34 @@
 //   RUN:-DKW=struct -DBASES=' : B' -o - -xc++ %s \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
-//   RUN: %clang_cc1 -verify -triple x86_64-linux -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
-//   RUN: > %t.cpp
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
+//   RUN:> %t.cpp
 //   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
 //
-//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.cpp
-//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.cpp
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" > %t.diags
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.diags
+//   RUN: cat %t.diags >> %t.cpp
 //
 //   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm -o - %t.cpp \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
-//   RUN: %clang_cc1 -verify -triple x86_64-linux -ast-print %t.cpp \
+//   RUN: %clang_cc1 -verify -ast-print %t.cpp \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
+//   RUN: -DBASES=' : B' %s
+//
+//   Make sure implicit attributes aren't printed.  See comments in inMemberPtr
+//   for details.
+//
+//   RUN: %clang_cc1 -triple i686-pc-win32 -verify -ast-print -DKW=struct \
+//   RUN:-DBASES=' : B' -xc++ %s > %t.cpp
+//   RUN: FileCheck --check-

[PATCH] D46903: [Attr] Don't print attr arg with default value

2018-05-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: aaron.ballman, rsmith, hfinkel.

For example, given:

  class __single_inheritance T;

-ast-print -fms-extensions used to print:

  class __single_inheritance(1) T;

Clang fails to parse that because the "(1)" is not valid syntax.

This was discovered at:

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180514/228390.html

To fix that, this patch generally suppresses printing any attribute
argument that has its default value unless other arguments will be
printed after it.  Doing so should always maintain the original source
semantics and produce valid syntax.

However, doing so also drops arguments where attributes are legally
specified explicitly with their default values but are not followed by
other arguments.  Correct syntax in the previous case seems more
important than exact textual fidelity in this case.


https://reviews.llvm.org/D46903

Files:
  test/SemaCXX/attr-print.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -374,6 +374,11 @@
 OS << Default;
   OS << ";";
 }
+
+std::string getIsOmitted() const override {
+  return "Default" + getUpperName().str() + " == get" +
+ getUpperName().str() + "()";
+}
   };
 
   class StringArgument : public Argument {
@@ -1432,6 +1437,7 @@
   unsigned NonFakeArgs = 0;
   unsigned TrailingOptArgs = 0;
   bool FoundNonOptArg = false;
+  std::string Indent = "";
   for (const auto &arg : llvm::reverse(Args)) {
 if (arg->isFake())
   continue;
@@ -1446,9 +1452,14 @@
 }
 if (!TrailingOptArgs++)
   OS << "\";\n"
- << "unsigned TrailingOmittedArgs = 0;\n";
-OS << "if (" << arg->getIsOmitted() << ")\n"
-   << "  ++TrailingOmittedArgs;\n";
+ << Indent << "unsigned TrailingOmittedArgs = 0;\n";
+OS << Indent << "if (" << arg->getIsOmitted() << ") {\n";
+Indent += "  ";
+OS << Indent << "++TrailingOmittedArgs;\n";
+  }
+  for (unsigned i = 0; i < TrailingOptArgs; ++i) {
+Indent.resize(Indent.size() - 2);
+OS << Indent << "}\n";
   }
   if (TrailingOptArgs)
 OS << "OS << \"";
@@ -1463,26 +1474,21 @@
   for (const auto &arg : Args) {
 if (arg->isFake())
   continue;
-if (ArgIndex) {
-  if (ArgIndex >= NonFakeArgs - TrailingOptArgs)
-OS << "\";\n"
-   << "if (" << ArgIndex << " < " << NonFakeArgs
-   << " - TrailingOmittedArgs)\n"
-   << "  OS << \", \";\n"
-   << "OS << \"";
-  else
-OS << ", ";
-}
-std::string IsOmitted = arg->getIsOmitted();
-if (arg->isOptional() && IsOmitted != "false")
+if (ArgIndex >= NonFakeArgs - TrailingOptArgs) {
   OS << "\";\n"
- << "if (!(" << IsOmitted << ")) {\n"
- << "  OS << \"";
+ << "if (" << ArgIndex << " < " << NonFakeArgs
+ << " - TrailingOmittedArgs) {\n";
+  if (ArgIndex)
+OS << "  OS << \", \";\n";
+  OS << "  OS << \"";
+} else if (ArgIndex)
+  OS << ", ";
 arg->writeValue(OS);
-if (arg->isOptional() && IsOmitted != "false")
+if (ArgIndex >= NonFakeArgs - TrailingOptArgs) {
   OS << "\";\n"
  << "}\n"
  << "OS << \"";
+}
 ++ArgIndex;
   }
   if (TrailingOptArgs < NonFakeArgs)
Index: test/SemaCXX/attr-print.cpp
===
--- test/SemaCXX/attr-print.cpp
+++ test/SemaCXX/attr-print.cpp
@@ -34,3 +34,27 @@
   // CHECK: void callableWhen() __attribute__((callable_when("unconsumed", "consumed")));
   void callableWhen()  __attribute__((callable_when("unconsumed", "consumed")));
 };
+
+// CHECK: class __single_inheritance SingleInheritance;
+class __single_inheritance SingleInheritance;
+
+// CHECK: void sentinel(int a, ...) __attribute__((sentinel));
+void sentinel(int a, ...) __attribute__((sentinel));
+
+// CHECK: void sentinel_1n(int a, ...) __attribute__((sentinel(1)));
+void sentinel_1n(int a, ...) __attribute__((sentinel(1)));
+
+// CHECK: void sentinel_1d2n(int a, ...) __attribute__((sentinel(0, 1)));
+void sentinel_1d2n(int a, ...) __attribute__((sentinel(0, 1)));
+
+// CHECK: void sentinel_1n2n(int a, ...) __attribute__((sentinel(1, 1)));
+void sentinel_1n2n(int a, ...) __attribute__((sentinel(1, 1)));
+
+// It would be better if we didn't lose arguments in the following cases, but
+// at least the default values have the same semantics.
+
+// CHECK: void sentinel_1d(int a, ...) __attribute__((sentinel));
+void sentinel_1d(int a, ...) __attribute

[PATCH] D46903: [Attr] Don't print attr arg with default value

2018-05-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

I occurs to me now that I could have fixed __single_inheritance by declaring 
its argument "fake".  However, I still prefer the above solution because (1) it 
should help with any other attributes where arguments should have been declared 
fake (but no, I haven't identified any yet), and (2) it generally makes 
attribute printing more succinct, including cases where originally implicit 
values were printing as explicit.  Again, the sacrifice is that some explicit 
values now print as implicit, but at least the semantics don't change.

If others disagree, I can change this.


https://reviews.llvm.org/D46903



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


[PATCH] D46905: [Attr] Don't print fake MSInheritance argument

2018-05-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: aaron.ballman, rsmith, hfinkel.

This was discovered at:

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180514/228390.html


https://reviews.llvm.org/D46905

Files:
  include/clang/Basic/Attr.td
  test/SemaCXX/attr-print.cpp


Index: test/SemaCXX/attr-print.cpp
===
--- test/SemaCXX/attr-print.cpp
+++ test/SemaCXX/attr-print.cpp
@@ -34,3 +34,12 @@
   // CHECK: void callableWhen() __attribute__((callable_when("unconsumed", 
"consumed")));
   void callableWhen()  __attribute__((callable_when("unconsumed", 
"consumed")));
 };
+
+// CHECK: class __single_inheritance SingleInheritance;
+class __single_inheritance SingleInheritance;
+
+// CHECK: class __multiple_inheritance MultipleInheritance;
+class __multiple_inheritance MultipleInheritance;
+
+// CHECK: class __virtual_inheritance VirtualInheritance;
+class __virtual_inheritance VirtualInheritance;
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -184,7 +184,8 @@
 class AlignedArgument : Argument;
 
 // A bool argument with a default value
-class DefaultBoolArgument : BoolArgument {
+class DefaultBoolArgument
+: BoolArgument {
   bit Default = default;
 }
 
@@ -2617,7 +2618,7 @@
 
 def MSInheritance : InheritableAttr {
   let LangOpts = [MicrosoftExt];
-  let Args = [DefaultBoolArgument<"BestCase", 1>];
+  let Args = [DefaultBoolArgument<"BestCase", /*default*/1, /*fake*/1>];
   let Spellings = [Keyword<"__single_inheritance">,
Keyword<"__multiple_inheritance">,
Keyword<"__virtual_inheritance">,


Index: test/SemaCXX/attr-print.cpp
===
--- test/SemaCXX/attr-print.cpp
+++ test/SemaCXX/attr-print.cpp
@@ -34,3 +34,12 @@
   // CHECK: void callableWhen() __attribute__((callable_when("unconsumed", "consumed")));
   void callableWhen()  __attribute__((callable_when("unconsumed", "consumed")));
 };
+
+// CHECK: class __single_inheritance SingleInheritance;
+class __single_inheritance SingleInheritance;
+
+// CHECK: class __multiple_inheritance MultipleInheritance;
+class __multiple_inheritance MultipleInheritance;
+
+// CHECK: class __virtual_inheritance VirtualInheritance;
+class __virtual_inheritance VirtualInheritance;
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -184,7 +184,8 @@
 class AlignedArgument : Argument;
 
 // A bool argument with a default value
-class DefaultBoolArgument : BoolArgument {
+class DefaultBoolArgument
+: BoolArgument {
   bit Default = default;
 }
 
@@ -2617,7 +2618,7 @@
 
 def MSInheritance : InheritableAttr {
   let LangOpts = [MicrosoftExt];
-  let Args = [DefaultBoolArgument<"BestCase", 1>];
+  let Args = [DefaultBoolArgument<"BestCase", /*default*/1, /*fake*/1>];
   let Spellings = [Keyword<"__single_inheritance">,
Keyword<"__multiple_inheritance">,
Keyword<"__virtual_inheritance">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46903: [Attr] Don't print attr arg with default value

2018-05-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny abandoned this revision.
jdenny added a comment.

After further thought, this patch doesn't seem worthwhile.  Sorry for all the 
noise.


https://reviews.llvm.org/D46903



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


[PATCH] D46894: [Attr] Don't print implicit attributes

2018-05-15 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332411: [Attr] Don't print implicit attributes 
(authored by jdenny, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D46894

Files:
  lib/AST/DeclPrinter.cpp
  test/Misc/ast-print-record-decl.c


Index: test/Misc/ast-print-record-decl.c
===
--- test/Misc/ast-print-record-decl.c
+++ test/Misc/ast-print-record-decl.c
@@ -54,20 +54,34 @@
 //   RUN:-DKW=struct -DBASES=' : B' -o - -xc++ %s \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
-//   RUN: %clang_cc1 -verify -triple x86_64-linux -ast-print -DKW=struct 
-DBASES=' : B' -xc++ %s \
-//   RUN: > %t.cpp
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
+//   RUN:> %t.cpp
 //   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
 //
-//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.cpp
-//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked 
deprecated here}}" >> %t.cpp
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" > %t.diags
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked 
deprecated here}}" >> %t.diags
+//   RUN: cat %t.diags >> %t.cpp
 //
 //   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm -o - 
%t.cpp \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
-//   RUN: %clang_cc1 -verify -triple x86_64-linux -ast-print %t.cpp \
+//   RUN: %clang_cc1 -verify -ast-print %t.cpp \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
+//   RUN: -DBASES=' : B' %s
+//
+//   Make sure implicit attributes aren't printed.  See comments in inMemberPtr
+//   for details.
+//
+//   RUN: %clang_cc1 -triple i686-pc-win32 -verify -ast-print -DKW=struct \
+//   RUN:-DBASES=' : B' -xc++ %s > %t.cpp
+//   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
+//   RUN:   -DBASES=' : B' %s --input-file %t.cpp
+//
+//   RUN: cat %t.diags >> %t.cpp
+//   RUN: %clang_cc1 -triple i686-pc-win32 -verify -ast-print %t.cpp \
 //   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN: -DBASES=' : B' %s
 
@@ -236,6 +250,9 @@
 #ifdef __cplusplus
 // PRINT-CXX-LABEL: inMemberPtr
 void inMemberPtr() {
+  // Under windows, the implicit attribute __single_inheritance used to print
+  // between KW and T1 here, but that wasn't faithful to the original source.
+  //
   // PRINT-CXX-NEXT: [[KW]] T1 {
   // PRINT-CXX-NEXT:   int i;
   // PRINT-CXX-NEXT: };
Index: lib/AST/DeclPrinter.cpp
===
--- lib/AST/DeclPrinter.cpp
+++ lib/AST/DeclPrinter.cpp
@@ -215,7 +215,7 @@
   if (D->hasAttrs()) {
 AttrVec &Attrs = D->getAttrs();
 for (auto *A : Attrs) {
-  if (A->isInherited())
+  if (A->isInherited() || A->isImplicit())
 continue;
   switch (A->getKind()) {
 #define ATTR(X)


Index: test/Misc/ast-print-record-decl.c
===
--- test/Misc/ast-print-record-decl.c
+++ test/Misc/ast-print-record-decl.c
@@ -54,20 +54,34 @@
 //   RUN:-DKW=struct -DBASES=' : B' -o - -xc++ %s \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
-//   RUN: %clang_cc1 -verify -triple x86_64-linux -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
-//   RUN: > %t.cpp
+//   RUN: %clang_cc1 -verify -ast-print -DKW=struct -DBASES=' : B' -xc++ %s \
+//   RUN:> %t.cpp
 //   RUN: FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
 //   RUN:   -DBASES=' : B' %s --input-file %t.cpp
 //
 //   Now check compiling and printing of the printed file.
 //
-//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" >> %t.cpp
-//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.cpp
+//   RUN: echo "// expected""-warning@* 10 {{'T' is deprecated}}" > %t.diags
+//   RUN: echo "// expected""-note@* 10 {{'T' has been explicitly marked deprecated here}}" >> %t.diags
+//   RUN: cat %t.diags >> %t.cpp
 //
 //   RUN: %clang -target x86_64-linux -Xclang -verify -S -emit-llvm -o - %t.cpp \
 //   RUN: | FileCheck --check-prefixes=CHECK,LLVM %s
 //
-//   RUN: %clang_cc1 -verify -triple x86_64-linux -ast-print %t.cpp \
+//   RUN: %clang_cc1 -verify -ast-print %t.cpp \
+//   RUN: | FileCheck --check-prefixes=CHECK,PRINT,PRINT-CXX -DKW=struct \
+//   RUN: -DBASES=' : B' %s
+//
+//   Make sure implicit attributes aren't printed.  See comments in inMemberPtr
+//   for details.
+//
+//   RUN: %clang_cc1 -triple i686-pc-win32 -verify -ast-print -DKW=struct \
+//   RUN:-DBASES=' : B' -xc++ %s > %t.cpp
+//   RUN: FileC

[PATCH] D46919: [libclang] Deprecate CXPrintingPolicy_IncludeTagDefinition

2018-05-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: rsmith.

And make it have no effect.  Suggested at:

https://reviews.llvm.org/D45463#1096629

I'm not sure of the proper way to deprecate something in libclang.
Let me know if something else is needed.


https://reviews.llvm.org/D46919

Files:
  include/clang-c/Index.h
  include/clang/AST/PrettyPrinter.h
  lib/AST/DeclPrinter.cpp
  lib/AST/TypePrinter.cpp

Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -454,7 +454,7 @@
 OS << '(';
 
   PrintingPolicy InnerPolicy(Policy);
-  InnerPolicy.IncludeTagDefinition = false;
+  InnerPolicy.PrintOwnedTagDecl = false;
   TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
 
   OS << "::*";
@@ -1054,9 +1054,9 @@
 }
 
 void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition) {
+  if (Policy.PrintOwnedTagDecl) {
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.PrintOwnedTagDecl = false;
 D->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
@@ -1209,35 +1209,34 @@
 
 void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl()) {
+  if (Policy.PrintOwnedTagDecl && T->getOwnedTagDecl()) {
 TagDecl *OwnedTagDecl = T->getOwnedTagDecl();
 assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() &&
"OwnedTagDecl expected to be a declaration for the type");
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.PrintOwnedTagDecl = false;
 OwnedTagDecl->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
   }
 
   // The tag definition will take care of these.
-  if (!Policy.IncludeTagDefinition)
-  {
+  if (!Policy.PrintOwnedTagDecl) {
 OS << TypeWithKeyword::getKeywordName(T->getKeyword());
 if (T->getKeyword() != ETK_None)
   OS << " ";
 NestedNameSpecifier *Qualifier = T->getQualifier();
 if (Qualifier)
   Qualifier->print(OS, Policy);
   }
-  
+
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printBefore(T->getNamedType(), OS);
 }
 
 void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl())
+  if (Policy.PrintOwnedTagDecl && T->getOwnedTagDecl())
 return;
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printAfter(T->getNamedType(), OS);
Index: lib/AST/DeclPrinter.cpp
===
--- lib/AST/DeclPrinter.cpp
+++ lib/AST/DeclPrinter.cpp
@@ -178,12 +178,12 @@
   for ( ; Begin != End; ++Begin) {
 if (isFirst) {
   if(TD)
-SubPolicy.IncludeTagDefinition = true;
+SubPolicy.PrintOwnedTagDecl = true;
   SubPolicy.SuppressSpecifiers = false;
   isFirst = false;
 } else {
   if (!isFirst) Out << ", ";
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.PrintOwnedTagDecl = false;
   SubPolicy.SuppressSpecifiers = true;
 }
 
@@ -849,7 +849,7 @@
   }
   PrintingPolicy SubPolicy(Policy);
   SubPolicy.SuppressSpecifiers = false;
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.PrintOwnedTagDecl = false;
   Init->printPretty(Out, nullptr, SubPolicy, Indentation);
   if ((D->getInitStyle() == VarDecl::CallInit) && !isa(Init))
 Out << ")";
Index: include/clang/AST/PrettyPrinter.h
===
--- include/clang/AST/PrettyPrinter.h
+++ include/clang/AST/PrettyPrinter.h
@@ -40,7 +40,8 @@
   PrintingPolicy(const LangOptions &LO)
 : Indentation(2), SuppressSpecifiers(false),
   SuppressTagKeyword(LO.CPlusPlus),
-  IncludeTagDefinition(false), SuppressScope(false),
+  IncludeTagDefinition(false), PrintOwnedTagDecl(false),
+  SuppressScope(false),
   SuppressUnwrittenScope(false), SuppressInitializers(false),
   ConstantArraySizeAsWritten(false), AnonymousTagLocations(true),
   SuppressStrongLifetime(false), SuppressLifetimeQualifiers(false),
@@ -93,15 +94,18 @@
   /// \endcode
   bool SuppressTagKeyword : 1;
 
-  /// When true, include the body of a tag definition.
+  /// This flag is deprecated and no longer has any effect.
+  bool IncludeTagDefinition : 1;
+
+  /// When true, print any tag declaration owned by an elaborated type.
   ///
-  /// This is used to place the definition of a struct
-  /// in the middle of another declaration as with:
+  /// This is used to faithfully print the exact tag declaration that appears
+  /// within another declaration.  For example:
   ///
   /// \code
-  /// typedef struct { int x, y; } Point;
+  /// typedef struct T 

[PATCH] D46919: [libclang] Deprecate CXPrintingPolicy_IncludeTagDefinition

2018-05-16 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D46919#1100493, @rsmith wrote:

> The deprecated enumerator is also referenced by 
> `tools/c-index-test/c-index-test.c`


This test prompted me to keep the IncludeTagDefinition member in PrintingPolicy 
so that clang_PrintingPolicy_getProperty would return the previous value set by 
clang_PrintingPolicy_setProperty.  Otherwise, the value doesn't have any 
effect.  Is that self-consistency not worth worrying about?  If so, I'll remove 
both.

> This looks fine to me, but let's leave this review thread open for a week or 
> so, to give people a bit more time to object in case they're using the flag 
> for something.

Sure.




Comment at: include/clang/AST/PrettyPrinter.h:100-108
+  /// When true, print any tag declaration owned by an elaborated type.
   ///
-  /// This is used to place the definition of a struct
-  /// in the middle of another declaration as with:
+  /// This is used to faithfully print the exact tag declaration that appears
+  /// within another declaration.  For example:
   ///
   /// \code
+  /// typedef struct T { int x, y; } Point;

rsmith wrote:
> Please explicitly mark this as being transient state that's internal to the 
> printing algorithm and not part of its external configuration, so that people 
> don't try to expose it again in the future. The same is true for a bunch of 
> the other flags around here -- if we're going to do this, we should 
> systematically examine these flags to see which ones are external 
> configuration and which ones are internal state that we're (hackily) passing 
> between printing steps via the `PrintingPolicy`. It would also make sense to 
> move the internal state flags to a separate struct from the policy.
> Please explicitly mark this as being transient state that's internal to the 
> printing algorithm and not part of its external configuration, so that people 
> don't try to expose it again in the future.

Will do.

> The same is true for a bunch of the other flags around here -- if we're going 
> to do this, we should systematically examine these flags to see which ones 
> are external configuration and which ones are internal state that we're 
> (hackily) passing between printing steps via the PrintingPolicy.

Doing that now sounds like a lot of analysis and difficult judgment calls 
without much immediate gain -- at least for me as I'm not so familiar with all 
the flags and their potential uses from libclang.  My inclination is to write a 
fixme and refactor gradually.

> It would also make sense to move the internal state flags to a separate 
> struct from the policy.

Are you ok with making the new struct a member of the existing policy to 
simplify the refactoring effort?


https://reviews.llvm.org/D46919



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


[PATCH] D46905: [Attr] Don't print fake MSInheritance argument

2018-05-16 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332481: [Attr] Don't print fake MSInheritance argument 
(authored by jdenny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46905?vs=146923&id=147096#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46905

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/test/SemaCXX/attr-print.cpp


Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -184,7 +184,8 @@
 class AlignedArgument : Argument;
 
 // A bool argument with a default value
-class DefaultBoolArgument : BoolArgument {
+class DefaultBoolArgument
+: BoolArgument {
   bit Default = default;
 }
 
@@ -2624,7 +2625,7 @@
 
 def MSInheritance : InheritableAttr {
   let LangOpts = [MicrosoftExt];
-  let Args = [DefaultBoolArgument<"BestCase", 1>];
+  let Args = [DefaultBoolArgument<"BestCase", /*default*/1, /*fake*/1>];
   let Spellings = [Keyword<"__single_inheritance">,
Keyword<"__multiple_inheritance">,
Keyword<"__virtual_inheritance">,
Index: cfe/trunk/test/SemaCXX/attr-print.cpp
===
--- cfe/trunk/test/SemaCXX/attr-print.cpp
+++ cfe/trunk/test/SemaCXX/attr-print.cpp
@@ -34,3 +34,12 @@
   // CHECK: void callableWhen() __attribute__((callable_when("unconsumed", 
"consumed")));
   void callableWhen()  __attribute__((callable_when("unconsumed", 
"consumed")));
 };
+
+// CHECK: class __single_inheritance SingleInheritance;
+class __single_inheritance SingleInheritance;
+
+// CHECK: class __multiple_inheritance MultipleInheritance;
+class __multiple_inheritance MultipleInheritance;
+
+// CHECK: class __virtual_inheritance VirtualInheritance;
+class __virtual_inheritance VirtualInheritance;


Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -184,7 +184,8 @@
 class AlignedArgument : Argument;
 
 // A bool argument with a default value
-class DefaultBoolArgument : BoolArgument {
+class DefaultBoolArgument
+: BoolArgument {
   bit Default = default;
 }
 
@@ -2624,7 +2625,7 @@
 
 def MSInheritance : InheritableAttr {
   let LangOpts = [MicrosoftExt];
-  let Args = [DefaultBoolArgument<"BestCase", 1>];
+  let Args = [DefaultBoolArgument<"BestCase", /*default*/1, /*fake*/1>];
   let Spellings = [Keyword<"__single_inheritance">,
Keyword<"__multiple_inheritance">,
Keyword<"__virtual_inheritance">,
Index: cfe/trunk/test/SemaCXX/attr-print.cpp
===
--- cfe/trunk/test/SemaCXX/attr-print.cpp
+++ cfe/trunk/test/SemaCXX/attr-print.cpp
@@ -34,3 +34,12 @@
   // CHECK: void callableWhen() __attribute__((callable_when("unconsumed", "consumed")));
   void callableWhen()  __attribute__((callable_when("unconsumed", "consumed")));
 };
+
+// CHECK: class __single_inheritance SingleInheritance;
+class __single_inheritance SingleInheritance;
+
+// CHECK: class __multiple_inheritance MultipleInheritance;
+class __multiple_inheritance MultipleInheritance;
+
+// CHECK: class __virtual_inheritance VirtualInheritance;
+class __virtual_inheritance VirtualInheritance;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46846: [Attr] Fix loss of enum forward decl from decl context

2018-05-16 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 147130.
jdenny retitled this revision from "[Attr] Fix printing attrs for enum forward 
decl at file scope" to "[Attr] Fix loss of enum forward decl from decl context".
jdenny edited the summary of this revision.
jdenny added a comment.

Made the suggested change.  Thanks!


https://reviews.llvm.org/D46846

Files:
  lib/Sema/SemaDecl.cpp
  test/Sema/ast-print.c
  test/SemaCXX/MicrosoftCompatibility.cpp


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -239,6 +239,15 @@
ENUM2_c = 0x1 // expected-warning {{enumerator value is not 
representable in the underlying type 'int'}}
 };
 
+namespace NsEnumForwardDecl {
+  enum E *p; // expected-warning {{forward references to 'enum' types are a 
Microsoft extension}}
+  extern E e;
+}
+// Clang used to complain that NsEnumForwardDecl::E was undeclared below.
+NsEnumForwardDecl::E NsEnumForwardDecl_e;
+namespace NsEnumForwardDecl {
+  extern E e;
+}
 
 namespace PR11791 {
   template
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field 
designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been 
explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is 
deprecated}}"
+// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been 
explicitly marked deprecated here}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been 
explicitly marked deprecated here}}"
 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
@@ -86,8 +88,7 @@
   // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note 
{{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
-// FIXME: If enum is forward-declared at file scope, attributes are lost.
-// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
+// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 
*EnumWithAttributes2Ptr;
 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked 
deprecated here}}
 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14343,7 +14343,6 @@
   // PrevDecl.
   TagDecl *New;
 
-  bool IsForwardReference = false;
   if (Kind == TTK_Enum) {
 // FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
 // enum X { A, B, C } D;D should chain to X.
@@ -14373,12 +14372,6 @@
 else if (getLangOpts().CPlusPlus)
   DiagID = diag::err_forward_ref_enum;
 Diag(Loc, DiagID);
-
-// If this is a forward-declared reference to an enumeration, make a
-// note of it; we won't actually be introducing the declaration into
-// the declaration context.
-if (TUK == TUK_Reference)
-  IsForwardReference = true;
   }
 }
 
@@ -14536,9 +14529,7 @@
 PushOnScopeChains(New, EnclosingScope, /* AddToContext = */ false);
   } else if (Name) {
 S = getNonFieldDeclScope(S);
-PushOnScopeChains(New, S, !IsForwardReference);
-if (IsForwardReference)
-  SearchDC->makeDeclVisibleInContext(New);
+PushOnScopeChains(New, S, true);
   } else {
 CurContext->addDecl(New);
   }


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -239,6 +239,15 @@
 	ENUM2_c = 0x1 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
 };
 
+namespace NsEnumForwardDecl {
+  enum E *p; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
+  extern E e;
+}
+// Clang used to complain that NsEnumForwardDecl::E was undeclared below.
+NsEnumForwardDecl::E NsEnumForwardDecl_e;
+namespace NsEnumForwardDecl {
+  extern E e;
+}
 
 namespace PR11791 {
   template
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is depre

[PATCH] D46919: [libclang] Deprecate CXPrintingPolicy_IncludeTagDefinition

2018-05-21 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 147887.
jdenny marked 2 inline comments as done.
jdenny edited the summary of this revision.
jdenny added a comment.

Made a stab at the suggested changes.


https://reviews.llvm.org/D46919

Files:
  include/clang-c/Index.h
  include/clang/AST/PrettyPrinter.h
  lib/AST/DeclPrinter.cpp
  lib/AST/TypePrinter.cpp
  tools/c-index-test/c-index-test.c

Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -99,8 +99,6 @@
CXPrintingPolicy_SuppressSpecifiers},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSTAGKEYWORD",
CXPrintingPolicy_SuppressTagKeyword},
-  {"CINDEXTEST_PRINTINGPOLICY_INCLUDETAGDEFINITION",
-   CXPrintingPolicy_IncludeTagDefinition},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSSCOPE",
CXPrintingPolicy_SuppressScope},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSUNWRITTENSCOPE",
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -454,7 +454,7 @@
 OS << '(';
 
   PrintingPolicy InnerPolicy(Policy);
-  InnerPolicy.IncludeTagDefinition = false;
+  InnerPolicy.State.PrintOwnedTagDecl = false;
   TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
 
   OS << "::*";
@@ -1054,9 +1054,9 @@
 }
 
 void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition) {
+  if (Policy.State.PrintOwnedTagDecl) {
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.State.PrintOwnedTagDecl = false;
 D->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
@@ -1209,35 +1209,34 @@
 
 void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl()) {
+  if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl()) {
 TagDecl *OwnedTagDecl = T->getOwnedTagDecl();
 assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() &&
"OwnedTagDecl expected to be a declaration for the type");
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.State.PrintOwnedTagDecl = false;
 OwnedTagDecl->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
   }
 
   // The tag definition will take care of these.
-  if (!Policy.IncludeTagDefinition)
-  {
+  if (!Policy.State.PrintOwnedTagDecl) {
 OS << TypeWithKeyword::getKeywordName(T->getKeyword());
 if (T->getKeyword() != ETK_None)
   OS << " ";
 NestedNameSpecifier *Qualifier = T->getQualifier();
 if (Qualifier)
   Qualifier->print(OS, Policy);
   }
-  
+
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printBefore(T->getNamedType(), OS);
 }
 
 void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl())
+  if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl())
 return;
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printAfter(T->getNamedType(), OS);
Index: lib/AST/DeclPrinter.cpp
===
--- lib/AST/DeclPrinter.cpp
+++ lib/AST/DeclPrinter.cpp
@@ -178,12 +178,12 @@
   for ( ; Begin != End; ++Begin) {
 if (isFirst) {
   if(TD)
-SubPolicy.IncludeTagDefinition = true;
+SubPolicy.State.PrintOwnedTagDecl = true;
   SubPolicy.SuppressSpecifiers = false;
   isFirst = false;
 } else {
   if (!isFirst) Out << ", ";
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.State.PrintOwnedTagDecl = false;
   SubPolicy.SuppressSpecifiers = true;
 }
 
@@ -849,7 +849,7 @@
   }
   PrintingPolicy SubPolicy(Policy);
   SubPolicy.SuppressSpecifiers = false;
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.State.PrintOwnedTagDecl = false;
   Init->printPretty(Out, nullptr, SubPolicy, Indentation);
   if ((D->getInitStyle() == VarDecl::CallInit) && !isa(Init))
 Out << ")";
Index: include/clang/AST/PrettyPrinter.h
===
--- include/clang/AST/PrettyPrinter.h
+++ include/clang/AST/PrettyPrinter.h
@@ -93,14 +93,7 @@
   /// \endcode
   bool SuppressTagKeyword : 1;
 
-  /// When true, include the body of a tag definition.
-  ///
-  /// This is used to place the definition of a struct
-  /// in the middle of another declaration as with:
-  ///
-  /// \code
-  /// typedef struct { int x, y; } Point;
-  /// \endcode
+  /// This flag is deprecated and no longer has any effect.
   bool IncludeTagDefinition : 1;
 
   /// Suppresses printing of scope specifiers.
@@ -225,6 +218,25 @@
   /// Whe

[PATCH] D46919: [libclang] Deprecate CXPrintingPolicy_IncludeTagDefinition

2018-05-21 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D46919#1101268, @jdenny wrote:

> In https://reviews.llvm.org/D46919#1100493, @rsmith wrote:
>
> > The deprecated enumerator is also referenced by 
> > `tools/c-index-test/c-index-test.c`
>
>
> This test prompted me to keep the IncludeTagDefinition member in 
> PrintingPolicy so that clang_PrintingPolicy_getProperty would return the 
> previous value set by clang_PrintingPolicy_setProperty.  Otherwise, the value 
> doesn't have any effect.  Is that self-consistency not worth worrying about?  
> If so, I'll remove both.


Sorry, I was thinking of a different test.  I've removed the reference you 
mentioned.




Comment at: include/clang/AST/PrettyPrinter.h:97-99
+  /// This flag is deprecated and no longer has any effect.
+  bool IncludeTagDefinition : 1;
+

rsmith wrote:
> There's no need to keep this around. We have no API stability guarantees for 
> our C++ API.
The test LibclangPrintingPolicyTest in unittests/libclang/LibclangTest.cpp 
wants  clang_PrintingPolicy_getProperty to return the previous value set by 
clang_PrintingPolicy_setProperty for every member of CXPrintingPolicyProperty.  
Keeping this field makes that possible.


https://reviews.llvm.org/D46919



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


[PATCH] D46919: [libclang] Deprecate CXPrintingPolicy_IncludeTagDefinition

2018-05-21 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D46919#1107296, @rsmith wrote:

> In https://reviews.llvm.org/D46919#1101268, @jdenny wrote:
>
> > In https://reviews.llvm.org/D46919#1100493, @rsmith wrote:
> >
> > > The deprecated enumerator is also referenced by 
> > > `tools/c-index-test/c-index-test.c`
> >
> >
> > This test prompted me to keep the IncludeTagDefinition member in 
> > PrintingPolicy so that clang_PrintingPolicy_getProperty would return the 
> > previous value set by clang_PrintingPolicy_setProperty.  Otherwise, the 
> > value doesn't have any effect.  Is that self-consistency not worth worrying 
> > about?  If so, I'll remove both.
>
>
> I don't think it's worth worrying about. We don't guarantee that the values 
> round-trip in general (most of them are `unsigned`s being written to a 
> `bool`, so we don't preserve values that are neither 0 nor 1).


I was actually thinking of a different test (see my comments from today), and 
it wants 0 and 1 to be preserved.


https://reviews.llvm.org/D46919



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


[PATCH] D46846: [AST] Fix loss of enum forward decl from decl context

2018-05-29 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 149021.
jdenny added a comment.

Rebased.  Ping.


https://reviews.llvm.org/D46846

Files:
  lib/Sema/SemaDecl.cpp
  test/Sema/ast-print.c
  test/SemaCXX/MicrosoftCompatibility.cpp


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -239,6 +239,15 @@
ENUM2_c = 0x1 // expected-warning {{enumerator value is not 
representable in the underlying type 'int'}}
 };
 
+namespace NsEnumForwardDecl {
+  enum E *p; // expected-warning {{forward references to 'enum' types are a 
Microsoft extension}}
+  extern E e;
+}
+// Clang used to complain that NsEnumForwardDecl::E was undeclared below.
+NsEnumForwardDecl::E NsEnumForwardDecl_e;
+namespace NsEnumForwardDecl {
+  extern E e;
+}
 
 namespace PR11791 {
   template
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field 
designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been 
explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is 
deprecated}}"
+// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been 
explicitly marked deprecated here}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been 
explicitly marked deprecated here}}"
 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
@@ -86,8 +88,7 @@
   // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note 
{{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
-// FIXME: If enum is forward-declared at file scope, attributes are lost.
-// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
+// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 
*EnumWithAttributes2Ptr;
 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked 
deprecated here}}
 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14280,7 +14280,6 @@
   // PrevDecl.
   TagDecl *New;
 
-  bool IsForwardReference = false;
   if (Kind == TTK_Enum) {
 // FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
 // enum X { A, B, C } D;D should chain to X.
@@ -14310,12 +14309,6 @@
 else if (getLangOpts().CPlusPlus)
   DiagID = diag::err_forward_ref_enum;
 Diag(Loc, DiagID);
-
-// If this is a forward-declared reference to an enumeration, make a
-// note of it; we won't actually be introducing the declaration into
-// the declaration context.
-if (TUK == TUK_Reference)
-  IsForwardReference = true;
   }
 }
 
@@ -14473,9 +14466,7 @@
 PushOnScopeChains(New, EnclosingScope, /* AddToContext = */ false);
   } else if (Name) {
 S = getNonFieldDeclScope(S);
-PushOnScopeChains(New, S, !IsForwardReference);
-if (IsForwardReference)
-  SearchDC->makeDeclVisibleInContext(New);
+PushOnScopeChains(New, S, true);
   } else {
 CurContext->addDecl(New);
   }


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -239,6 +239,15 @@
 	ENUM2_c = 0x1 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
 };
 
+namespace NsEnumForwardDecl {
+  enum E *p; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
+  extern E e;
+}
+// Clang used to complain that NsEnumForwardDecl::E was undeclared below.
+NsEnumForwardDecl::E NsEnumForwardDecl_e;
+namespace NsEnumForwardDecl {
+  extern E e;
+}
 
 namespace PR11791 {
   template
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is deprecated}}"
+// RUN: echo >

[PATCH] D46919: [libclang] Deprecate CXPrintingPolicy_IncludeTagDefinition

2018-07-20 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 156620.
jdenny added a comment.

Ping.  Rebased.


https://reviews.llvm.org/D46919

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/PrettyPrinter.h
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/tools/c-index-test/c-index-test.c

Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -99,8 +99,6 @@
CXPrintingPolicy_SuppressSpecifiers},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSTAGKEYWORD",
CXPrintingPolicy_SuppressTagKeyword},
-  {"CINDEXTEST_PRINTINGPOLICY_INCLUDETAGDEFINITION",
-   CXPrintingPolicy_IncludeTagDefinition},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSSCOPE",
CXPrintingPolicy_SuppressScope},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSUNWRITTENSCOPE",
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -455,7 +455,7 @@
 OS << '(';
 
   PrintingPolicy InnerPolicy(Policy);
-  InnerPolicy.IncludeTagDefinition = false;
+  InnerPolicy.State.PrintOwnedTagDecl = false;
   TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
 
   OS << "::*";
@@ -1103,9 +1103,9 @@
 }
 
 void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition) {
+  if (Policy.State.PrintOwnedTagDecl) {
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.State.PrintOwnedTagDecl = false;
 D->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
@@ -1258,35 +1258,34 @@
 
 void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl()) {
+  if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl()) {
 TagDecl *OwnedTagDecl = T->getOwnedTagDecl();
 assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() &&
"OwnedTagDecl expected to be a declaration for the type");
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.State.PrintOwnedTagDecl = false;
 OwnedTagDecl->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
   }
 
   // The tag definition will take care of these.
-  if (!Policy.IncludeTagDefinition)
-  {
+  if (!Policy.State.PrintOwnedTagDecl) {
 OS << TypeWithKeyword::getKeywordName(T->getKeyword());
 if (T->getKeyword() != ETK_None)
   OS << " ";
 NestedNameSpecifier *Qualifier = T->getQualifier();
 if (Qualifier)
   Qualifier->print(OS, Policy);
   }
-  
+
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printBefore(T->getNamedType(), OS);
 }
 
 void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl())
+  if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl())
 return;
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printAfter(T->getNamedType(), OS);
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -178,12 +178,12 @@
   for ( ; Begin != End; ++Begin) {
 if (isFirst) {
   if(TD)
-SubPolicy.IncludeTagDefinition = true;
+SubPolicy.State.PrintOwnedTagDecl = true;
   SubPolicy.SuppressSpecifiers = false;
   isFirst = false;
 } else {
   if (!isFirst) Out << ", ";
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.State.PrintOwnedTagDecl = false;
   SubPolicy.SuppressSpecifiers = true;
 }
 
@@ -849,7 +849,7 @@
   }
   PrintingPolicy SubPolicy(Policy);
   SubPolicy.SuppressSpecifiers = false;
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.State.PrintOwnedTagDecl = false;
   Init->printPretty(Out, nullptr, SubPolicy, Indentation);
   if ((D->getInitStyle() == VarDecl::CallInit) && !isa(Init))
 Out << ")";
Index: clang/include/clang/AST/PrettyPrinter.h
===
--- clang/include/clang/AST/PrettyPrinter.h
+++ clang/include/clang/AST/PrettyPrinter.h
@@ -93,14 +93,7 @@
   /// \endcode
   bool SuppressTagKeyword : 1;
 
-  /// When true, include the body of a tag definition.
-  ///
-  /// This is used to place the definition of a struct
-  /// in the middle of another declaration as with:
-  ///
-  /// \code
-  /// typedef struct { int x, y; } Point;
-  /// \endcode
+  /// This flag is deprecated and no longer has any effect.
   bool IncludeTagDefinition : 1;
 
   /// Suppresses printing of scope specifiers.
@@ -225,6 +218,25 @@
   /// When tru

[PATCH] D43204: [OpenMP] Fix trailing space when printing pragmas

2018-02-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: ABataev.
Herald added a subscriber: guansong.

-ast-print prints omp pragmas with a trailing space.  While this
behavior is likely of little concern to most users, surely it's
unintentional, and it's annoying for some source-level work I'm 
pursuing.  This patch focuses on omp pragmas, but it also fixes
init_seg and loop hint pragmas because they share implementation.

The testing strategy here is to add usually just one '{{$}}' per 
relevant -ast-print test file.  This seems to achieve good code
coverage.  However, this strategy is probably easy to forget as the 
tests evolve.  That's probably fine as this fix is far from critical.
The main goal of the testing is to aid the initial review.

This patch also adds a fixme for "#pragma unroll", which prints as
"#pragma unroll (enable)", which is invalid syntax.


https://reviews.llvm.org/D43204

Files:
  include/clang/Basic/Attr.td
  lib/AST/StmtPrinter.cpp
  test/Misc/ast-print-pragmas.cpp
  test/OpenMP/atomic_ast_print.cpp
  test/OpenMP/barrier_ast_print.cpp
  test/OpenMP/cancel_ast_print.cpp
  test/OpenMP/cancellation_point_ast_print.cpp
  test/OpenMP/critical_ast_print.cpp
  test/OpenMP/declare_reduction_ast_print.c
  test/OpenMP/declare_reduction_ast_print.cpp
  test/OpenMP/declare_simd_ast_print.c
  test/OpenMP/declare_simd_ast_print.cpp
  test/OpenMP/declare_target_ast_print.cpp
  test/OpenMP/distribute_ast_print.cpp
  test/OpenMP/distribute_dist_schedule_ast_print.cpp
  test/OpenMP/distribute_parallel_for_ast_print.cpp
  test/OpenMP/distribute_parallel_for_simd_ast_print.cpp
  test/OpenMP/distribute_simd_ast_print.cpp
  test/OpenMP/flush_ast_print.cpp
  test/OpenMP/for_ast_print.cpp
  test/OpenMP/for_simd_ast_print.cpp
  test/OpenMP/master_ast_print.cpp
  test/OpenMP/ordered_ast_print.cpp
  test/OpenMP/parallel_ast_print.cpp
  test/OpenMP/parallel_for_ast_print.cpp
  test/OpenMP/parallel_for_simd_ast_print.cpp
  test/OpenMP/parallel_sections_ast_print.cpp
  test/OpenMP/sections_ast_print.cpp
  test/OpenMP/simd_ast_print.cpp
  test/OpenMP/single_ast_print.cpp
  test/OpenMP/target_ast_print.cpp
  test/OpenMP/target_data_ast_print.cpp
  test/OpenMP/target_data_use_device_ptr_ast_print.cpp
  test/OpenMP/target_enter_data_ast_print.cpp
  test/OpenMP/target_exit_data_ast_print.cpp
  test/OpenMP/target_is_device_ptr_ast_print.cpp
  test/OpenMP/target_parallel_ast_print.cpp
  test/OpenMP/target_parallel_for_ast_print.cpp
  test/OpenMP/target_parallel_for_is_device_ptr_ast_print.cpp
  test/OpenMP/target_parallel_for_simd_ast_print.cpp
  test/OpenMP/target_parallel_for_simd_is_device_ptr_ast_print.cpp
  test/OpenMP/target_parallel_is_device_ptr_ast_print.cpp
  test/OpenMP/target_simd_ast_print.cpp
  test/OpenMP/target_teams_ast_print.cpp
  test/OpenMP/target_teams_distribute_ast_print.cpp
  test/OpenMP/target_teams_distribute_parallel_for_ast_print.cpp
  test/OpenMP/target_teams_distribute_parallel_for_is_device_ptr_ast_print.cpp
  test/OpenMP/target_teams_distribute_parallel_for_simd_ast_print.cpp
  
test/OpenMP/target_teams_distribute_parallel_for_simd_is_device_ptr_ast_print.cpp
  test/OpenMP/target_teams_distribute_simd_ast_print.cpp
  test/OpenMP/target_teams_distribute_simd_is_device_ptr_ast_print.cpp
  test/OpenMP/target_teams_is_device_ptr_ast_print.cpp
  test/OpenMP/target_update_ast_print.cpp
  test/OpenMP/task_ast_print.cpp
  test/OpenMP/taskgroup_ast_print.cpp
  test/OpenMP/taskloop_ast_print.cpp
  test/OpenMP/taskloop_simd_ast_print.cpp
  test/OpenMP/taskwait_ast_print.cpp
  test/OpenMP/taskyield_ast_print.cpp
  test/OpenMP/teams_ast_print.cpp
  test/OpenMP/teams_distribute_ast_print.cpp
  test/OpenMP/teams_distribute_parallel_for_ast_print.cpp
  test/OpenMP/teams_distribute_parallel_for_simd_ast_print.cpp
  test/OpenMP/teams_distribute_simd_ast_print.cpp
  test/OpenMP/threadprivate_ast_print.cpp
  test/PCH/pragma-loop.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -1368,7 +1368,7 @@
   "OS << \"" << Prefix << Spelling;
 
 if (Variety == "Pragma") {
-  OS << " \";\n";
+  OS << "\";\n";
   OS << "printPrettyPragma(OS, Policy);\n";
   OS << "OS << \"\\n\";";
   OS << "break;\n";
Index: test/PCH/pragma-loop.cpp
===
--- test/PCH/pragma-loop.cpp
+++ test/PCH/pragma-loop.cpp
@@ -4,7 +4,7 @@
 // FIXME: A bug in ParsedAttributes causes the order of the attributes to be
 // reversed. The checks are consequently in the reverse order below.
 
-// CHECK: #pragma clang loop unroll_count(16)
+// CHECK: #pragma clang loop unroll_count(16){{$}}
 // CHECK: #pragma clang loop interleave_count(8)
 // CHECK: #pragma clang loop vectorize_width(4)
 // CHECK: #pragma clang loop distribute(enable)
@@ -15,9 +15,10 @@
 // CHECK

[PATCH] D43248: [Attr] Fix printing of parameter indices in attributes

2018-02-13 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: aaron.ballman, hfinkel.

Parameter indices in some attributes (argument_with_type_tag,
pointer_with_type_tag, nonnull, ownership_takes, ownership_holds, and 
ownership_returns) are specified in source as one-origin including any 
this parameter, are stored as zero-origin excluding any this
parameter, and were erroneously printing (-ast-print) as the stored
values.  This patch fixes those cases by printing re-incremented
values.

An alternative solution is to store only the original values, but that
requires modifying all users.  I tried that for nonnull and found that
it required repeating index adjustment logic in many places while this
patch encapsulates that logic in relatively few places.

Another alternative is to store both sets of values, but that would be
less efficient.

This patch also fixes argument_with_type_tag and pointer_with_type_tag
not to print their fake IsPointer arguments.


https://reviews.llvm.org/D43248

Files:
  include/clang/Basic/Attr.td
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-print.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -738,6 +738,42 @@
 }
   };
 
+  class VariadicParamIndexArgument : public VariadicArgument {
+std::string DisallowImplicitThisParamName;
+
+  protected:
+// Assumed to receive a parameter: raw_ostream OS.
+virtual void writeValueImpl(raw_ostream &OS) const {
+  OS << "OS << (Val + 1";
+  if (!DisallowImplicitThisParamName.empty())
+OS << " + get" << DisallowImplicitThisParamName << "()";
+  OS << ");\n";
+}
+  public:
+VariadicParamIndexArgument(const Record &Arg, StringRef Attr)
+: VariadicArgument(Arg, Attr, "unsigned"),
+  DisallowImplicitThisParamName(
+  Arg.getValueAsString("DisallowImplicitThisParamName")) {}
+  };
+
+  class ParamIndexArgument : public SimpleArgument {
+std::string DisallowImplicitThisParamName;
+
+  protected:
+void writeValue(raw_ostream &OS) const override {
+  OS << "\" << (get" << getUpperName() << "() + 1";
+  if (!DisallowImplicitThisParamName.empty())
+OS << " + get" << DisallowImplicitThisParamName << "()";
+  OS << ") << \"";
+}
+
+  public:
+ParamIndexArgument(const Record &Arg, StringRef Attr)
+: SimpleArgument(Arg, Attr, "unsigned"),
+  DisallowImplicitThisParamName(
+  Arg.getValueAsString("DisallowImplicitThisParamName")) {}
+  };
+
   // Unique the enums, but maintain the original declaration ordering.
   std::vector
   uniqueEnumsInOrder(const std::vector &enums) {
@@ -1237,6 +1273,10 @@
 Ptr = llvm::make_unique(Arg, Attr);
   else if (ArgName == "VariadicExprArgument")
 Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "VariadicParamIndexArgument")
+Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "ParamIndexArgument")
+Ptr = llvm::make_unique(Arg, Attr);
   else if (ArgName == "VersionArgument")
 Ptr = llvm::make_unique(Arg, Attr);
 
Index: test/Sema/attr-print.cpp
===
--- /dev/null
+++ test/Sema/attr-print.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 %s -ast-print | FileCheck %s
+
+void awtt(int, int, ...) __attribute__((argument_with_type_tag(foo, 3, 2)));
+// CHECK: void awtt(int, int, ...) __attribute__((argument_with_type_tag(foo, 3, 2)));
+void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 1, 2)));
+// CHECK: void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 1, 2)));
+
+void nn(int *, int *) __attribute__((nonnull(1, 2)));
+// CHECK: void nn(int *, int *) __attribute__((nonnull(1, 2)));
+
+void ownt(int *, int *) __attribute__((ownership_takes(foo, 1, 2)));
+// CHECK: void ownt(int *, int *) __attribute__((ownership_takes(foo, 1, 2)));
+void ownh(int *, int *) __attribute__((ownership_holds(foo, 1, 2)));
+// CHECK: void ownh(int *, int *) __attribute__((ownership_holds(foo, 1, 2)));
+void ownr(int) __attribute__((ownership_returns(foo, 1)));
+// CHECK: void ownr(int) __attribute__((ownership_returns(foo, 1)));
+
+class C {
+  void awtt(int, int, ...) __attribute__((argument_with_type_tag(foo, 4, 3)));
+  // CHECK: void awtt(int, int, ...) __attribute__((argument_with_type_tag(foo, 4, 3)));
+  void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 2, 3)));
+  // CHECK: void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 2, 3)));
+
+  void nn(int *, int *) __attribute__((nonnull(2, 3)));
+  // CHECK: void nn(int *, int *) __attribute__((nonnull(2, 3)));
+
+  void ownt(int *, int *) __attribute__((ownership_takes(foo, 2, 3)));
+  // CHECK: void ownt(int *, int *) __attribute__((ownership_takes(foo, 2, 3)));
+  void ownh(int *, int *) __attribute__((ownership_holds(foo, 2, 3)));
+

[PATCH] D43204: [OpenMP] Fix trailing space when printing pragmas

2018-02-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43204#1007502, @ABataev wrote:

> LG


Alexey: Thanks for accepting. I do not have commit privileges. Would
you please commit for me?


https://reviews.llvm.org/D43204



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


[PATCH] D43248: [Attr] Fix printing of parameter indices in attributes

2018-02-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: include/clang/Basic/Attr.td:182
+  // it would always be false.
+  string DisallowImplicitThisParamName = disallowImplicitThisParamName;
+}

aaron.ballman wrote:
> Is there much benefit to forcing the attribute author to pick a name for 
> this? It seems like this is more of a Boolean value: either implicit this is 
> allowed or not. It would be really nice if we could hide these mechanics as 
> implementation details so that the user only needs to write 
> `VariadicParamIndexArgument<"name", DisallowImplicitThis>` (or something 
> similar) when defining the attribute, and ideally not have to do any extra 
> work in SemaDeclAttr.cpp by taking care of it in ClangAttrEmitter.cpp if 
> possible.
Thanks for the review.  I'll work on that.



Comment at: lib/Sema/SemaDeclAttr.cpp:355-357
   }
+  else if (DisallowImplicitThisParam)
+*DisallowImplicitThisParam = false;

aaron.ballman wrote:
> Formatting is off here -- the `else if` should go up a line.
I don't follow.  It looks right to me. 



Comment at: lib/Sema/SemaDeclAttr.cpp:4612
+   TypeTagIdx, false,
+   &DisallowImplicitThisParam))
 return;

aaron.ballman wrote:
> This value cannot be different from the previously-read value, correct? Might 
> want to assert that.
Right.  Hopefully this will go away after I apply your initial suggestion.



Comment at: test/Sema/attr-print.cpp:1
+// RUN: %clang_cc1 %s -ast-print | FileCheck %s
+

aaron.ballman wrote:
> -ast-print tests generally live in Misc rather than Sema -- can you move this 
> test over to that directory?
Sure.  Should the existing test/Sema/attr-print.c move too?



Comment at: test/Sema/attr-print.cpp:33
+  // CHECK: void ownr(int) __attribute__((ownership_returns(foo, 2)));
+};

aaron.ballman wrote:
> Can you add some tests for `__attribute__((format))` and 
> `__attribute__((format_arg))` to demonstrate that their pretty-printed 
> argument values are also sensible?
Will look into it.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix printing of parameter indices in attributes

2018-02-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny marked 3 inline comments as done.
jdenny added a comment.






Comment at: include/clang/Basic/Attr.td:182
+  // it would always be false.
+  string DisallowImplicitThisParamName = disallowImplicitThisParamName;
+}

jdenny wrote:
> aaron.ballman wrote:
> > Is there much benefit to forcing the attribute author to pick a name for 
> > this? It seems like this is more of a Boolean value: either implicit this 
> > is allowed or not. It would be really nice if we could hide these mechanics 
> > as implementation details so that the user only needs to write 
> > `VariadicParamIndexArgument<"name", DisallowImplicitThis>` (or something 
> > similar) when defining the attribute, and ideally not have to do any extra 
> > work in SemaDeclAttr.cpp by taking care of it in ClangAttrEmitter.cpp if 
> > possible.
> Thanks for the review.  I'll work on that.
> Is there much benefit to forcing the attribute author to pick a name for 
> this? It seems like this is more of a Boolean value: either implicit this is 
> allowed or not.

If the attribute author picks the name, then the attribute author can ensure 
there's only one of these per attribute.  I could rewrite it to have one per 
VariadicParamIndexArgument and one per ParamIndexArgument if you like.  In that 
case, ArgumentWithTypeTagAttr would end up with two of these, and future 
attributes could potentially have more, but they should all have the same value 
within a single attribute.  I didn't investigate how that redundancy would 
actually impact memory usage.  What do you think?

>  It would be really nice if we could hide these mechanics as implementation 
> details so that the user only needs to write 
> VariadicParamIndexArgument<"name", DisallowImplicitThis> (or something 
> similar) when defining the attribute, and ideally not have to do any extra 
> work in SemaDeclAttr.cpp by taking care of it in ClangAttrEmitter.cpp if 
> possible.

So far, I haven't found a good way to accomplish that, or maybe I've 
misunderstood you

The logic of checkFunctionOrMethodParameterIndex in SemaDeclAttr.cpp seems 
pretty tightly coupled with its users' logic.  For example, handleNonNullAttr 
uses the indices as adjusted by checkFunctionOrMethodParameterIndex to 
determine which indices belong in the array to be passed to the NonNullAttr 
constructor.  We could try to have NonNullAttr (in the constructor, presumably) 
perform the adjustment of indices so that SemaDeclAttr.cpp doesn't need that 
logic, but then it would be too late to for handleNonNullAttr to filter them.

The only extra work this patch adds to SemaDeclAttr.cpp beyond what's already 
there is to reuse the DisallowImplicitThis that is essentially already computed 
in checkFunctionOrMethodParameterIndex.

Another possibility is to have SemaDeclAttr.cpp fully encapsulate the index 
adjustment logic and pass an index offset to attribute constructors, so 
ClangAttrEmitter.cpp would just know it has to print indices with some given 
offset.  But a general index offset is wider than the single bool being stored 
now.  Again, I haven't investigated the actual impact on memory usage.

Do you see a better way to achieve the encapsulation you're looking for?





Comment at: lib/Sema/SemaDeclAttr.cpp:355-357
   }
+  else if (DisallowImplicitThisParam)
+*DisallowImplicitThisParam = false;

aaron.ballman wrote:
> jdenny wrote:
> > aaron.ballman wrote:
> > > Formatting is off here -- the `else if` should go up a line.
> > I don't follow.  It looks right to me. 
> Our coding standard is to write:
> ```
> if (foo) {
> } else if (bar) {
> }
> ```
> rather than
> ```
> if (foo) {
> }
> else if (bar) {
> }
> ```
> One good way to catch this sort of thing is to run your patch through 
> clang-format: 
> https://clang.llvm.org/docs/ClangFormat.html#script-for-patch-reformatting
Thanks.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix printing of parameter indices in attributes

2018-02-16 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: include/clang/Basic/Attr.td:182
+  // it would always be false.
+  string DisallowImplicitThisParamName = disallowImplicitThisParamName;
+}

aaron.ballman wrote:
> jdenny wrote:
> > jdenny wrote:
> > > aaron.ballman wrote:
> > > > Is there much benefit to forcing the attribute author to pick a name 
> > > > for this? It seems like this is more of a Boolean value: either 
> > > > implicit this is allowed or not. It would be really nice if we could 
> > > > hide these mechanics as implementation details so that the user only 
> > > > needs to write `VariadicParamIndexArgument<"name", 
> > > > DisallowImplicitThis>` (or something similar) when defining the 
> > > > attribute, and ideally not have to do any extra work in 
> > > > SemaDeclAttr.cpp by taking care of it in ClangAttrEmitter.cpp if 
> > > > possible.
> > > Thanks for the review.  I'll work on that.
> > > Is there much benefit to forcing the attribute author to pick a name for 
> > > this? It seems like this is more of a Boolean value: either implicit this 
> > > is allowed or not.
> > 
> > If the attribute author picks the name, then the attribute author can 
> > ensure there's only one of these per attribute.  I could rewrite it to have 
> > one per VariadicParamIndexArgument and one per ParamIndexArgument if you 
> > like.  In that case, ArgumentWithTypeTagAttr would end up with two of 
> > these, and future attributes could potentially have more, but they should 
> > all have the same value within a single attribute.  I didn't investigate 
> > how that redundancy would actually impact memory usage.  What do you think?
> > 
> > >  It would be really nice if we could hide these mechanics as 
> > > implementation details so that the user only needs to write 
> > > VariadicParamIndexArgument<"name", DisallowImplicitThis> (or something 
> > > similar) when defining the attribute, and ideally not have to do any 
> > > extra work in SemaDeclAttr.cpp by taking care of it in 
> > > ClangAttrEmitter.cpp if possible.
> > 
> > So far, I haven't found a good way to accomplish that, or maybe I've 
> > misunderstood you
> > 
> > The logic of checkFunctionOrMethodParameterIndex in SemaDeclAttr.cpp seems 
> > pretty tightly coupled with its users' logic.  For example, 
> > handleNonNullAttr uses the indices as adjusted by 
> > checkFunctionOrMethodParameterIndex to determine which indices belong in 
> > the array to be passed to the NonNullAttr constructor.  We could try to 
> > have NonNullAttr (in the constructor, presumably) perform the adjustment of 
> > indices so that SemaDeclAttr.cpp doesn't need that logic, but then it would 
> > be too late to for handleNonNullAttr to filter them.
> > 
> > The only extra work this patch adds to SemaDeclAttr.cpp beyond what's 
> > already there is to reuse the DisallowImplicitThis that is essentially 
> > already computed in checkFunctionOrMethodParameterIndex.
> > 
> > Another possibility is to have SemaDeclAttr.cpp fully encapsulate the index 
> > adjustment logic and pass an index offset to attribute constructors, so 
> > ClangAttrEmitter.cpp would just know it has to print indices with some 
> > given offset.  But a general index offset is wider than the single bool 
> > being stored now.  Again, I haven't investigated the actual impact on 
> > memory usage.
> > 
> > Do you see a better way to achieve the encapsulation you're looking for?
> > 
> > 
> > In that case, ArgumentWithTypeTagAttr would end up with two of these, and 
> > future attributes could potentially have more, but they should all have the 
> > same value within a single attribute. I didn't investigate how that 
> > redundancy would actually impact memory usage. What do you think?
> 
> That redundancy could probably be worked around in ClangAttrEmitter.cpp by 
> inspecting the attribute argument list and noticing duplicate 
> `[Variadic]ParamIndexArgument` before generating the code for the arguments, 
> perhaps?
> 
> > Another possibility is to have SemaDeclAttr.cpp fully encapsulate the index 
> > adjustment logic and pass an index offset to attribute constructors, so 
> > ClangAttrEmitter.cpp would just know it has to print indices with some 
> > given offset.
> 
> This was more along the lines of what I was thinking of.
> 
> Basically, it seems like the declarative part in Attr.td should be able to 
> specify an attribute argument is intended to be a function parameter 
> positional index, and whether implicit this needs special handling or not. 
> Past that, the semantics of the attribute really shouldn't matter -- when 
> asking for the index, it should be automatically adjusted so that users of 
> the attribute don't have to do anything, and when printing the attribute, the 
> index should be appropriately adjusted back. I'd like to avoid needing 
> collusion between the declarative part in Attr.td and the semantic part in 
> SemaDeclAttr.cpp because that collusion 

[PATCH] D43248: [Attr] Fix printing of parameter indices in attributes

2018-02-16 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: include/clang/Basic/Attr.td:182
+  // it would always be false.
+  string DisallowImplicitThisParamName = disallowImplicitThisParamName;
+}

aaron.ballman wrote:
> jdenny wrote:
> > aaron.ballman wrote:
> > > jdenny wrote:
> > > > jdenny wrote:
> > > > > aaron.ballman wrote:
> > > > > > Is there much benefit to forcing the attribute author to pick a 
> > > > > > name for this? It seems like this is more of a Boolean value: 
> > > > > > either implicit this is allowed or not. It would be really nice if 
> > > > > > we could hide these mechanics as implementation details so that the 
> > > > > > user only needs to write `VariadicParamIndexArgument<"name", 
> > > > > > DisallowImplicitThis>` (or something similar) when defining the 
> > > > > > attribute, and ideally not have to do any extra work in 
> > > > > > SemaDeclAttr.cpp by taking care of it in ClangAttrEmitter.cpp if 
> > > > > > possible.
> > > > > Thanks for the review.  I'll work on that.
> > > > > Is there much benefit to forcing the attribute author to pick a name 
> > > > > for this? It seems like this is more of a Boolean value: either 
> > > > > implicit this is allowed or not.
> > > > 
> > > > If the attribute author picks the name, then the attribute author can 
> > > > ensure there's only one of these per attribute.  I could rewrite it to 
> > > > have one per VariadicParamIndexArgument and one per ParamIndexArgument 
> > > > if you like.  In that case, ArgumentWithTypeTagAttr would end up with 
> > > > two of these, and future attributes could potentially have more, but 
> > > > they should all have the same value within a single attribute.  I 
> > > > didn't investigate how that redundancy would actually impact memory 
> > > > usage.  What do you think?
> > > > 
> > > > >  It would be really nice if we could hide these mechanics as 
> > > > > implementation details so that the user only needs to write 
> > > > > VariadicParamIndexArgument<"name", DisallowImplicitThis> (or 
> > > > > something similar) when defining the attribute, and ideally not have 
> > > > > to do any extra work in SemaDeclAttr.cpp by taking care of it in 
> > > > > ClangAttrEmitter.cpp if possible.
> > > > 
> > > > So far, I haven't found a good way to accomplish that, or maybe I've 
> > > > misunderstood you
> > > > 
> > > > The logic of checkFunctionOrMethodParameterIndex in SemaDeclAttr.cpp 
> > > > seems pretty tightly coupled with its users' logic.  For example, 
> > > > handleNonNullAttr uses the indices as adjusted by 
> > > > checkFunctionOrMethodParameterIndex to determine which indices belong 
> > > > in the array to be passed to the NonNullAttr constructor.  We could try 
> > > > to have NonNullAttr (in the constructor, presumably) perform the 
> > > > adjustment of indices so that SemaDeclAttr.cpp doesn't need that logic, 
> > > > but then it would be too late to for handleNonNullAttr to filter them.
> > > > 
> > > > The only extra work this patch adds to SemaDeclAttr.cpp beyond what's 
> > > > already there is to reuse the DisallowImplicitThis that is essentially 
> > > > already computed in checkFunctionOrMethodParameterIndex.
> > > > 
> > > > Another possibility is to have SemaDeclAttr.cpp fully encapsulate the 
> > > > index adjustment logic and pass an index offset to attribute 
> > > > constructors, so ClangAttrEmitter.cpp would just know it has to print 
> > > > indices with some given offset.  But a general index offset is wider 
> > > > than the single bool being stored now.  Again, I haven't investigated 
> > > > the actual impact on memory usage.
> > > > 
> > > > Do you see a better way to achieve the encapsulation you're looking for?
> > > > 
> > > > 
> > > > In that case, ArgumentWithTypeTagAttr would end up with two of these, 
> > > > and future attributes could potentially have more, but they should all 
> > > > have the same value within a single attribute. I didn't investigate how 
> > > > that redundancy would actually impact memory usage. What do you think?
> > > 
> > > That redundancy could probably be worked around in ClangAttrEmitter.cpp 
> > > by inspecting the attribute argument list and noticing duplicate 
> > > `[Variadic]ParamIndexArgument` before generating the code for the 
> > > arguments, perhaps?
> > > 
> > > > Another possibility is to have SemaDeclAttr.cpp fully encapsulate the 
> > > > index adjustment logic and pass an index offset to attribute 
> > > > constructors, so ClangAttrEmitter.cpp would just know it has to print 
> > > > indices with some given offset.
> > > 
> > > This was more along the lines of what I was thinking of.
> > > 
> > > Basically, it seems like the declarative part in Attr.td should be able 
> > > to specify an attribute argument is intended to be a function parameter 
> > > positional index, and whether implicit this needs special handling or 
> > > not. Past that, the semantics of the attribute really shouldn't mat

[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: aaron.ballman.

https://reviews.llvm.org/D43747

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/warn-type-safety.c


Index: test/Sema/warn-type-safety.c
===
--- test/Sema/warn-type-safety.c
+++ test/Sema/warn-type-safety.c
@@ -37,6 +37,10 @@
 int wrong10(double buf, MPI_Datatype type)
 __attribute__(( pointer_with_type_tag(mpi,1,2) )); // expected-error 
{{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
+int ok11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,1,2) ));
+int wrong11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,2,3) )); // expected-error 
{{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
 extern struct A datatype_wrong1
 __attribute__(( type_tag_for_datatype )); // expected-error 
{{'type_tag_for_datatype' attribute requires parameter 1 to be an identifier}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4567,11 +4567,10 @@
   bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag";
   if (IsPointer) {
 // Ensure that buffer has a pointer type.
-QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
-if (!BufferTy->isPointerType()) {
+if (ArgumentIdx >= getFunctionOrMethodNumParams(D) ||
+!getFunctionOrMethodParamType(D, ArgumentIdx)->isPointerType())
   S.Diag(AL.getLoc(), diag::err_attribute_pointers_only)
-<< AL.getName() << 0;
-}
+  << AL.getName() << 0;
   }
 
   D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(


Index: test/Sema/warn-type-safety.c
===
--- test/Sema/warn-type-safety.c
+++ test/Sema/warn-type-safety.c
@@ -37,6 +37,10 @@
 int wrong10(double buf, MPI_Datatype type)
 __attribute__(( pointer_with_type_tag(mpi,1,2) )); // expected-error {{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
+int ok11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,1,2) ));
+int wrong11(void *, ...)
+__attribute__(( pointer_with_type_tag(mpi,2,3) )); // expected-error {{'pointer_with_type_tag' attribute only applies to pointer arguments}}
 
 extern struct A datatype_wrong1
 __attribute__(( type_tag_for_datatype )); // expected-error {{'type_tag_for_datatype' attribute requires parameter 1 to be an identifier}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4567,11 +4567,10 @@
   bool IsPointer = AL.getName()->getName() == "pointer_with_type_tag";
   if (IsPointer) {
 // Ensure that buffer has a pointer type.
-QualType BufferTy = getFunctionOrMethodParamType(D, ArgumentIdx);
-if (!BufferTy->isPointerType()) {
+if (ArgumentIdx >= getFunctionOrMethodNumParams(D) ||
+!getFunctionOrMethodParamType(D, ArgumentIdx)->isPointerType())
   S.Diag(AL.getLoc(), diag::err_attribute_pointers_only)
-<< AL.getName() << 0;
-}
+  << AL.getName() << 0;
   }
 
   D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: aaron.ballman.

The first FIXME introduced here will be addressed in another patch
soon.


https://reviews.llvm.org/D43748

Files:
  test/Misc/ast-print-objectivec.m
  test/Sema/attr-print.c
  test/Sema/attr-print.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -231,6 +231,7 @@
 virtual void writePCHReadArgs(raw_ostream &OS) const = 0;
 virtual void writePCHReadDecls(raw_ostream &OS) const = 0;
 virtual void writePCHWrite(raw_ostream &OS) const = 0;
+virtual std::string getIsOmitted() const { return "false"; }
 virtual void writeValue(raw_ostream &OS) const = 0;
 virtual void writeDump(raw_ostream &OS) const = 0;
 virtual void writeDumpChildren(raw_ostream &OS) const {}
@@ -298,23 +299,30 @@
std::string(getUpperName()) + "()");
 }
 
+std::string getIsOmitted() const override {
+  if (type == "FunctionDecl *")
+return "false";
+  if (type == "IdentifierInfo *")
+return "!get" + getUpperName().str() + "()";
+  if (type == "TypeSourceInfo *")
+return "false";
+  // FIXME: Do this declaratively in Attr.td.
+  if (getAttrName() == "AllocSize")
+return "0 == get" + getUpperName().str() + "()";
+  return "false";
+}
+
 void writeValue(raw_ostream &OS) const override {
-  if (type == "FunctionDecl *") {
-OS << "\" << get" << getUpperName()
-   << "()->getNameInfo().getAsString() << \"";
-  } else if (type == "IdentifierInfo *") {
-OS << "\";\n";
-if (isOptional())
-  OS << "if (get" << getUpperName() << "()) ";
-else
-  OS << "";
-OS << "OS << get" << getUpperName() << "()->getName();\n";
-OS << "OS << \"";
-  } else if (type == "TypeSourceInfo *") {
-OS << "\" << get" << getUpperName() << "().getAsString() << \"";
-  } else {
-OS << "\" << get" << getUpperName() << "() << \"";
-  }
+  StringRef Val;
+  if (type == "FunctionDecl *")
+Val = "->getNameInfo().getAsString()";
+  else if (type == "IdentifierInfo *")
+Val = "->getName()";
+  else if (type == "TypeSourceInfo *")
+Val = ".getAsString()";
+  else
+Val = "";
+  OS << "\" << get" << getUpperName() << "()" << Val << " << \"";
 }
 
 void writeDump(raw_ostream &OS) const override {
@@ -576,12 +584,15 @@
  << "Type());\n";
 }
 
+std::string getIsOmitted() const override {
+  return "!is" + getLowerName().str() + "Expr || !" + getLowerName().str()
+ + "Expr";
+}
+
 void writeValue(raw_ostream &OS) const override {
   OS << "\";\n";
-  // The aligned attribute argument expression is optional.
-  OS << "if (is" << getLowerName() << "Expr && "
- << getLowerName() << "Expr)\n";
-  OS << "  " << getLowerName() << "Expr->printPretty(OS, nullptr, Policy);\n";
+  OS << "" << getLowerName()
+ << "Expr->printPretty(OS, nullptr, Policy);\n";
   OS << "OS << \"";
 }
 
@@ -1376,33 +1387,83 @@
   continue;
 }
 
-// Fake arguments aren't part of the parsed form and should not be
-// pretty-printed.
-bool hasNonFakeArgs = llvm::any_of(
-Args, [](const std::unique_ptr &A) { return !A->isFake(); });
-
-// FIXME: always printing the parenthesis isn't the correct behavior for
-// attributes which have optional arguments that were not provided. For
-// instance: __attribute__((aligned)) will be pretty printed as
-// __attribute__((aligned())). The logic should check whether there is only
-// a single argument, and if it is optional, whether it has been provided.
-if (hasNonFakeArgs)
-  OS << "(";
 if (Spelling == "availability") {
+  OS << "(";
   writeAvailabilityValue(OS);
+  OS << ")";
 } else if (Spelling == "deprecated" || Spelling == "gnu::deprecated") {
-writeDeprecatedAttrValue(OS, Variety);
+  OS << "(";
+  writeDeprecatedAttrValue(OS, Variety);
+  OS << ")";
 } else {
-  unsigned index = 0;
+  // To avoid printing parentheses around an empty argument list or
+  // printing spurious commas at the end of an argument list, we need to
+  // determine where the last provided non-fake argument is.
+  unsigned NonFakeArgs = 0;
+  unsigned TrailingOptArgs = 0;
+  bool FoundNonOptArg = false;
+  for (const auto &arg : llvm::reverse(Args)) {
+if (arg->isFake())
+  continue;
+++NonFakeArgs;
+if (FoundNonOptArg)
+  continue;
+// FIXME: arg->getIsOmitted() == "false" means we haven't implemented
+// any way to detect whether the argument was o

[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: aaron.ballman.

For consistency with other attributes, fix alloc_size's diagnostics to
report the attribute's argument index for a function parameter index
rather than the actual function parameter index specified in the
source.


https://reviews.llvm.org/D43749

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/alloc-size.c


Index: test/Sema/alloc-size.c
===
--- test/Sema/alloc-size.c
+++ test/Sema/alloc-size.c
@@ -1,16 +1,16 @@
 // RUN: %clang_cc1 %s -verify
 
-void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' 
attribute takes at least 1 argument}}
+void *fail1(int a) __attribute__((alloc_size));   
//expected-error{{'alloc_size' attribute takes at least 1 argument}}
 void *fail2(int a) __attribute__((alloc_size())); 
//expected-error{{'alloc_size' attribute takes at least 1 argument}}
 
-void *fail3(int a) __attribute__((alloc_size(0))); 
//expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
-void *fail4(int a) __attribute__((alloc_size(2))); 
//expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
+void *fail3(int a) __attribute__((alloc_size(0))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
+void *fail4(int a) __attribute__((alloc_size(2))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
 
-void *fail5(int a, int b) __attribute__((alloc_size(0, 1))); 
//expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
-void *fail6(int a, int b) __attribute__((alloc_size(3, 1))); 
//expected-error{{'alloc_size' attribute parameter 3 is out of bounds}}
+void *fail5(int a, int b) __attribute__((alloc_size(0, 1))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
+void *fail6(int a, int b) __attribute__((alloc_size(3, 1))); 
//expected-error{{'alloc_size' attribute parameter 1 is out of bounds}}
 
-void *fail7(int a, int b) __attribute__((alloc_size(1, 0))); 
//expected-error{{'alloc_size' attribute parameter 0 is out of bounds}}
-void *fail8(int a, int b) __attribute__((alloc_size(1, 3))); 
//expected-error{{'alloc_size' attribute parameter 3 is out of bounds}}
+void *fail7(int a, int b) __attribute__((alloc_size(1, 0))); 
//expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
+void *fail8(int a, int b) __attribute__((alloc_size(1, 3))); 
//expected-error{{'alloc_size' attribute parameter 2 is out of bounds}}
 
 int fail9(int a) __attribute__((alloc_size(1))); 
//expected-warning{{'alloc_size' attribute only applies to return values that 
are pointers}}
 
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -765,19 +765,19 @@
   AL.getAttributeSpellingListIndex()));
 }
 
-/// \brief Checks to be sure that the given parameter number is in bounds, and 
is
-/// an integral type. Will emit appropriate diagnostics if this returns
+/// \brief Checks to be sure that the given parameter number is in bounds, and
+/// is an integral type. Will emit appropriate diagnostics if this returns
 /// false.
 ///
-/// FuncParamNo is expected to be from the user, so is base-1. AttrArgNo is 
used
-/// to actually retrieve the argument, so it's base-0.
+/// AttrArgNo is used to actually retrieve the argument, so it's base-0.
 template 
 static bool checkParamIsIntegerType(Sema &S, const FunctionDecl *FD,
-const AttrInfo &AI, Expr *AttrArg,
-unsigned FuncParamNo, unsigned AttrArgNo,
+const AttrInfo &AI, unsigned AttrArgNo,
 bool AllowDependentType = false) {
+  assert(AI.isArgExpr(AttrArgNo) && "Expected expression argument");
+  Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
   uint64_t Idx;
-  if (!checkFunctionOrMethodParameterIndex(S, FD, AI, FuncParamNo, AttrArg,
+  if (!checkFunctionOrMethodParameterIndex(S, FD, AI, AttrArgNo + 1, AttrArg,
Idx))
 return false;
 
@@ -793,20 +793,6 @@
   return true;
 }
 
-/// \brief Checks to be sure that the given parameter number is in bounds, and 
is
-/// an integral type. Will emit appropriate diagnostics if this returns false.
-///
-/// FuncParamNo is expected to be from the user, so is base-1. AttrArgNo is 
used
-/// to actually retrieve the argument, so it's base-0.
-static bool checkParamIsIntegerType(Sema &S, const FunctionDecl *FD,
-const AttributeList &AL,
-unsigned FuncParamNo, unsigned AttrArgNo,
-bool AllowDependentType = false) {
-  assert(AL.isArgExpr(AttrArgNo) && "Expected expression argument");
-  return checkParamIsIntegerType(S, FD, AL, AL.getArgAsExpr(AttrArgNo),
-

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 135839.
jdenny retitled this revision from "[Attr] Fix printing of parameter indices in 
attributes" to "[Attr] Fix parameter indexing for attributes".
jdenny edited the summary of this revision.
jdenny added a comment.
Herald added a subscriber: kristof.beyls.

After several attempts at strategies Aaron and I discussed, I ended up going a 
different way.  See the new summary for details.  I believe this version 
addresses all the issues Aaron raised so far.


https://reviews.llvm.org/D43248

Files:
  include/clang/AST/Attr.h
  include/clang/Basic/Attr.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  test/CodeGenCXX/alloc-size.cpp
  test/Misc/ast-dump-attr.cpp
  test/Sema/attr-ownership.cpp
  test/Sema/attr-print.cpp
  test/Sema/error-type-safety.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -306,9 +306,6 @@
 return "!get" + getUpperName().str() + "()";
   if (type == "TypeSourceInfo *")
 return "false";
-  // FIXME: Do this declaratively in Attr.td.
-  if (getAttrName() == "AllocSize")
-return "0 == get" + getUpperName().str() + "()";
   return "false";
 }
 
@@ -749,6 +746,192 @@
 }
   };
 
+  class VariadicParamIdxArgument : public Argument {
+std::string IdxBeginName, SizeName;
+bool AllowsThis;
+
+  public:
+VariadicParamIdxArgument(const Record &Arg, StringRef Attr)
+: Argument(Arg, Attr), IdxBeginName(getUpperName().str() + "_begin"),
+  SizeName(getUpperName().str() + "_size"),
+  AllowsThis(Arg.getValueAsBit("AllowsThis")) {}
+
+bool isVariadic() const override { return true; }
+
+void writeDeclarations(raw_ostream &OS) const override {
+  OS << "  ParamIdxItr " << IdxBeginName << ";\n";
+  OS << "  unsigned " << SizeName << ";\n";
+}
+
+  public:
+void writeAccessors(raw_ostream &OS) const override {
+  OS << "\n"
+ << "  static bool " << getLowerName() << "_allowsThis() {"
+ << " return " << AllowsThis << "; }\n";
+  OS << "  unsigned " << getLowerName() << "_size() const {"
+ << " return " << SizeName << "; }\n";
+  OS << "  ParamIdxItr " << getLowerName() << "_begin() const { return "
+ << IdxBeginName << "; }\n"
+ << "  ParamIdxItr " << getLowerName() << "_end() const { return "
+ << IdxBeginName << " + " << SizeName << "; }\n"
+ << "  llvm::iterator_range " << getLowerName()
+ << "() const { return llvm::make_range(" << getLowerName()
+ << "_begin(), " << getLowerName() << "_end()); }\n";
+}
+
+void writeCtorParameters(raw_ostream &OS) const override {
+  OS << "ParamIdxItr " << IdxBeginName << ", "
+ << "unsigned " << SizeName;
+}
+
+void writeCloneArgs(raw_ostream &OS) const override {
+  OS << IdxBeginName << ", " << SizeName;
+}
+
+void writeTemplateInstantiationArgs(raw_ostream &OS) const override {
+  // This isn't elegant, but we have to go through public methods...
+  OS << "A->" << getLowerName() << "_begin(), "
+ << "A->" << getLowerName() << "_size()";
+}
+
+void writeImplicitCtorArgs(raw_ostream &OS) const override {
+  OS << IdxBeginName << ", " << SizeName;
+}
+
+void writeCtorInitializers(raw_ostream &OS) const override {
+  OS << IdxBeginName << "(), ";
+  OS << SizeName << "(" << SizeName << ")";
+}
+
+void writeCtorDefaultInitializers(raw_ostream &OS) const override {
+  OS << IdxBeginName << "(), " << SizeName << "(0)";
+}
+
+void writeCtorBody(raw_ostream &OS) const override {
+  OS << "unsigned *" << getUpperName()
+ << "_array = new (Ctx, 16) unsigned[" << SizeName << "];\n";
+  OS << "std::copy((ParamIdxAtSrcItr)" << IdxBeginName
+ << ", (ParamIdxAtSrcItr)" << IdxBeginName << " + " << SizeName << ", "
+ << getUpperName() << "_array);\n";
+  OS << "this->" << IdxBeginName << " = ParamIdxItr(" << getUpperName()
+ << "_array, " << IdxBeginName << ".hasThis());\n";
+}
+
+void writePCHReadDecls(raw_ostream &OS) const override {
+  OS << "unsigned " << SizeName << " = Record.readInt();\n";
+  OS << "SmallVector " << getUpperName() << "_vec;\n"
+ << "" << getUpperName() << "_vec.reserve(" << SizeName << ");\n"
+ << "for (unsigned i = 0; i != " << SizeName << "; ++i)\n"
+ << "  " << getUpperName() << "_vec.push_back(Record.readInt());\n";
+  OS << "bool " << getUpperName() << "HasThis = Record.readInt();\n";
+

[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Hi Aaron. Thanks for accepting. I do not have commit privileges. Would
you please commit this (and any other patches you accept) for me?


https://reviews.llvm.org/D43747



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43749#1018818, @aaron.ballman wrote:

> Aside from a minor testcase nit, this LGTM. Why is this dependent on 
> https://reviews.llvm.org/D43248?


The dependency goes the other way.  Did I get it wrong?




Comment at: test/Sema/alloc-size.c:3
 
-void *fail1(int a) __attribute__((alloc_size)); //expected-error{{'alloc_size' 
attribute takes at least 1 argument}}
+void *fail1(int a) __attribute__((alloc_size));   
//expected-error{{'alloc_size' attribute takes at least 1 argument}}
 void *fail2(int a) __attribute__((alloc_size())); 
//expected-error{{'alloc_size' attribute takes at least 1 argument}}

aaron.ballman wrote:
> This looks like a whitespace-only change?
clang-format-diff.py suggested that.  Should I drop that?


https://reviews.llvm.org/D43749



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


[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43747#1018824, @aaron.ballman wrote:

> In https://reviews.llvm.org/D43747#1018814, @jdenny wrote:
>
> > Hi Aaron. Thanks for accepting. I do not have commit privileges. Would
> >  you please commit this (and any other patches you accept) for me?
>
>
> I'm happy to do so. Just to double-check though, there's nothing about this 
> patch that actually relies on functionality in 
> https://reviews.llvm.org/D43248, correct?


Right.  The dependency is in the other direction.


https://reviews.llvm.org/D43747



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


[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-25 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: test/Misc/ast-print-objectivec.m:52
 // CHECK: @class C1;
-// CHECK: struct __attribute__((objc_bridge_related(C1, , ))) S1;
+// CHECK: struct __attribute__((objc_bridge_related(C1))) S1;

aaron.ballman wrote:
> This fix is incorrect in this case -- the attribute doesn't parse without the 
> extra commas.
> 
> https://godbolt.org/g/Ze69HD
Sorry, I should have researched that one.

It is straight-forward to make it treat an argument as provided based on its 
argument type.  Will look into it soon.


https://reviews.llvm.org/D43748



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-26 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43749#1018846, @aaron.ballman wrote:

> Committed (with whitespace fix for the test case) in r326058, thanks for the 
> patch!


Sure.  Thanks for committing.

By the way the commit log you added isn't quite right. The issue isn't base 0 
versus base 1.  The issue is attribute argument index versus attribute argument 
value.  See the test case for an example.

I'm not suggesting we somehow change the commit log.  I just want to be sure 
you see what I actually did here.


https://reviews.llvm.org/D43749



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-26 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43749#1019377, @aaron.ballman wrote:

> Oh, yeah, I did muck up that commit log message a bit. Sorry about that!


No problem.  :-)

I'll get to your comments in the other patches hopefully soon.  Thanks again.


https://reviews.llvm.org/D43749



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


[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-26 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 135982.
jdenny added a comment.

Aaron: Because the last two arguments for objc_bridge_related must be delimited 
with commas, this revision takes the view that they are not optional but are 
permitted to be the empty string.

The test suite behaves as expected.  Are there any untested attributes that 
might be broken by this patch?  Hopefully they can be addressed in a similar 
manner.


https://reviews.llvm.org/D43748

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

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -231,6 +231,7 @@
 virtual void writePCHReadArgs(raw_ostream &OS) const = 0;
 virtual void writePCHReadDecls(raw_ostream &OS) const = 0;
 virtual void writePCHWrite(raw_ostream &OS) const = 0;
+virtual std::string getIsOmitted() const { return "false"; }
 virtual void writeValue(raw_ostream &OS) const = 0;
 virtual void writeDump(raw_ostream &OS) const = 0;
 virtual void writeDumpChildren(raw_ostream &OS) const {}
@@ -298,33 +299,43 @@
std::string(getUpperName()) + "()");
 }
 
+std::string getIsOmitted() const override {
+  if (type == "FunctionDecl *")
+return "false";
+  if (type == "IdentifierInfo *")
+return "!get" + getUpperName().str() + "()";
+  if (type == "TypeSourceInfo *")
+return "false";
+  // FIXME: Do this declaratively in Attr.td.
+  if (getAttrName() == "AllocSize")
+return "0 == get" + getUpperName().str() + "()";
+  return "false";
+}
+
 void writeValue(raw_ostream &OS) const override {
-  if (type == "FunctionDecl *") {
+  if (type == "FunctionDecl *")
 OS << "\" << get" << getUpperName()
<< "()->getNameInfo().getAsString() << \"";
-  } else if (type == "IdentifierInfo *") {
-OS << "\";\n";
-if (isOptional())
-  OS << "if (get" << getUpperName() << "()) ";
-else
-  OS << "";
-OS << "OS << get" << getUpperName() << "()->getName();\n";
-OS << "OS << \"";
-  } else if (type == "TypeSourceInfo *") {
+  else if (type == "IdentifierInfo *")
+// Some non-optional (comma required) identifier arguments can be the
+// empty string but are then recorded as a nullptr.
+OS << "\" << (get" << getUpperName() << "() ? get" << getUpperName()
+   << "()->getName() : \"\") << \"";
+  else if (type == "TypeSourceInfo *")
 OS << "\" << get" << getUpperName() << "().getAsString() << \"";
-  } else {
+  else
 OS << "\" << get" << getUpperName() << "() << \"";
-  }
 }
 
 void writeDump(raw_ostream &OS) const override {
   if (type == "FunctionDecl *" || type == "NamedDecl *") {
 OS << "OS << \" \";\n";
 OS << "dumpBareDeclRef(SA->get" << getUpperName() << "());\n"; 
   } else if (type == "IdentifierInfo *") {
-if (isOptional())
-  OS << "if (SA->get" << getUpperName() << "())\n  ";
-OS << "OS << \" \" << SA->get" << getUpperName()
+// Some non-optional (comma required) identifier arguments can be the
+// empty string but are then recorded as a nullptr.
+OS << "if (SA->get" << getUpperName() << "())\n"
+   << "  OS << \" \" << SA->get" << getUpperName()
<< "()->getName();\n";
   } else if (type == "TypeSourceInfo *") {
 OS << "OS << \" \" << SA->get" << getUpperName()
@@ -576,12 +587,15 @@
  << "Type());\n";
 }
 
+std::string getIsOmitted() const override {
+  return "!is" + getLowerName().str() + "Expr || !" + getLowerName().str()
+ + "Expr";
+}
+
 void writeValue(raw_ostream &OS) const override {
   OS << "\";\n";
-  // The aligned attribute argument expression is optional.
-  OS << "if (is" << getLowerName() << "Expr && "
- << getLowerName() << "Expr)\n";
-  OS << "  " << getLowerName() << "Expr->printPretty(OS, nullptr, Policy);\n";
+  OS << "" << getLowerName()
+ << "Expr->printPretty(OS, nullptr, Policy);\n";
   OS << "OS << \"";
 }
 
@@ -1376,33 +1390,83 @@
   continue;
 }
 
-// Fake arguments aren't part of the parsed form and should not be
-// pretty-printed.
-bool hasNonFakeArgs = llvm::any_of(
-Args, [](const std::unique_ptr &A) { return !A->isFake(); });
-
-// FIXME: always printing the parenthesis isn't the correct behavior for
-// attributes which have optional arguments that were not provided. For
-// instance: __attribute__((aligned)) will be pretty printed as
-// __attribute__((aligned())). The logic should check

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-02-26 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 136019.
jdenny marked 8 inline comments as done.
jdenny edited the summary of this revision.
jdenny added a comment.

This revision should address all issues raised.


https://reviews.llvm.org/D43248

Files:
  include/clang/AST/Attr.h
  include/clang/Basic/Attr.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  test/CodeGenCXX/alloc-size.cpp
  test/Misc/ast-dump-attr.cpp
  test/Sema/attr-ownership.cpp
  test/Sema/attr-print.cpp
  test/Sema/error-type-safety.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -306,9 +306,6 @@
 return "!get" + getUpperName().str() + "()";
   if (type == "TypeSourceInfo *")
 return "false";
-  // FIXME: Do this declaratively in Attr.td.
-  if (getAttrName() == "AllocSize")
-return "0 == get" + getUpperName().str() + "()";
   return "false";
 }
 
@@ -752,6 +749,152 @@
 }
   };
 
+  class VariadicParamIdxArgument : public VariadicArgument {
+bool AllowsThis;
+
+  public:
+VariadicParamIdxArgument(const Record &Arg, StringRef Attr)
+: VariadicArgument(Arg, Attr, "ParamIdx"),
+  AllowsThis(Arg.getValueAsBit("AllowsThis")) {}
+
+  public:
+void writeAccessors(raw_ostream &OS) const override {
+  VariadicArgument::writeAccessors(OS);
+  OS << "\n"
+ << "  static bool " << getLowerName() << "_allowsThis() {"
+ << " return " << AllowsThis << "; }\n";
+}
+
+void writeCtorBody(raw_ostream &OS) const override {
+  VariadicArgument::writeCtorBody(OS);
+  OS << "#ifndef NDEBUG\n"
+ << "if (" << getLowerName() << "_size()) {\n"
+ << "  bool HasThis = " << getLowerName()
+ << "_begin()->hasThis();\n"
+ << "  for (const auto Idx : " << getLowerName() << "()) {\n"
+ << "assert(Idx.isValid() && \"ParamIdx must be valid\");\n"
+ << "assert(HasThis == Idx.hasThis() && "
+"\"HasThis must be consistent\");\n"
+ << "  }\n"
+ << "}\n"
+ << "#endif\n";
+}
+
+void writePCHReadDecls(raw_ostream &OS) const override {
+  OS << "unsigned " << getUpperName() << "Size = Record.readInt();\n";
+  OS << "bool " << getUpperName() << "HasThis = " << getUpperName()
+ << "Size ? Record.readInt() : false;\n";
+  OS << "SmallVector " << getUpperName() << ";\n"
+ << "" << getUpperName() << ".reserve(" << getUpperName()
+ << "Size);\n"
+ << "for (unsigned i = 0; i != " << getUpperName()
+ << "Size; ++i) {\n"
+ << "  " << getUpperName()
+ << ".push_back(ParamIdx(Record.readInt(), " << getUpperName()
+ << "HasThis));\n"
+ << "}\n";
+}
+
+void writePCHReadArgs(raw_ostream &OS) const override {
+  OS << getUpperName() << ".data(), " << getUpperName() << "Size";
+}
+
+void writePCHWrite(raw_ostream &OS) const override {
+  OS << "Record.push_back(SA->" << getLowerName() << "_size());\n";
+  OS << "if (SA->" << getLowerName() << "_size())\n"
+ << "  Record.push_back(SA->" << getLowerName()
+ << "_begin()->hasThis());\n";
+  OS << "for (auto Idx : SA->" << getLowerName() << "())\n"
+ << "  Record.push_back(Idx.getSourceIndex());\n";
+}
+
+void writeValueImpl(raw_ostream &OS) const override {
+  OS << "OS << Val.getSourceIndex();\n";
+}
+
+void writeDump(raw_ostream &OS) const override {
+  OS << "for (auto Idx : SA->" << getLowerName() << "())\n";
+  OS << "  OS << \" \" << Idx.getSourceIndex();\n";
+}
+  };
+
+  class ParamIdxArgument : public Argument {
+bool AllowsThis;
+std::string IdxName;
+
+  public:
+ParamIdxArgument(const Record &Arg, StringRef Attr)
+: Argument(Arg, Attr), AllowsThis(Arg.getValueAsBit("AllowsThis")),
+  IdxName(getUpperName()) {}
+
+void writeDeclarations(raw_ostream &OS) const override {
+  OS << "ParamIdx " << IdxName << ";\n";
+}
+
+void writeAccessors(raw_ostream &OS) const override {
+  OS << "\n"
+ << "  static bool " << getLowerName() << "_allowsThis() {"
+ << " return " << AllowsThis << "; }\n";
+  OS << "  ParamIdx " << getLowerName() << "() const {"
+ << " return " << IdxName << "; }\n";
+}
+
+void writeCtorParameters(raw_ostream &OS) const override {
+  OS << "ParamIdx " << IdxName;
+}
+
+void writeCloneArgs(raw_ostream &OS) const override { OS << IdxName; }
+
+void writ

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-02-26 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: include/clang/AST/Attr.h:210-212
+  unsigned Idx;
+  bool HasThis;
+  bool IsValid;

aaron.ballman wrote:
> I think it might be best to mash these together using bit-fields:
> ```
> unsigned Idx : 30;
> unsigned HasThis : 1;
> unsigned IsValid : 1;
> ```
Good point.  Thanks.



Comment at: include/clang/AST/Attr.h:238-243
+  ParamIdx &operator=(const ParamIdx &I) {
+Idx = I.Idx;
+HasThis = I.HasThis;
+IsValid = I.IsValid;
+return *this;
+  }

aaron.ballman wrote:
> Is this necessary? There should be an implicit copy assignment operator for 
> this class, and it's a bit strange to have a copy assignment but no copy 
> constructor.
Oops.  Thanks.



Comment at: include/clang/AST/Attr.h:291-292
+template 
+class ParamIdxItrBase : public std::iterator {
+  DerivedT &der() { return *static_cast(this); }

aaron.ballman wrote:
> `std::iterator` was deprecated in C++17, so you should manually expose these 
> fields.
Now that sizeof(ParamIdx) == sizeof(unsigned), I can no longer find a reason to 
avoid ParamIdx arrays, and so I can no longer find a good justification for the 
iterator classes.


https://reviews.llvm.org/D43248



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


[PATCH] D39694: [VerifyDiagnosticConsumer] support -verify=

2017-12-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 127088.
jdenny added a comment.
Herald added a subscriber: mgrang.

1. Use std::binary_search, as suggested by Hal.

2. Fix another case of line wrapping.

3. Rebase onto a recent master, and remove rewrites of tests that have recently 
changed.


https://reviews.llvm.org/D39694

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Basic/DiagnosticOptions.h
  include/clang/Driver/CC1Options.td
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/VerifyDiagnosticConsumer.cpp
  test/Frontend/diagnostics-order.c
  test/Frontend/verify-prefixes.c
  test/Sema/tautological-unsigned-enum-zero-compare.c
  test/Sema/tautological-unsigned-enum-zero-compare.cpp
  test/Sema/tautological-unsigned-zero-compare.c

Index: test/Sema/tautological-unsigned-zero-compare.c
===
--- test/Sema/tautological-unsigned-zero-compare.c
+++ test/Sema/tautological-unsigned-zero-compare.c
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -fsyntax-only -DTEST -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify %s
-// RUN: %clang_cc1 -fsyntax-only -DTEST -verify -x c++ %s
-// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify -x c++ %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify=silence %s
+// RUN: %clang_cc1 -fsyntax-only -verify -x c++ %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-tautological-unsigned-zero-compare -verify=silence -x c++ %s
 
 unsigned uvalue(void);
 signed int svalue(void);
@@ -13,13 +13,8 @@
 void TFunc() {
   // Make sure that we do warn for normal variables in template functions !
   unsigned char c = svalue();
-#ifdef TEST
   if (c < 0) // expected-warning {{comparison of unsigned expression < 0 is always false}}
   return;
-#else
-  if (c < 0)
-  return;
-#endif
 
   if (c < macro(0))
   return;
@@ -39,7 +34,8 @@
 
   unsigned un = uvalue();
 
-#ifdef TEST
+  // silence-no-diagnostics
+
   if (un == 0)
   return 0;
   if (un != 0)
@@ -91,65 +87,10 @@
   return 0;
   if (0UL >= un)
   return 0;
-#else
-// expected-no-diagnostics
-  if (un == 0)
-  return 0;
-  if (un != 0)
-  return 0;
-  if (un < 0)
-  return 0;
-  if (un <= 0)
-  return 0;
-  if (un > 0)
-  return 0;
-  if (un >= 0)
-  return 0;
-
-  if (0 == un)
-  return 0;
-  if (0 != un)
-  return 0;
-  if (0 < un)
-  return 0;
-  if (0 <= un)
-  return 0;
-  if (0 > un)
-  return 0;
-  if (0 >= un)
-  return 0;
-
-  if (un == 0UL)
-  return 0;
-  if (un != 0UL)
-  return 0;
-  if (un < 0UL)
-  return 0;
-  if (un <= 0UL)
-  return 0;
-  if (un > 0UL)
-  return 0;
-  if (un >= 0UL)
-  return 0;
-
-  if (0UL == un)
-  return 0;
-  if (0UL != un)
-  return 0;
-  if (0UL < un)
-  return 0;
-  if (0UL <= un)
-  return 0;
-  if (0UL > un)
-  return 0;
-  if (0UL >= un)
-  return 0;
-#endif
 
 
   signed int a = svalue();
 
-#ifdef TEST
   if (a == 0)
   return 0;
   if (a != 0)
@@ -201,60 +142,6 @@
   return 0;
   if (0UL >= a)
   return 0;
-#else
-// expected-no-diagnostics
-  if (a == 0)
-  return 0;
-  if (a != 0)
-  return 0;
-  if (a < 0)
-  return 0;
-  if (a <= 0)
-  return 0;
-  if (a > 0)
-  return 0;
-  if (a >= 0)
-  return 0;
-
-  if (0 == a)
-  return 0;
-  if (0 != a)
-  return 0;
-  if (0 < a)
-  return 0;
-  if (0 <= a)
-  return 0;
-  if (0 > a)
-  return 0;
-  if (0 >= a)
-  return 0;
-
-  if (a == 0UL)
-  return 0;
-  if (a != 0UL)
-  return 0;
-  if (a < 0UL)
-  return 0;
-  if (a <= 0UL)
-  return 0;
-  if (a > 0UL)
-  return 0;
-  if (a >= 0UL)
-  return 0;
-
-  if (0UL == a)
-  return 0;
-  if (0UL != a)
-  return 0;
-  if (0UL < a)
-  return 0;
-  if (0UL <= a)
-  return 0;
-  if (0UL > a)
-  return 0;
-  if (0UL >= a)
-  return 0;
-#endif
 
 
   float fl = 0;
Index: test/Sema/tautological-unsigned-enum-zero-compare.cpp
===
--- test/Sema/tautological-unsigned-enum-zero-compare.cpp
+++ test/Sema/tautological-unsigned-enum-zero-compare.cpp
@@ -1,6 +1,12 @@
-// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-linux-gnu -fsyntax-only -DUNSIGNED -verify %s
-// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only -DSIGNED -verify %s
-// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only -DSILENCE -Wno-tautological-unsigned-enum-zero-compare -verify %s
+// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-linux-gnu -fsyntax-only \
+// RUN:-verify=unsigned,unsigned-signed %s
+// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only \
+// RUN:-verify=unsigned-signed %s
+// RUN: %clang_cc1 -std=c++11 -triple=x86_64-pc-win32 -fsyntax-only \
+// RUN:-Wno-taut

[PATCH] D39694: [VerifyDiagnosticConsumer] support -verify=

2017-12-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny marked an inline comment as done.
jdenny added inline comments.



Comment at: lib/Frontend/VerifyDiagnosticConsumer.cpp:398
+// DToken is foo-bar-warning, but foo is the only -verify prefix).
+if (Prefixes.end() == std::find(Prefixes.begin(), Prefixes.end(), DToken))
+  continue;

hfinkel wrote:
> > Converts from std::vector to std::set for more efficient prefix lookup.
> 
> Don't do that. First, std::find is O(N) here anyway. You'd want to use 
> Prefixes.find(...) instead. However, this set is essentially constant and 
> you're trying to optimize the lookup. In such a case, std::set is not a good 
> choice. Just use a sorted vector instead (e.g., call std::sort on the 
> vector), and then use std::binary_search here. That's likely much faster.
> 
Thanks.


https://reviews.llvm.org/D39694



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


[PATCH] D39694: [VerifyDiagnosticConsumer] support -verify=

2017-12-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D39694#956661, @hfinkel wrote:

> LGTM


Thanks for accepting. I don't have commit privileges. Would you please commit 
for me?  This depends on https://reviews.llvm.org/D40995, which also needs to 
be committed.


https://reviews.llvm.org/D39694



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


[PATCH] D41841: [OpenMP] Fix handling of clause on wrong directive

2018-01-08 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: ABataev.

First, this patch fixes an assert failure when, for example, "omp for"
has num_teams.

Second, this patch prevents duplicate diagnostics when, for example,
"omp for" has uniform.

This patch makes the general assumption (even where it doesn't
necessarily fix an existing bug) that it is worthless to perform sema
for a clause that appears on a directive on which OpenMP does not 
permit that clause.  However, due to this assumption, this patch
suppresses some diagnostics that were expected in the test suite.  I
assert that those diagnostics were likely just distracting to the 
user.


https://reviews.llvm.org/D41841

Files:
  include/clang/Parse/Parser.h
  lib/Parse/ParseOpenMP.cpp
  test/OpenMP/distribute_simd_loop_messages.cpp
  test/OpenMP/for_misc_messages.c
  test/OpenMP/parallel_messages.cpp
  test/OpenMP/simd_loop_messages.cpp
  test/OpenMP/target_teams_distribute_simd_messages.cpp
  test/OpenMP/taskloop_loop_messages.cpp

Index: test/OpenMP/taskloop_loop_messages.cpp
===
--- test/OpenMP/taskloop_loop_messages.cpp
+++ test/OpenMP/taskloop_loop_messages.cpp
@@ -294,10 +294,8 @@
 c[ii] = a[ii];
 
 #pragma omp parallel
-// expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp taskloop'}}
-// expected-note@+1 {{defined as linear}}
+// expected-error@+1 {{unexpected OpenMP clause 'linear' in directive '#pragma omp taskloop'}}
 #pragma omp taskloop linear(ii)
-// expected-error@+1 {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be linear, predetermined as private}}
   for (ii = 0; ii < 10; ii++)
 c[ii] = a[ii];
 
Index: test/OpenMP/target_teams_distribute_simd_messages.cpp
===
--- test/OpenMP/target_teams_distribute_simd_messages.cpp
+++ test/OpenMP/target_teams_distribute_simd_messages.cpp
@@ -64,7 +64,7 @@
 // expected-error@+1 {{unexpected OpenMP clause 'default' in directive '#pragma omp target teams distribute simd'}}
 #pragma omp target teams distribute simd default(none)
   for (int i = 0; i < 10; ++i)
-++argc; // expected-error {{ariable 'argc' must have explicitly specified data sharing attributes}}
+++argc;
 
   goto L2; // expected-error {{use of undeclared label 'L2'}}
 #pragma omp target teams distribute simd
Index: test/OpenMP/simd_loop_messages.cpp
===
--- test/OpenMP/simd_loop_messages.cpp
+++ test/OpenMP/simd_loop_messages.cpp
@@ -236,9 +236,7 @@
   for (ii = 0; ii < 10; ii++)
 c[ii] = a[ii];
 
-  // expected-error@+3 {{unexpected OpenMP clause 'shared' in directive '#pragma omp simd'}}
-  // expected-note@+2  {{defined as shared}}
-  // expected-error@+2 {{loop iteration variable in the associated loop of 'omp simd' directive may not be shared, predetermined as linear}}
+  // expected-error@+1 {{unexpected OpenMP clause 'shared' in directive '#pragma omp simd'}}
   #pragma omp simd shared(ii)
   for (ii = 0; ii < 10; ii++)
 c[ii] = a[ii];
Index: test/OpenMP/parallel_messages.cpp
===
--- test/OpenMP/parallel_messages.cpp
+++ test/OpenMP/parallel_messages.cpp
@@ -31,6 +31,8 @@
   foo();
   L1:
 foo();
+  #pragma omp parallel ordered // expected-error {{unexpected OpenMP clause 'ordered' in directive '#pragma omp parallel'}}
+;
   #pragma omp parallel
   ;
   #pragma omp parallel
Index: test/OpenMP/for_misc_messages.c
===
--- test/OpenMP/for_misc_messages.c
+++ test/OpenMP/for_misc_messages.c
@@ -54,6 +54,20 @@
 #pragma omp for foo bar
   for (i = 0; i < 16; ++i)
 ;
+// At one time, this failed an assert.
+// expected-error@+1 {{unexpected OpenMP clause 'num_teams' in directive '#pragma omp for'}}
+#pragma omp for num_teams(3)
+  for (i = 0; i < 16; ++i)
+;
+// At one time, this error was reported twice.
+// expected-error@+1 {{unexpected OpenMP clause 'uniform' in directive '#pragma omp for'}}
+#pragma omp for uniform
+  for (i = 0; i < 16; ++i)
+;
+// expected-error@+1 {{unexpected OpenMP clause 'if' in directive '#pragma omp for'}}
+#pragma omp for if(0)
+  for (i = 0; i < 16; ++i)
+;
 }
 
 void test_non_identifiers() {
Index: test/OpenMP/distribute_simd_loop_messages.cpp
===
--- test/OpenMP/distribute_simd_loop_messages.cpp
+++ test/OpenMP/distribute_simd_loop_messages.cpp
@@ -324,9 +324,7 @@
 
   #pragma omp target
   #pragma omp teams
-  // expected-error@+3 {{unexpected OpenMP clause 'shared' in directive '#pragma omp distribute simd'}}
-  // expected-note@+2  {{defined as shared}}
-  // expected-error@+2 {{loop iteration variable in the associated loop of 'omp distribute simd' directive may not be shared, predetermined as linear}}
+  //

[PATCH] D41841: [OpenMP] Fix handling of clause on wrong directive

2018-01-09 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Alexey: Thanks for accepting. I do not have commit privileges. Would
you please commit for me?


https://reviews.llvm.org/D41841



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


[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-27 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: test/Sema/attr-print.c:12
+short arr[3] __attribute__((aligned));
+
 // CHECK: void foo() __attribute__((const));

aaron.ballman wrote:
> Please add a test showing that `objc_bridge_related` isn't mangled by 
> `-ast-print`.
There's already one in Misc/ast-print-objectivec.m, but I can add one here too 
if that's helpful.


https://reviews.llvm.org/D43748



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


[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-27 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 136136.
jdenny edited the summary of this revision.
jdenny added a comment.

This addresses the comment about redundant ifs.


https://reviews.llvm.org/D43748

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

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -231,6 +231,7 @@
 virtual void writePCHReadArgs(raw_ostream &OS) const = 0;
 virtual void writePCHReadDecls(raw_ostream &OS) const = 0;
 virtual void writePCHWrite(raw_ostream &OS) const = 0;
+virtual std::string getIsOmitted() const { return "false"; }
 virtual void writeValue(raw_ostream &OS) const = 0;
 virtual void writeDump(raw_ostream &OS) const = 0;
 virtual void writeDumpChildren(raw_ostream &OS) const {}
@@ -298,33 +299,39 @@
std::string(getUpperName()) + "()");
 }
 
+std::string getIsOmitted() const override {
+  if (type == "IdentifierInfo *")
+return "!get" + getUpperName().str() + "()";
+  // FIXME: Do this declaratively in Attr.td.
+  if (getAttrName() == "AllocSize")
+return "0 == get" + getUpperName().str() + "()";
+  return "false";
+}
+
 void writeValue(raw_ostream &OS) const override {
-  if (type == "FunctionDecl *") {
+  if (type == "FunctionDecl *")
 OS << "\" << get" << getUpperName()
<< "()->getNameInfo().getAsString() << \"";
-  } else if (type == "IdentifierInfo *") {
-OS << "\";\n";
-if (isOptional())
-  OS << "if (get" << getUpperName() << "()) ";
-else
-  OS << "";
-OS << "OS << get" << getUpperName() << "()->getName();\n";
-OS << "OS << \"";
-  } else if (type == "TypeSourceInfo *") {
+  else if (type == "IdentifierInfo *")
+// Some non-optional (comma required) identifier arguments can be the
+// empty string but are then recorded as a nullptr.
+OS << "\" << (get" << getUpperName() << "() ? get" << getUpperName()
+   << "()->getName() : \"\") << \"";
+  else if (type == "TypeSourceInfo *")
 OS << "\" << get" << getUpperName() << "().getAsString() << \"";
-  } else {
+  else
 OS << "\" << get" << getUpperName() << "() << \"";
-  }
 }
 
 void writeDump(raw_ostream &OS) const override {
   if (type == "FunctionDecl *" || type == "NamedDecl *") {
 OS << "OS << \" \";\n";
 OS << "dumpBareDeclRef(SA->get" << getUpperName() << "());\n"; 
   } else if (type == "IdentifierInfo *") {
-if (isOptional())
-  OS << "if (SA->get" << getUpperName() << "())\n  ";
-OS << "OS << \" \" << SA->get" << getUpperName()
+// Some non-optional (comma required) identifier arguments can be the
+// empty string but are then recorded as a nullptr.
+OS << "if (SA->get" << getUpperName() << "())\n"
+   << "  OS << \" \" << SA->get" << getUpperName()
<< "()->getName();\n";
   } else if (type == "TypeSourceInfo *") {
 OS << "OS << \" \" << SA->get" << getUpperName()
@@ -576,12 +583,15 @@
  << "Type());\n";
 }
 
+std::string getIsOmitted() const override {
+  return "!is" + getLowerName().str() + "Expr || !" + getLowerName().str()
+ + "Expr";
+}
+
 void writeValue(raw_ostream &OS) const override {
   OS << "\";\n";
-  // The aligned attribute argument expression is optional.
-  OS << "if (is" << getLowerName() << "Expr && "
- << getLowerName() << "Expr)\n";
-  OS << "  " << getLowerName() << "Expr->printPretty(OS, nullptr, Policy);\n";
+  OS << "" << getLowerName()
+ << "Expr->printPretty(OS, nullptr, Policy);\n";
   OS << "OS << \"";
 }
 
@@ -1376,33 +1386,83 @@
   continue;
 }
 
-// Fake arguments aren't part of the parsed form and should not be
-// pretty-printed.
-bool hasNonFakeArgs = llvm::any_of(
-Args, [](const std::unique_ptr &A) { return !A->isFake(); });
-
-// FIXME: always printing the parenthesis isn't the correct behavior for
-// attributes which have optional arguments that were not provided. For
-// instance: __attribute__((aligned)) will be pretty printed as
-// __attribute__((aligned())). The logic should check whether there is only
-// a single argument, and if it is optional, whether it has been provided.
-if (hasNonFakeArgs)
-  OS << "(";
 if (Spelling == "availability") {
+  OS << "(";
   writeAvailabilityValue(OS);
+  OS << ")";
 } else if (Spelling == "deprecated" || Spelling == "gnu::deprecated") {
-writeDeprecatedAttrValue(OS, Variety);
+  OS 

[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-27 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43747#1018844, @aaron.ballman wrote:

> Committed in r326057.
>
> If you're not already on IRC, I would recommend joining the #llvm channel on 
> OFTC so that you can watch for build break notifications from the build bots.


Thanks.  Can your recommend effective ways to make use of this?  Do developers 
just stay logged in all day to catch failures relevant to their work?


https://reviews.llvm.org/D43747



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


[PATCH] D43747: [Attr] Fix pointer_with_type_tag assert fail for variadic

2018-02-27 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43747#1021234, @aaron.ballman wrote:

> In https://reviews.llvm.org/D43747#1021209, @jdenny wrote:
>
> > In https://reviews.llvm.org/D43747#1018844, @aaron.ballman wrote:
> >
> > > Committed in r326057.
> > >
> > > If you're not already on IRC, I would recommend joining the #llvm channel 
> > > on OFTC so that you can watch for build break notifications from the 
> > > build bots.
> >
> >
> > Thanks.  Can your recommend effective ways to make use of this?  Do 
> > developers just stay logged in all day to catch failures relevant to their 
> > work?
>
>
> Generally, yes. Some folks will even go so far as to set up IRC bouncers to 
> capture messages while their host machine is asleep and no longer connected 
> (but this is by no means required). The key thing is: most build bots send 
> out an email if a commit breaks the build, but not all bots do (some only 
> send to IRC) and that email goes to whoever is on the commit list. So if you 
> make commits or have someone commit something on your behalf, being in the 
> IRC channel can help you quickly fix issues. However, if you're not on the 
> IRC channel, someone else will help make sure you get notified if something 
> goes wrong, so being in IRC isn't required.


Makes sense.  Thanks for the tips.


https://reviews.llvm.org/D43747



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


[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-27 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43748#1021246, @aaron.ballman wrote:

> LGTM! I can commit on your behalf, or, if you plan to continue submitting 
> patches, you can ask for commit privileges 
> (http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access) and 
> commit yourself. Either way works for me.


I'll definitely pursue commit privileges.  If you don't mind committing 
anything you accept today, that would be great.  Thanks for your help!


https://reviews.llvm.org/D43748



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-01 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Hi Aaron.  It occurs to me now that this patch has grown rather large and, in 
some places, a little subtle.  Would it help the review if I were to break it 
up into a patch series that introduces ParamIdx to each attribute, one at a 
time?  I'm not trying to rush you, but I hate for the review to be painful for 
you if it doesn't have to be.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-01 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43248#1024183, @aaron.ballman wrote:

> In https://reviews.llvm.org/D43248#1023720, @jdenny wrote:
>
> > Hi Aaron.  It occurs to me now that this patch has grown rather large and, 
> > in some places, a little subtle.  Would it help the review if I were to 
> > break it up into a patch series that introduces ParamIdx to each attribute, 
> > one at a time?  I'm not trying to rush you, but I hate for the review to be 
> > painful for you if it doesn't have to be.
>
>
> No need to do that -- this review just takes a bit more time for me to 
> complete, but it's reasonably well-factored. Thank you, though!


Sure!  Thanks for the review.




Comment at: include/clang/AST/Attr.h:206
+
+  void cmpable(const ParamIdx &I) const {
+assert(isValid() && I.isValid() &&

aaron.ballman wrote:
> The name here can be improved. How about `checkInvariants()`? Might as well 
> make this inline while you're at it.
Sure, I can change the name.

It's inside the class, so specifying inline is against the LLVM coding 
standards, right?



Comment at: include/clang/AST/Attr.h:236
+  /// parameter.
+  ParamIdx(unsigned Idx, bool HasThis)
+  : Idx(Idx), HasThis(HasThis), IsValid(true) {}

aaron.ballman wrote:
> Is this constructor used anywhere? I didn't see it being used, but I could 
> have missed something. If it's not used, go ahead and remove it.
It's used by the deserialization code generated by ClangAttrEmitter.cpp.



Comment at: include/clang/AST/Attr.h:281-284
+  bool operator<(const ParamIdx &I) const { cmpable(I); return Idx < I.Idx; }
+  bool operator>(const ParamIdx &I) const { cmpable(I); return Idx > I.Idx; }
+  bool operator<=(const ParamIdx &I) const { cmpable(I); return Idx <= I.Idx; }
+  bool operator>=(const ParamIdx &I) const { cmpable(I); return Idx >= I.Idx; }

aaron.ballman wrote:
> Are all of these operations required for the class?
operator== and operator< are needed for sorting and finding.  It seems strange 
to me not to finish the set.



Comment at: include/clang/Basic/Attr.td:172-174
+  // Whether the C++ implicit this parameter is allowed.  Users that construct
+  // attributes from the source code use this information when validating
+  // parameter indices.

aaron.ballman wrote:
> I still find the `AllowThis` parts to be hard to follow, so I want to be sure 
> I understand your design properly. Everything that uses this new argument 
> type sets `AllowsThis` to 0. As written, it sounds like setting that to 0 
> means that the parameter index cannot be used on a C++ instance method, and I 
> know that's not the correct interpretation. Under what circumstances would 
> this be set to 1 instead?
> 
> Looking at the existing code, the only circumstances under which 
> `checkFunctionOrMethodParameterIndex()` was being passed `true` for "allow 
> this" was for XRayLogArgs, which doesn't even use `ParamIdx`. Perhaps this 
> member isn't necessary any longer?
> I still find the AllowThis parts to be hard to follow, so I want to be sure I 
> understand your design properly. Everything that uses this new argument type 
> sets AllowsThis to 0. As written, it sounds like setting that to 0 means that 
> the parameter index cannot be used on a C++ instance method, and I know 
> that's not the correct interpretation.

Right. AllowsThis=0 means it is an error for the attribute in the source code 
to specify the C++ implicit this parameter (index 1).

> Under what circumstances would this be set to 1 instead?
>
> Looking at the existing code, the only circumstances under which 
> checkFunctionOrMethodParameterIndex() was being passed true for "allow this" 
> was for XRayLogArgs, which doesn't even use ParamIdx. Perhaps this member 
> isn't necessary any longer?

Right.  I also noticed this issue, but I probably should have mentioned that in 
a comment in the source instead of just rewording the last paragraph of the 
patch summary.  Sorry.

I thought about removing AllowsThis, but I hesitated because I had already 
implemented it by the time I noticed this issue and because I assumed there 
must be some reason why attributes for C++ have index 1 mean the this 
parameter, so there might be some attribute that could eventually take 
advantage of AllowsThis=1.  Moreover, it makes the related argument to 
checkFunctionOrMethodParameterIndex in SemaDeclAttr.cpp clearer.

I don't feel strongly either way, so I'm happy to remove it or keep it.



Comment at: lib/Sema/SemaDeclAttr.cpp:1650-1651
   OwnershipAttr(AL.getLoc(), S.Context, nullptr, nullptr, 0,
-AL.getAttributeSpellingListIndex()).getOwnKind();
+AL.getAttributeSpellingListIndex())
+  .getOwnKind();
 

aaron.ballman wrote:
> This change looks to be unrelated to the patch?
Sorry, I think clang-f

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-01 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny marked 3 inline comments as done.
jdenny added inline comments.



Comment at: include/clang/Basic/Attr.td:172-174
+  // Whether the C++ implicit this parameter is allowed.  Users that construct
+  // attributes from the source code use this information when validating
+  // parameter indices.

aaron.ballman wrote:
> jdenny wrote:
> > aaron.ballman wrote:
> > > I still find the `AllowThis` parts to be hard to follow, so I want to be 
> > > sure I understand your design properly. Everything that uses this new 
> > > argument type sets `AllowsThis` to 0. As written, it sounds like setting 
> > > that to 0 means that the parameter index cannot be used on a C++ instance 
> > > method, and I know that's not the correct interpretation. Under what 
> > > circumstances would this be set to 1 instead?
> > > 
> > > Looking at the existing code, the only circumstances under which 
> > > `checkFunctionOrMethodParameterIndex()` was being passed `true` for 
> > > "allow this" was for XRayLogArgs, which doesn't even use `ParamIdx`. 
> > > Perhaps this member isn't necessary any longer?
> > > I still find the AllowThis parts to be hard to follow, so I want to be 
> > > sure I understand your design properly. Everything that uses this new 
> > > argument type sets AllowsThis to 0. As written, it sounds like setting 
> > > that to 0 means that the parameter index cannot be used on a C++ instance 
> > > method, and I know that's not the correct interpretation.
> > 
> > Right. AllowsThis=0 means it is an error for the attribute in the source 
> > code to specify the C++ implicit this parameter (index 1).
> > 
> > > Under what circumstances would this be set to 1 instead?
> > >
> > > Looking at the existing code, the only circumstances under which 
> > > checkFunctionOrMethodParameterIndex() was being passed true for "allow 
> > > this" was for XRayLogArgs, which doesn't even use ParamIdx. Perhaps this 
> > > member isn't necessary any longer?
> > 
> > Right.  I also noticed this issue, but I probably should have mentioned 
> > that in a comment in the source instead of just rewording the last 
> > paragraph of the patch summary.  Sorry.
> > 
> > I thought about removing AllowsThis, but I hesitated because I had already 
> > implemented it by the time I noticed this issue and because I assumed there 
> > must be some reason why attributes for C++ have index 1 mean the this 
> > parameter, so there might be some attribute that could eventually take 
> > advantage of AllowsThis=1.  Moreover, it makes the related argument to 
> > checkFunctionOrMethodParameterIndex in SemaDeclAttr.cpp clearer.
> > 
> > I don't feel strongly either way, so I'm happy to remove it or keep it.
> > Right. AllowsThis=0 means it is an error for the attribute in the source 
> > code to specify the C++ implicit this parameter (index 1).
> 
> Then if we keep this functionality, I think a better identifier would be 
> something like `CanIndexImplicitThis` and the comments could be updated to 
> more clearly state what is allowed/disallowed. Then the other uses of "allow 
> this" can be updated to use similar terminology for clarity.
> 
> > so there might be some attribute that could eventually take advantage of 
> > AllowsThis=1. Moreover, it makes the related argument to 
> > checkFunctionOrMethodParameterIndex in SemaDeclAttr.cpp clearer.
> 
> My gut feeling is that this functionality isn't going to be needed all that 
> frequently. If we get a second case where we need it, then I'd say it might 
> make more sense to add it.
> 
> Attributes that use positional arguments should hopefully be the exception, 
> not the rule, because those indexes are horribly fragile.
> 
> What do you think?
> My gut feeling is that this functionality isn't going to be needed all that 
> frequently. If we get a second case where we need it, then I'd say it might 
> make more sense to add it.
> 
> Attributes that use positional arguments should hopefully be the exception, 
> not the rule, because those indexes are horribly fragile.
> 
> What do you think?

I'm guessing you have more experience with attributes in general, so let's go 
with your gut.  :-)



Comment at: lib/Sema/SemaDeclAttr.cpp:4549-4551
+if (ArgumentIdx.getASTIndex() >= getFunctionOrMethodNumParams(D) ||
+!getFunctionOrMethodParamType(D, ArgumentIdx.getASTIndex())
+ ->isPointerType())

aaron.ballman wrote:
> jdenny wrote:
> > aaron.ballman wrote:
> > > Is this formatting produced by clang-format?
> > Yes.
> How funky. :-)
Agreed.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-01 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 136624.
jdenny marked 23 inline comments as done.
jdenny edited the summary of this revision.
jdenny added a comment.

This update should address all outstanding comments.


https://reviews.llvm.org/D43248

Files:
  include/clang/AST/Attr.h
  include/clang/Basic/Attr.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  test/CodeGenCXX/alloc-size.cpp
  test/Misc/ast-dump-attr.cpp
  test/Sema/attr-ownership.cpp
  test/Sema/attr-print.cpp
  test/Sema/error-type-safety.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -302,9 +302,6 @@
 std::string getIsOmitted() const override {
   if (type == "IdentifierInfo *")
 return "!get" + getUpperName().str() + "()";
-  // FIXME: Do this declaratively in Attr.td.
-  if (getAttrName() == "AllocSize")
-return "0 == get" + getUpperName().str() + "()";
   return "false";
 }
 
@@ -748,6 +745,138 @@
 }
   };
 
+  class VariadicParamIdxArgument : public VariadicArgument {
+  public:
+VariadicParamIdxArgument(const Record &Arg, StringRef Attr)
+: VariadicArgument(Arg, Attr, "ParamIdx") {}
+
+  public:
+void writeCtorBody(raw_ostream &OS) const override {
+  VariadicArgument::writeCtorBody(OS);
+  OS << "#ifndef NDEBUG\n"
+ << "if (" << getLowerName() << "_size()) {\n"
+ << "  bool HasThis = " << getLowerName()
+ << "_begin()->hasThis();\n"
+ << "  for (const auto Idx : " << getLowerName() << "()) {\n"
+ << "assert(Idx.isValid() && \"ParamIdx must be valid\");\n"
+ << "assert(HasThis == Idx.hasThis() && "
+"\"HasThis must be consistent\");\n"
+ << "  }\n"
+ << "}\n"
+ << "#endif\n";
+}
+
+void writePCHReadDecls(raw_ostream &OS) const override {
+  OS << "unsigned " << getUpperName() << "Size = Record.readInt();\n";
+  OS << "bool " << getUpperName() << "HasThis = " << getUpperName()
+ << "Size ? Record.readInt() : false;\n";
+  OS << "SmallVector " << getUpperName() << ";\n"
+ << "" << getUpperName() << ".reserve(" << getUpperName()
+ << "Size);\n"
+ << "for (unsigned i = 0; i != " << getUpperName()
+ << "Size; ++i) {\n"
+ << "  " << getUpperName()
+ << ".push_back(ParamIdx(Record.readInt(), " << getUpperName()
+ << "HasThis));\n"
+ << "}\n";
+}
+
+void writePCHReadArgs(raw_ostream &OS) const override {
+  OS << getUpperName() << ".data(), " << getUpperName() << "Size";
+}
+
+void writePCHWrite(raw_ostream &OS) const override {
+  OS << "Record.push_back(SA->" << getLowerName() << "_size());\n";
+  OS << "if (SA->" << getLowerName() << "_size())\n"
+ << "  Record.push_back(SA->" << getLowerName()
+ << "_begin()->hasThis());\n";
+  OS << "for (auto Idx : SA->" << getLowerName() << "())\n"
+ << "  Record.push_back(Idx.getSourceIndex());\n";
+}
+
+void writeValueImpl(raw_ostream &OS) const override {
+  OS << "OS << Val.getSourceIndex();\n";
+}
+
+void writeDump(raw_ostream &OS) const override {
+  OS << "for (auto Idx : SA->" << getLowerName() << "())\n";
+  OS << "  OS << \" \" << Idx.getSourceIndex();\n";
+}
+  };
+
+  class ParamIdxArgument : public Argument {
+std::string IdxName;
+
+  public:
+ParamIdxArgument(const Record &Arg, StringRef Attr)
+: Argument(Arg, Attr), IdxName(getUpperName()) {}
+
+void writeDeclarations(raw_ostream &OS) const override {
+  OS << "ParamIdx " << IdxName << ";\n";
+}
+
+void writeAccessors(raw_ostream &OS) const override {
+  OS << "\n"
+ << "  ParamIdx " << getLowerName() << "() const {"
+ << " return " << IdxName << "; }\n";
+}
+
+void writeCtorParameters(raw_ostream &OS) const override {
+  OS << "ParamIdx " << IdxName;
+}
+
+void writeCloneArgs(raw_ostream &OS) const override { OS << IdxName; }
+
+void writeTemplateInstantiationArgs(raw_ostream &OS) const override {
+  OS << "A->" << getLowerName() << "()";
+}
+
+void writeImplicitCtorArgs(raw_ostream &OS) const override {
+  OS << IdxName;
+}
+
+void writeCtorInitializers(raw_ostream &OS) const override {
+  OS << IdxName << "(" << IdxName << ")";
+}
+
+void writeCtorDefaultInitializers(raw_ostream &OS) const override {
+  OS << IdxName << "()";
+}
+
+void writePCHReadDecls(raw_ostream &OS) const

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-01 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: include/clang/AST/Attr.h:206
+
+  void cmpable(const ParamIdx &I) const {
+assert(isValid() && I.isValid() &&

aaron.ballman wrote:
> jdenny wrote:
> > aaron.ballman wrote:
> > > The name here can be improved. How about `checkInvariants()`? Might as 
> > > well make this inline while you're at it.
> > Sure, I can change the name.
> > 
> > It's inside the class, so specifying inline is against the LLVM coding 
> > standards, right?
> Derp, you're correct, it's already implicitly inline. Ignore that part of the 
> suggestion.
> The name here can be improved. How about checkInvariants()?

I went with assertComparable because, in my view, this is not so much a class 
invariant as it is an assertion about correct usage of comparison operators.  
But I'm not married to it.




https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-02 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: test/Sema/attr-ownership.cpp:1
+// RUN: %clang_cc1 %s -verify
+

aaron.ballman wrote:
> Please pass `-fsyntax-only` as well.
Sure.  Would you like me to change test/Sema/attr-ownership.c while we're 
thinking about it?


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-02 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Aaron, thanks for the review.  I've applied your suggestions and am ready to 
commit.

I've noticed a variety of styles in commit logs, I've read the coding 
standards, and it seems there's a lot of freedom here.  Below are the two 
commit logs I'm planning to use.  Please let me know if you have any 
objections.  Thanks.

  [Attr] Fix parameter indexing for several attributes
  
  The patch fixes a number of bugs related to parameter indexing in
  attributes:
  
  * Parameter indices in some attributes (argument_with_type_tag,
pointer_with_type_tag, nonnull, ownership_takes, ownership_holds,
and ownership_returns) are specified in source as one-origin
including any C++ implicit this parameter, were stored as
zero-origin excluding any this parameter, and were erroneously
printing (-ast-print) and confusingly dumping (-ast-dump) as the
stored values.
  
  * For alloc_size, the C++ implicit this parameter was not subtracted
correctly in Sema, leading to assert failures or to silent failures
of __builtin_object_size to compute a value.
  
  * For argument_with_type_tag, pointer_with_type_tag, and
ownership_returns, the C++ implicit this parameter was not added
back to parameter indices in some diagnostics.
  
  This patch fixes the above bugs and aims to prevent similar bugs in
  the future by introducing careful mechanisms for handling parameter
  indices in attributes.  ParamIdx stores a parameter index and is
  designed to hide the stored encoding while providing accessors that
  require each use (such as printing) to make explicit the encoding that
  is needed.  Attribute declarations declare parameter index arguments
  as [Variadic]ParamIdxArgument, which are exposed as ParamIdx[*].  This
  patch rewrites all attribute arguments that are processed by
  checkFunctionOrMethodParameterIndex in SemaDeclAttr.cpp to be declared
  as [Variadic]ParamIdxArgument.  The only exception is xray_log_args's
  argument, which is encoded as a count not an index.
  
  Differential Revision: https://reviews.llvm.org/D43248

For the test/Sema/attr-ownership.c change:

  [Attr] Use -fsyntax-only in test
  
  Suggested at: https://reviews.llvm.org/D43248


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-02 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326602: [Attr] Fix parameter indexing for several attributes 
(authored by jdenny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43248?vs=136624&id=136811#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43248

Files:
  cfe/trunk/include/clang/AST/Attr.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  cfe/trunk/test/CodeGenCXX/alloc-size.cpp
  cfe/trunk/test/Misc/ast-dump-attr.cpp
  cfe/trunk/test/Sema/attr-ownership.cpp
  cfe/trunk/test/Sema/attr-print.cpp
  cfe/trunk/test/Sema/error-type-safety.cpp
  cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Index: cfe/trunk/include/clang/AST/Attr.h
===
--- cfe/trunk/include/clang/AST/Attr.h
+++ cfe/trunk/include/clang/AST/Attr.h
@@ -195,6 +195,120 @@
}
 };
 
+/// A single parameter index whose accessors require each use to make explicit
+/// the parameter index encoding needed.
+class ParamIdx {
+  // Idx is exposed only via accessors that specify specific encodings.
+  unsigned Idx : 30;
+  unsigned HasThis : 1;
+  unsigned IsValid : 1;
+
+  void assertComparable(const ParamIdx &I) const {
+assert(isValid() && I.isValid() &&
+   "ParamIdx must be valid to be compared");
+// It's possible to compare indices from separate functions, but so far
+// it's not proven useful.  Moreover, it might be confusing because a
+// comparison on the results of getASTIndex might be inconsistent with a
+// comparison on the ParamIdx objects themselves.
+assert(HasThis == I.HasThis &&
+   "ParamIdx must be for the same function to be compared");
+  }
+
+public:
+  /// Construct an invalid parameter index (\c isValid returns false and
+  /// accessors fail an assert).
+  ParamIdx() : Idx(0), HasThis(false), IsValid(false) {}
+
+  /// \param Idx is the parameter index as it is normally specified in
+  /// attributes in the source: one-origin including any C++ implicit this
+  /// parameter.
+  ///
+  /// \param D is the declaration containing the parameters.  It is used to
+  /// determine if there is a C++ implicit this parameter.
+  ParamIdx(unsigned Idx, const Decl *D)
+  : Idx(Idx), HasThis(false), IsValid(true) {
+if (const auto *FD = dyn_cast(D))
+  HasThis = FD->isCXXInstanceMember();
+  }
+
+  /// \param Idx is the parameter index as it is normally specified in
+  /// attributes in the source: one-origin including any C++ implicit this
+  /// parameter.
+  ///
+  /// \param HasThis specifies whether the function has a C++ implicit this
+  /// parameter.
+  ParamIdx(unsigned Idx, bool HasThis)
+  : Idx(Idx), HasThis(HasThis), IsValid(true) {}
+
+  /// Is this parameter index valid?
+  bool isValid() const { return IsValid; }
+
+  /// Is there a C++ implicit this parameter?
+  bool hasThis() const {
+assert(isValid() && "ParamIdx must be valid");
+return HasThis;
+  }
+
+  /// Get the parameter index as it would normally be encoded for attributes at
+  /// the source level of representation: one-origin including any C++ implicit
+  /// this parameter.
+  ///
+  /// This encoding thus makes sense for diagnostics, pretty printing, and
+  /// constructing new attributes from a source-like specification.
+  unsigned getSourceIndex() const {
+assert(isValid() && "ParamIdx must be valid");
+return Idx;
+  }
+
+  /// Get the parameter index as it would normally be encoded at the AST level
+  /// of representation: zero-origin not including any C++ implicit this
+  /// parameter.
+  ///
+  /// This is the encoding primarily used in Sema.  However, in diagnostics,
+  /// Sema uses \c getSourceIndex instead.
+  unsigned getASTIndex() const {
+assert(isValid() && "ParamIdx must be valid");
+assert(Idx >= 1 + HasThis &&
+   "stored index must be base-1 and not specify C++ implicit this");
+return Idx - 1 - HasThis;
+  }
+
+  /// Get the parameter index as it would normally be encoded at the LLVM level
+  /// of representation: zero-origin including any C++ implicit this parameter.
+  ///
+  /// This is the encoding primarily used in CodeGen.
+  unsigned getLLVMIndex() const {
+assert(isValid() && "ParamIdx must be valid");
+assert(Idx >= 1 && "stored index must be base-1");
+return Idx - 1;
+  }
+
+  bool operator==(const ParamIdx &I) const {
+assertComparable(I);
+return Idx == I.Idx;
+  }
+  bool operator!=(const ParamIdx &I) const {
+assertComparable(I);
+return Idx != I.Idx;
+  }
+  bool operator<(c

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-11 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 137964.
jdenny added a comment.

This commit was reverted by r326862 due to:

https://bugs.llvm.org/show_bug.cgi?id=36620

This revision includes a new test case and a fix.

While the difference from the last revision is small, it's not trivial, so 
another review is probably worthwhile.  The main difference is two new  
ParamIdx member functions: serialize and deserialize.   In 
ClangAttrEmitter.cpp, these functions enable significant simplifications and 
facilitate the bug fix.


https://reviews.llvm.org/D43248

Files:
  include/clang/AST/Attr.h
  include/clang/Basic/Attr.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  test/CodeGenCXX/alloc-size.cpp
  test/Frontend/ast-attr.cpp
  test/Misc/ast-dump-attr.cpp
  test/Sema/attr-ownership.cpp
  test/Sema/attr-print.cpp
  test/Sema/error-type-safety.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -104,6 +104,7 @@
 .Case("Expr *", "Record.readExpr()")
 .Case("IdentifierInfo *", "Record.getIdentifierInfo()")
 .Case("StringRef", "Record.readString()")
+.Case("ParamIdx", "ParamIdx::deserialize(Record.readInt())")
 .Default("Record.readInt()");
 }
 
@@ -122,6 +123,7 @@
 .Case("Expr *", "AddStmt(" + std::string(name) + ");\n")
 .Case("IdentifierInfo *", "AddIdentifierRef(" + std::string(name) + ");\n")
 .Case("StringRef", "AddString(" + std::string(name) + ");\n")
+.Case("ParamIdx", "push_back(" + std::string(name) + ".serialize());\n")
 .Default("push_back(" + std::string(name) + ");\n");
 }
 
@@ -302,9 +304,8 @@
 std::string getIsOmitted() const override {
   if (type == "IdentifierInfo *")
 return "!get" + getUpperName().str() + "()";
-  // FIXME: Do this declaratively in Attr.td.
-  if (getAttrName() == "AllocSize")
-return "0 == get" + getUpperName().str() + "()";
+  if (type == "ParamIdx")
+return "!get" + getUpperName().str() + "().isValid()";
   return "false";
 }
 
@@ -319,6 +320,8 @@
<< "()->getName() : \"\") << \"";
   else if (type == "TypeSourceInfo *")
 OS << "\" << get" << getUpperName() << "().getAsString() << \"";
+  else if (type == "ParamIdx")
+OS << "\" << get" << getUpperName() << "().getSourceIndex() << \"";
   else
 OS << "\" << get" << getUpperName() << "() << \"";
 }
@@ -341,6 +344,11 @@
<< getUpperName() << "\";\n";
   } else if (type == "int" || type == "unsigned") {
 OS << "OS << \" \" << SA->get" << getUpperName() << "();\n";
+  } else if (type == "ParamIdx") {
+if (isOptional())
+  OS << "if (SA->get" << getUpperName() << "().isValid())\n  ";
+OS << "OS << \" \" << SA->get" << getUpperName()
+   << "().getSourceIndex();\n";
   } else {
 llvm_unreachable("Unknown SimpleArgument type!");
   }
@@ -618,6 +626,10 @@
 virtual void writeValueImpl(raw_ostream &OS) const {
   OS << "OS << Val;\n";
 }
+// Assumed to receive a parameter: raw_ostream OS.
+virtual void writeDumpImpl(raw_ostream &OS) const {
+  OS << "  OS << \" \" << Val;\n";
+}
 
   public:
 VariadicArgument(const Record &Arg, StringRef Attr, std::string T)
@@ -744,7 +756,22 @@
 
 void writeDump(raw_ostream &OS) const override {
   OS << "for (const auto &Val : SA->" << RangeName << "())\n";
-  OS << "  OS << \" \" << Val;\n";
+  writeDumpImpl(OS);
+}
+  };
+
+  class VariadicParamIdxArgument : public VariadicArgument {
+  public:
+VariadicParamIdxArgument(const Record &Arg, StringRef Attr)
+: VariadicArgument(Arg, Attr, "ParamIdx") {}
+
+  public:
+void writeValueImpl(raw_ostream &OS) const override {
+  OS << "OS << Val.getSourceIndex();\n";
+}
+
+void writeDumpImpl(raw_ostream &OS) const override {
+  OS << "  OS << \" \" << Val.getSourceIndex();\n";
 }
   };
 
@@ -1247,6 +1274,10 @@
 Ptr = llvm::make_unique(Arg, Attr);
   else if (ArgName == "VariadicExprArgument")
 Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "VariadicParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "ParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr, "ParamIdx");
   else if (ArgName == "VersionArgument")
 Ptr = llvm::make_unique(Arg, Attr);
 
Index: test/Sema/error-type-safety.cpp
===
--- test/Sema/error-type-safety.cpp
+++ test/Sema/error-type-safety.cpp
@@ -3,21 +3,50 @@
 #define INT_TAG 42

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 138111.
jdenny added a comment.

OK, this diff has the svn paths, and I've rebased to a more recent master.


https://reviews.llvm.org/D43248

Files:
  trunk/include/clang/AST/Attr.h
  trunk/include/clang/Basic/Attr.td
  trunk/lib/AST/ExprConstant.cpp
  trunk/lib/CodeGen/CGCall.cpp
  trunk/lib/Sema/SemaChecking.cpp
  trunk/lib/Sema/SemaDecl.cpp
  trunk/lib/Sema/SemaDeclAttr.cpp
  trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  trunk/test/CodeGenCXX/alloc-size.cpp
  trunk/test/Frontend/ast-attr.cpp
  trunk/test/Misc/ast-dump-attr.cpp
  trunk/test/Sema/attr-ownership.cpp
  trunk/test/Sema/attr-print.cpp
  trunk/test/Sema/error-type-safety.cpp
  trunk/utils/TableGen/ClangAttrEmitter.cpp

Index: trunk/utils/TableGen/ClangAttrEmitter.cpp
===
--- trunk/utils/TableGen/ClangAttrEmitter.cpp
+++ trunk/utils/TableGen/ClangAttrEmitter.cpp
@@ -104,6 +104,7 @@
 .Case("Expr *", "Record.readExpr()")
 .Case("IdentifierInfo *", "Record.getIdentifierInfo()")
 .Case("StringRef", "Record.readString()")
+.Case("ParamIdx", "ParamIdx::deserialize(Record.readInt())")
 .Default("Record.readInt()");
 }
 
@@ -122,6 +123,7 @@
 .Case("Expr *", "AddStmt(" + std::string(name) + ");\n")
 .Case("IdentifierInfo *", "AddIdentifierRef(" + std::string(name) + ");\n")
 .Case("StringRef", "AddString(" + std::string(name) + ");\n")
+.Case("ParamIdx", "push_back(" + std::string(name) + ".serialize());\n")
 .Default("push_back(" + std::string(name) + ");\n");
 }
 
@@ -302,9 +304,8 @@
 std::string getIsOmitted() const override {
   if (type == "IdentifierInfo *")
 return "!get" + getUpperName().str() + "()";
-  // FIXME: Do this declaratively in Attr.td.
-  if (getAttrName() == "AllocSize")
-return "0 == get" + getUpperName().str() + "()";
+  if (type == "ParamIdx")
+return "!get" + getUpperName().str() + "().isValid()";
   return "false";
 }
 
@@ -319,6 +320,8 @@
<< "()->getName() : \"\") << \"";
   else if (type == "TypeSourceInfo *")
 OS << "\" << get" << getUpperName() << "().getAsString() << \"";
+  else if (type == "ParamIdx")
+OS << "\" << get" << getUpperName() << "().getSourceIndex() << \"";
   else
 OS << "\" << get" << getUpperName() << "() << \"";
 }
@@ -341,6 +344,11 @@
<< getUpperName() << "\";\n";
   } else if (type == "int" || type == "unsigned") {
 OS << "OS << \" \" << SA->get" << getUpperName() << "();\n";
+  } else if (type == "ParamIdx") {
+if (isOptional())
+  OS << "if (SA->get" << getUpperName() << "().isValid())\n  ";
+OS << "OS << \" \" << SA->get" << getUpperName()
+   << "().getSourceIndex();\n";
   } else {
 llvm_unreachable("Unknown SimpleArgument type!");
   }
@@ -618,6 +626,10 @@
 virtual void writeValueImpl(raw_ostream &OS) const {
   OS << "OS << Val;\n";
 }
+// Assumed to receive a parameter: raw_ostream OS.
+virtual void writeDumpImpl(raw_ostream &OS) const {
+  OS << "  OS << \" \" << Val;\n";
+}
 
   public:
 VariadicArgument(const Record &Arg, StringRef Attr, std::string T)
@@ -744,7 +756,22 @@
 
 void writeDump(raw_ostream &OS) const override {
   OS << "for (const auto &Val : SA->" << RangeName << "())\n";
-  OS << "  OS << \" \" << Val;\n";
+  writeDumpImpl(OS);
+}
+  };
+
+  class VariadicParamIdxArgument : public VariadicArgument {
+  public:
+VariadicParamIdxArgument(const Record &Arg, StringRef Attr)
+: VariadicArgument(Arg, Attr, "ParamIdx") {}
+
+  public:
+void writeValueImpl(raw_ostream &OS) const override {
+  OS << "OS << Val.getSourceIndex();\n";
+}
+
+void writeDumpImpl(raw_ostream &OS) const override {
+  OS << "  OS << \" \" << Val.getSourceIndex();\n";
 }
   };
 
@@ -1247,6 +1274,10 @@
 Ptr = llvm::make_unique(Arg, Attr);
   else if (ArgName == "VariadicExprArgument")
 Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "VariadicParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "ParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr, "ParamIdx");
   else if (ArgName == "VersionArgument")
 Ptr = llvm::make_unique(Arg, Attr);
 
Index: trunk/test/Sema/error-type-safety.cpp
===
--- trunk/test/Sema/error-type-safety.cpp
+++ trunk/test/Sema/error-type-safety.cpp
@@ -3,21 +3,50 @@
 #define INT_TAG 42
 
 static const int test_in
-  __attribute__((type_tag_for_datatype(test, int))) = INT_TAG;
+__attribute__((type_tag_for_datatype(test, int))) = INT_TAG;
 
 // Argument index: 1, Type tag index: 2
 void test_bounds_index(...)
-  __att

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 138113.
jdenny added a comment.

Well, that didn't work.  Here's another attempt at getting the paths right.


https://reviews.llvm.org/D43248

Files:
  cfe/trunk/include/clang/AST/Attr.h
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  cfe/trunk/test/CodeGenCXX/alloc-size.cpp
  cfe/trunk/test/Frontend/ast-attr.cpp
  cfe/trunk/test/Misc/ast-dump-attr.cpp
  cfe/trunk/test/Sema/attr-ownership.cpp
  cfe/trunk/test/Sema/attr-print.cpp
  cfe/trunk/test/Sema/error-type-safety.cpp
  cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Index: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
===
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
@@ -104,6 +104,7 @@
 .Case("Expr *", "Record.readExpr()")
 .Case("IdentifierInfo *", "Record.getIdentifierInfo()")
 .Case("StringRef", "Record.readString()")
+.Case("ParamIdx", "ParamIdx::deserialize(Record.readInt())")
 .Default("Record.readInt()");
 }
 
@@ -122,6 +123,7 @@
 .Case("Expr *", "AddStmt(" + std::string(name) + ");\n")
 .Case("IdentifierInfo *", "AddIdentifierRef(" + std::string(name) + ");\n")
 .Case("StringRef", "AddString(" + std::string(name) + ");\n")
+.Case("ParamIdx", "push_back(" + std::string(name) + ".serialize());\n")
 .Default("push_back(" + std::string(name) + ");\n");
 }
 
@@ -302,9 +304,8 @@
 std::string getIsOmitted() const override {
   if (type == "IdentifierInfo *")
 return "!get" + getUpperName().str() + "()";
-  // FIXME: Do this declaratively in Attr.td.
-  if (getAttrName() == "AllocSize")
-return "0 == get" + getUpperName().str() + "()";
+  if (type == "ParamIdx")
+return "!get" + getUpperName().str() + "().isValid()";
   return "false";
 }
 
@@ -319,6 +320,8 @@
<< "()->getName() : \"\") << \"";
   else if (type == "TypeSourceInfo *")
 OS << "\" << get" << getUpperName() << "().getAsString() << \"";
+  else if (type == "ParamIdx")
+OS << "\" << get" << getUpperName() << "().getSourceIndex() << \"";
   else
 OS << "\" << get" << getUpperName() << "() << \"";
 }
@@ -341,6 +344,11 @@
<< getUpperName() << "\";\n";
   } else if (type == "int" || type == "unsigned") {
 OS << "OS << \" \" << SA->get" << getUpperName() << "();\n";
+  } else if (type == "ParamIdx") {
+if (isOptional())
+  OS << "if (SA->get" << getUpperName() << "().isValid())\n  ";
+OS << "OS << \" \" << SA->get" << getUpperName()
+   << "().getSourceIndex();\n";
   } else {
 llvm_unreachable("Unknown SimpleArgument type!");
   }
@@ -618,6 +626,10 @@
 virtual void writeValueImpl(raw_ostream &OS) const {
   OS << "OS << Val;\n";
 }
+// Assumed to receive a parameter: raw_ostream OS.
+virtual void writeDumpImpl(raw_ostream &OS) const {
+  OS << "  OS << \" \" << Val;\n";
+}
 
   public:
 VariadicArgument(const Record &Arg, StringRef Attr, std::string T)
@@ -744,7 +756,22 @@
 
 void writeDump(raw_ostream &OS) const override {
   OS << "for (const auto &Val : SA->" << RangeName << "())\n";
-  OS << "  OS << \" \" << Val;\n";
+  writeDumpImpl(OS);
+}
+  };
+
+  class VariadicParamIdxArgument : public VariadicArgument {
+  public:
+VariadicParamIdxArgument(const Record &Arg, StringRef Attr)
+: VariadicArgument(Arg, Attr, "ParamIdx") {}
+
+  public:
+void writeValueImpl(raw_ostream &OS) const override {
+  OS << "OS << Val.getSourceIndex();\n";
+}
+
+void writeDumpImpl(raw_ostream &OS) const override {
+  OS << "  OS << \" \" << Val.getSourceIndex();\n";
 }
   };
 
@@ -1247,6 +1274,10 @@
 Ptr = llvm::make_unique(Arg, Attr);
   else if (ArgName == "VariadicExprArgument")
 Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "VariadicParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr);
+  else if (ArgName == "ParamIdxArgument")
+Ptr = llvm::make_unique(Arg, Attr, "ParamIdx");
   else if (ArgName == "VersionArgument")
 Ptr = llvm::make_unique(Arg, Attr);
 
Index: cfe/trunk/test/Sema/error-type-safety.cpp
===
--- cfe/trunk/test/Sema/error-type-safety.cpp
+++ cfe/trunk/test/Sema/error-type-safety.cpp
@@ -3,21 +3,50 @@
 #define INT_TAG 42
 
 static const int test_in
-  __attribute__((type_tag_for_datatype(test, int))) = INT_TAG;
+__attribute__((type_tag_for_datatype(test, int))

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43248#1035466, @aaron.ballman wrote:

> It seems like there are some other changes than just the serialize and 
> deserialize that I'm not opposed to, but am wondering why they're needed. It 
> seems some functions are now `getFoo()` calls


These were originally named getFoo, and my previous patch changed them to foo.  
I believe I did that to make ParamIdxArgument accessors more like 
VariadicParamIdxArgument accessors (which inherits accessors from 
VariadicArgument), but I probably shouldn't have done that.  In any case, this 
new revision implements ParamIdxArgument using SimpleArgument, and that names 
accessors like getFoo.

> and it seems like some declarations moved around. Are those intended as part 
> of this patch?

Are you referring to the changes in SemaDeclAttr.cpp?  Those changes are needed 
because the ParamIdx constructor now asserts that Idx is one-origin, but that 
requires validating that it's actually one-origin beforehand.  Sorry, I 
should've mentioned the new asserts.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:1-2
+// %S/../Sema/attr-print.cpp exercises many different attributes, so we reuse
+// it here to check -emit-ast for attributes.
+

aaron.ballman wrote:
> Can you move this below the RUN line?
Sure.  I'm still trying to learn the LLVM coding standards.  Is this specified 
there?


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:1-2
+// %S/../Sema/attr-print.cpp exercises many different attributes, so we reuse
+// it here to check -emit-ast for attributes.
+

aaron.ballman wrote:
> jdenny wrote:
> > aaron.ballman wrote:
> > > Can you move this below the RUN line?
> > Sure.  I'm still trying to learn the LLVM coding standards.  Is this 
> > specified there?
> Nope! I'm just used to looking at the very first line of the test to know 
> what it's running, and that seems consistent with other tests.
OK, that makes sense.  I'll be sure to change both of those.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: cfe/trunk/test/Frontend/ast-attr.cpp:5
+// RUN: %clang -emit-ast -o %t.ast %S/../Sema/attr-print.cpp
+// RUN: %clang_cc1 %t.ast -ast-print | FileCheck %S/../Sema/attr-print.cpp

aaron.ballman wrote:
> Just to verify my understanding, this test is checking the serialization and 
> deserialization?
That's right, and it failed without the other changes in this revision because 
alloc_size's second argument serialized/deserialized as 0 when it was actually 
invalid (that is, unspecified).  Of course, this test is more thorough than 
just exercising alloc_size.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-12 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43248#1035509, @aaron.ballman wrote:

> LGTM with the test comments fixed up.


Thanks!  I'll commit tomorrow.


https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-13 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jdenny marked 8 inline comments as done.
Closed by commit rC327405: Reland "[Attr] Fix parameter indexing for 
several attributes" (authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43248?vs=138113&id=138193#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43248

Files:
  include/clang/AST/Attr.h
  include/clang/Basic/Attr.td
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  test/CodeGenCXX/alloc-size.cpp
  test/Frontend/ast-attr.cpp
  test/Misc/ast-dump-attr.cpp
  test/Sema/attr-ownership.cpp
  test/Sema/attr-print.cpp
  test/Sema/error-type-safety.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1231,9 +1231,10 @@
   if (Att->getModule() != II_malloc)
 return nullptr;
 
-  OwnershipAttr::args_iterator I = Att->args_begin(), E = Att->args_end();
+  ParamIdx *I = Att->args_begin(), *E = Att->args_end();
   if (I != E) {
-return MallocMemAux(C, CE, CE->getArg(*I), UndefinedVal(), State);
+return MallocMemAux(C, CE, CE->getArg(I->getASTIndex()), UndefinedVal(),
+State);
   }
   return MallocMemAux(C, CE, UnknownVal(), UndefinedVal(), State);
 }
@@ -1331,9 +1332,9 @@
   bool ReleasedAllocated = false;
 
   for (const auto &Arg : Att->args()) {
-ProgramStateRef StateI = FreeMemAux(C, CE, State, Arg,
-   Att->getOwnKind() == OwnershipAttr::Holds,
-   ReleasedAllocated);
+ProgramStateRef StateI = FreeMemAux(
+C, CE, State, Arg.getASTIndex(),
+Att->getOwnKind() == OwnershipAttr::Holds, ReleasedAllocated);
 if (StateI)
   State = StateI;
   }
Index: lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
+++ lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
@@ -54,10 +54,11 @@
   AttrNonNull.set(0, NumArgs);
   break;
 }
-for (unsigned Val : NonNull->args()) {
-  if (Val >= NumArgs)
+for (const ParamIdx &Idx : NonNull->args()) {
+  unsigned IdxAST = Idx.getASTIndex();
+  if (IdxAST >= NumArgs)
 continue;
-  AttrNonNull.set(Val);
+  AttrNonNull.set(IdxAST);
 }
   }
   return AttrNonNull;
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -5475,9 +5475,8 @@
 llvm::APInt &Result) {
   const AllocSizeAttr *AllocSize = getAllocSizeAttr(Call);
 
-  // alloc_size args are 1-indexed, 0 means not present.
-  assert(AllocSize && AllocSize->getElemSizeParam() != 0);
-  unsigned SizeArgNo = AllocSize->getElemSizeParam() - 1;
+  assert(AllocSize && AllocSize->getElemSizeParam().isValid());
+  unsigned SizeArgNo = AllocSize->getElemSizeParam().getASTIndex();
   unsigned BitsInSizeT = Ctx.getTypeSize(Ctx.getSizeType());
   if (Call->getNumArgs() <= SizeArgNo)
 return false;
@@ -5495,14 +5494,13 @@
   if (!EvaluateAsSizeT(Call->getArg(SizeArgNo), SizeOfElem))
 return false;
 
-  if (!AllocSize->getNumElemsParam()) {
+  if (!AllocSize->getNumElemsParam().isValid()) {
 Result = std::move(SizeOfElem);
 return true;
   }
 
   APSInt NumberOfElems;
-  // Argument numbers start at 1
-  unsigned NumArgNo = AllocSize->getNumElemsParam() - 1;
+  unsigned NumArgNo = AllocSize->getNumElemsParam().getASTIndex();
   if (!EvaluateAsSizeT(Call->getArg(NumArgNo), NumberOfElems))
 return false;
 
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -176,7 +176,8 @@
 Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
 const AllocAlignAttr *Align, Decl *New) {
   Expr *Param = IntegerLiteral::Create(
-  S.getASTContext(), llvm::APInt(64, Align->getParamIndex()),
+  S.getASTContext(),
+  llvm::APInt(64, Align->getParamIndex().getSourceIndex()),
   S.getASTContext().UnsignedLongLongTy, Align->getLocation());
   S.AddAllocAlignAttr(Align->getLocation(), New, Param,
   Align->getSpellingListIndex());
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -13185,7 +13185,7 @@
 // We already have a __builtin___CFStringMakeConstan

[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-13 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added inline comments.



Comment at: test/Sema/attr-print.cpp:3
 
+// This file is also used as input for %S/../Frontend/ast-attr.cpp.
+

echristo wrote:
> Relatedly I don't think we use files as input files to other directories and 
> I don't think we should really. What are you trying to test here? This breaks 
> the hermeticness of each particular test directory.
Grep for "%S/.." and you'll see that a few other tests do something like this 
as well.

In test/Sema/attr-print.cpp, I am testing printing of attributes.  I chose to 
put that there because of the existing attr-print.c there.

In test/Frontend/ast-attr.cpp, I am testing serialization of attributes.  I 
chose to put that there because I see other -emit-ast tests there and because, 
if I put it in test/Sema instead, I get the complaint "Do not use the driver in 
Sema tests".

The same C++ code makes sense in both of these, but replicating it in two files 
would worsen maintainability.

I could try to  combine into one file in, say, tests/Misc if that works.

I have no strong opinions on where these live.  Just for my own education, is 
something real breaking right now because of their current locations?

Thanks.


Repository:
  rC Clang

https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-13 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

I'd prefer to move it than to expect people to obey such a comment.  Let's see 
what Aaron says.


Repository:
  rC Clang

https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-13 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43248#1036427, @echristo wrote:

> In https://reviews.llvm.org/D43248#1036426, @aaron.ballman wrote:
>
> > In https://reviews.llvm.org/D43248#1036409, @jdenny wrote:
> >
> > > I'd prefer to move it than to expect people to obey such a comment.  
> > > Let's see what Aaron says.
> >
> >
> > I have a slight preference for moving the tests now that I know they're 
> > causing problems, unless that turns out to be overly onerous for some 
> > reason.
> >
> > Thank you, @echristo for pointing out the issues with the tests, I hadn't 
> > considered that.
>
>
> No worries :)
>
> That said, please don't revert and reapply to move. Just a followup commit is 
> just fine - and whenever you get a chance. (Though if you let me know when 
> you do I'd appreciate it :)


Sure.

So, I'm planning to remove test/Frontend/ast-attr.cpp, rename 
test/Sema/attr-print.cpp to test/Misc/attr-print-emit.cpp, and change its run 
lines to:

  // RUN: %clang_cc1 %s -ast-print | FileCheck %s
  // RUN: %clang -emit-ast -o %t.ast %s
  // RUN: %clang_cc1 %t.ast -ast-print | FileCheck %s

That seems to work fine locally.  I'll just leave the old 
test/Sema/attr-print.c alone as it's not part of this problem.  Any objections?


Repository:
  rC Clang

https://reviews.llvm.org/D43248



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


[PATCH] D43248: [Attr] Fix parameter indexing for attributes

2018-03-13 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43248#1036439, @jdenny wrote:

> So, I'm planning to remove test/Frontend/ast-attr.cpp, rename 
> test/Sema/attr-print.cpp to test/Misc/attr-print-emit.cpp, and change its run 
> lines to:
>
>   // RUN: %clang_cc1 %s -ast-print | FileCheck %s
>   // RUN: %clang -emit-ast -o %t.ast %s
>   // RUN: %clang_cc1 %t.ast -ast-print | FileCheck %s
>
>
> That seems to work fine locally.  I'll just leave the old 
> test/Sema/attr-print.c alone as it's not part of this problem.  Any 
> objections?


I went ahead and committed.  It's in r327456.


Repository:
  rC Clang

https://reviews.llvm.org/D43248



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


[PATCH] D46846: [AST] Fix loss of enum forward decl from decl context

2018-05-30 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC333574: [AST] Fix loss of enum forward decl from decl 
context (authored by jdenny, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D46846

Files:
  lib/Sema/SemaDecl.cpp
  test/Sema/ast-print.c
  test/SemaCXX/MicrosoftCompatibility.cpp


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -239,6 +239,15 @@
ENUM2_c = 0x1 // expected-warning {{enumerator value is not 
representable in the underlying type 'int'}}
 };
 
+namespace NsEnumForwardDecl {
+  enum E *p; // expected-warning {{forward references to 'enum' types are a 
Microsoft extension}}
+  extern E e;
+}
+// Clang used to complain that NsEnumForwardDecl::E was undeclared below.
+NsEnumForwardDecl::E NsEnumForwardDecl_e;
+namespace NsEnumForwardDecl {
+  extern E e;
+}
 
 namespace PR11791 {
   template
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field 
designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been 
explicitly marked deprecated here}}"
+// RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is 
deprecated}}"
+// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been 
explicitly marked deprecated here}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is 
deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been 
explicitly marked deprecated here}}"
 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
@@ -86,8 +88,7 @@
   // CHECK-NEXT: } *EnumWithAttributesPtr;
 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note 
{{'EnumWithAttributes' has been explicitly marked deprecated here}}
 
-// FIXME: If enum is forward-declared at file scope, attributes are lost.
-// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
+// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 
*EnumWithAttributes2Ptr;
 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked 
deprecated here}}
 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -14287,7 +14287,6 @@
   // PrevDecl.
   TagDecl *New;
 
-  bool IsForwardReference = false;
   if (Kind == TTK_Enum) {
 // FIXME: Tag decls should be chained to any simultaneous vardecls, e.g.:
 // enum X { A, B, C } D;D should chain to X.
@@ -14317,12 +14316,6 @@
 else if (getLangOpts().CPlusPlus)
   DiagID = diag::err_forward_ref_enum;
 Diag(Loc, DiagID);
-
-// If this is a forward-declared reference to an enumeration, make a
-// note of it; we won't actually be introducing the declaration into
-// the declaration context.
-if (TUK == TUK_Reference)
-  IsForwardReference = true;
   }
 }
 
@@ -14480,9 +14473,7 @@
 PushOnScopeChains(New, EnclosingScope, /* AddToContext = */ false);
   } else if (Name) {
 S = getNonFieldDeclScope(S);
-PushOnScopeChains(New, S, !IsForwardReference);
-if (IsForwardReference)
-  SearchDC->makeDeclVisibleInContext(New);
+PushOnScopeChains(New, S, true);
   } else {
 CurContext->addDecl(New);
   }


Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -239,6 +239,15 @@
 	ENUM2_c = 0x1 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
 };
 
+namespace NsEnumForwardDecl {
+  enum E *p; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
+  extern E e;
+}
+// Clang used to complain that NsEnumForwardDecl::E was undeclared below.
+NsEnumForwardDecl::E NsEnumForwardDecl_e;
+namespace NsEnumForwardDecl {
+  extern E e;
+}
 
 namespace PR11791 {
   template
Index: test/Sema/ast-print.c
===
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -4,6 +4,8 @@
 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field designator extension}}"
 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is deprecated}}"
 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been explicitly

[PATCH] D46919: [libclang] Deprecate CXPrintingPolicy_IncludeTagDefinition

2018-06-19 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 151979.
jdenny added a comment.

Rebased.  Ping.


https://reviews.llvm.org/D46919

Files:
  include/clang-c/Index.h
  include/clang/AST/PrettyPrinter.h
  lib/AST/DeclPrinter.cpp
  lib/AST/TypePrinter.cpp
  tools/c-index-test/c-index-test.c

Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -99,8 +99,6 @@
CXPrintingPolicy_SuppressSpecifiers},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSTAGKEYWORD",
CXPrintingPolicy_SuppressTagKeyword},
-  {"CINDEXTEST_PRINTINGPOLICY_INCLUDETAGDEFINITION",
-   CXPrintingPolicy_IncludeTagDefinition},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSSCOPE",
CXPrintingPolicy_SuppressScope},
   {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSUNWRITTENSCOPE",
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AST/TypePrinter.cpp
@@ -454,7 +454,7 @@
 OS << '(';
 
   PrintingPolicy InnerPolicy(Policy);
-  InnerPolicy.IncludeTagDefinition = false;
+  InnerPolicy.State.PrintOwnedTagDecl = false;
   TypePrinter(InnerPolicy).print(QualType(T->getClass(), 0), OS, StringRef());
 
   OS << "::*";
@@ -1054,9 +1054,9 @@
 }
 
 void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition) {
+  if (Policy.State.PrintOwnedTagDecl) {
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.State.PrintOwnedTagDecl = false;
 D->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
@@ -1209,35 +1209,34 @@
 
 void TypePrinter::printElaboratedBefore(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl()) {
+  if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl()) {
 TagDecl *OwnedTagDecl = T->getOwnedTagDecl();
 assert(OwnedTagDecl->getTypeForDecl() == T->getNamedType().getTypePtr() &&
"OwnedTagDecl expected to be a declaration for the type");
 PrintingPolicy SubPolicy = Policy;
-SubPolicy.IncludeTagDefinition = false;
+SubPolicy.State.PrintOwnedTagDecl = false;
 OwnedTagDecl->print(OS, SubPolicy, Indentation);
 spaceBeforePlaceHolder(OS);
 return;
   }
 
   // The tag definition will take care of these.
-  if (!Policy.IncludeTagDefinition)
-  {
+  if (!Policy.State.PrintOwnedTagDecl) {
 OS << TypeWithKeyword::getKeywordName(T->getKeyword());
 if (T->getKeyword() != ETK_None)
   OS << " ";
 NestedNameSpecifier *Qualifier = T->getQualifier();
 if (Qualifier)
   Qualifier->print(OS, Policy);
   }
-  
+
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printBefore(T->getNamedType(), OS);
 }
 
 void TypePrinter::printElaboratedAfter(const ElaboratedType *T,
 raw_ostream &OS) {
-  if (Policy.IncludeTagDefinition && T->getOwnedTagDecl())
+  if (Policy.State.PrintOwnedTagDecl && T->getOwnedTagDecl())
 return;
   ElaboratedTypePolicyRAII PolicyRAII(Policy);
   printAfter(T->getNamedType(), OS);
Index: lib/AST/DeclPrinter.cpp
===
--- lib/AST/DeclPrinter.cpp
+++ lib/AST/DeclPrinter.cpp
@@ -178,12 +178,12 @@
   for ( ; Begin != End; ++Begin) {
 if (isFirst) {
   if(TD)
-SubPolicy.IncludeTagDefinition = true;
+SubPolicy.State.PrintOwnedTagDecl = true;
   SubPolicy.SuppressSpecifiers = false;
   isFirst = false;
 } else {
   if (!isFirst) Out << ", ";
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.State.PrintOwnedTagDecl = false;
   SubPolicy.SuppressSpecifiers = true;
 }
 
@@ -849,7 +849,7 @@
   }
   PrintingPolicy SubPolicy(Policy);
   SubPolicy.SuppressSpecifiers = false;
-  SubPolicy.IncludeTagDefinition = false;
+  SubPolicy.State.PrintOwnedTagDecl = false;
   Init->printPretty(Out, nullptr, SubPolicy, Indentation);
   if ((D->getInitStyle() == VarDecl::CallInit) && !isa(Init))
 Out << ")";
Index: include/clang/AST/PrettyPrinter.h
===
--- include/clang/AST/PrettyPrinter.h
+++ include/clang/AST/PrettyPrinter.h
@@ -93,14 +93,7 @@
   /// \endcode
   bool SuppressTagKeyword : 1;
 
-  /// When true, include the body of a tag definition.
-  ///
-  /// This is used to place the definition of a struct
-  /// in the middle of another declaration as with:
-  ///
-  /// \code
-  /// typedef struct { int x, y; } Point;
-  /// \endcode
+  /// This flag is deprecated and no longer has any effect.
   bool IncludeTagDefinition : 1;
 
   /// Suppresses printing of scope specifiers.
@@ -225,6 +218,25 @@
   /// When true, print the fully qualified name of function declarations.
   /// This is the opposite of SuppressSco

[PATCH] D54764: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: ABataev.
Herald added a subscriber: guansong.

This patch adjusts a test not to depend on deprecated FileCheck
behavior that permits overlapping matches within a block of CHECK-DAG
directives.  Thus, this patch also removes uses of FileCheck's
-allow-deprecated-dag-overlap command-line option.

Specifically, the FileCheck variables DBG_LOC_START, DBG_LOC_END, and 
DBG_LOC_CANCEL were all set to the same value.  As a result, three
TERM_DEBUG-DAG patterns, one for each variable, all matched the same
text under the old overlapping behavior.  Under the new 
non-overlapping behavior, that's not permitted.  This patch's solution
is to replace these variables with one variable and replace these
patterns with one pattern.

While I have attempted to preserve this test's original intent, I
might have misunderstood something, so please point out any problems.
Your explanation might prove helpful as I address similar issues in
other tests.


Repository:
  rC Clang

https://reviews.llvm.org/D54764

Files:
  clang/test/OpenMP/for_codegen.cpp


Index: clang/test/OpenMP/for_codegen.cpp
===
--- clang/test/OpenMP/for_codegen.cpp
+++ clang/test/OpenMP/for_codegen.cpp
@@ -1,14 +1,14 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck -allow-deprecated-dag-overlap %s 
--check-prefix=CHECK --check-prefix=LIFETIME
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck %s --check-prefix=CHECK 
--check-prefix=LIFETIME
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck -allow-deprecated-dag-overlap %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=TERM_DEBUG
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=PROF-INSTR-PATH
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck %s --check-prefix=TERM_DEBUG
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck %s --check-prefix=PROF-INSTR-PATH
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck 
-allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix 
SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix 
SIMD-ONLY0 %s
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 //
 // expected-no-diagnostics
@@ -385,22 +

[PATCH] D54765: [OpenMP] Update CHECK-DAG usage in target_parallel_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: ABataev.
Herald added a subscriber: guansong.

This patch adjusts a test not to depend on deprecated FileCheck
behavior that permits overlapping matches within a block of CHECK-DAG
directives.  Thus, this patch also removes uses of FileCheck's
-allow-deprecated-dag-overlap command-line option.

There were two issues in this test:

1. There were sets of patterns for store instructions in which a

pattern X could match a superset of a pattern Y.  While X appeared
before Y, Y's intended match appeared before X's intended match.  The 
result was that X matched Y's intended match.  Under the old 
overlapping behavior, Y also matched Y's intended match.  Under the 
new non-overlapping behavior, Y had nothing left to match.  This patch
fixes this by gathering these sets in one place and putting the most
specific patterns (Y) before the more general patterns (X).

2. The CHECK-DAG patterns involving the variables CBPADDR3 and

CBPADDR4 were the same, but there was only one match in the text, so
CBPADDR4 patterns had nothing to match under the new non-overlapping
behavior.  Moreover, a preceding related series of directives had 
variables (SADDR0, BPADDR0, etc.) numbered only 0 through 4, but this
series had variables numbered 0 through 5.  Assuming CBPADDR4's
directives were not intended, this patch removes them.

While I have attempted to preserve this test's original intent, I
might have misunderstood something, so please point out any problems.
Your explanation might prove helpful as I address similar issues in
other tests.


Repository:
  rC Clang

https://reviews.llvm.org/D54765

Files:
  clang/test/OpenMP/target_parallel_codegen.cpp

Index: clang/test/OpenMP/target_parallel_codegen.cpp
===
--- clang/test/OpenMP/target_parallel_codegen.cpp
+++ clang/test/OpenMP/target_parallel_codegen.cpp
@@ -1,37 +1,37 @@
 // Test host codegen.
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-64
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 

[PATCH] D54764: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D54764#1304573, @ABataev wrote:

> I'm fine with the patch,


Thanks for the quick reviews.  I'll push soon.

> the original intention was to handle a possible situation where we may have 
> several debug locations with the same line numbers.

We were afraid of that.  If we find we really need this use case, we'll have to 
find a nicer way to express it.  For reference, this use case is discussed 
under S1 here:

http://lists.llvm.org/pipermail/llvm-dev/2018-May/123258.html


Repository:
  rC Clang

https://reviews.llvm.org/D54764



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


[PATCH] D54765: [OpenMP] Update CHECK-DAG usage in target_parallel_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347351: [OpenMP] Update CHECK-DAG usage in 
target_parallel_codegen.cpp (authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54765?vs=174817&id=174837#toc

Repository:
  rC Clang

https://reviews.llvm.org/D54765

Files:
  test/OpenMP/target_parallel_codegen.cpp

Index: test/OpenMP/target_parallel_codegen.cpp
===
--- test/OpenMP/target_parallel_codegen.cpp
+++ test/OpenMP/target_parallel_codegen.cpp
@@ -1,37 +1,37 @@
 // Test host codegen.
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-64
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -ve

[PATCH] D54764: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347350: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp 
(authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54764?vs=174816&id=174836#toc

Repository:
  rC Clang

https://reviews.llvm.org/D54764

Files:
  test/OpenMP/for_codegen.cpp


Index: test/OpenMP/for_codegen.cpp
===
--- test/OpenMP/for_codegen.cpp
+++ test/OpenMP/for_codegen.cpp
@@ -1,14 +1,14 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck -allow-deprecated-dag-overlap %s 
--check-prefix=CHECK --check-prefix=LIFETIME
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck %s --check-prefix=CHECK 
--check-prefix=LIFETIME
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck -allow-deprecated-dag-overlap %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=TERM_DEBUG
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=PROF-INSTR-PATH
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck %s --check-prefix=TERM_DEBUG
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck %s --check-prefix=PROF-INSTR-PATH
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck 
-allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix 
SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix 
SIMD-ONLY0 %s
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 //
 // expected-no-diagnostics
@@ -385,22 +385,20 @@
 #pragma omp parallel
 #pragma omp for schedule(static, 5)
   // TERM_DEBUG-NOT: __kmpc_global_thread_num
-  // TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg 
[[DBG_LOC_START:![0-9]+]]
+  // TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg 
[[DBG_LOC:![0-9]+]]
   // TERM_DEBUG: invoke i32 {{.*}}foo{{.*}}()
   // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
   // TERM_DEBUG-NOT: __kmpc_global_thread_num
-  // TERM_DEBUG: call void @__kmpc_for_static_fini({{.+}}), !dbg 
[[DBG_LOC_END:![0-9]+]]
-  // TERM_DEBUG: call {{.+}} @__kmpc_barrier({{.+}}), !dbg 
[[DBG_LOC_CANCEL:![0-9]+]]
+  // TERM_DEBUG: call void @__kmpc_for_static_fini({{.+}}), !dbg 
[[DBG_LOC]]
+  // TERM_DEBUG

[PATCH] D55269: [CUDA][OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu

2018-12-04 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: ABataev, Hahnfeld, tra, sylvestre.ledru.
Herald added a subscriber: guansong.

D40453  (r319317) was meant to handle 
nvidia-cuda-toolkit's split CUDA
installation in Debian.  This patch addresses two issues left
unresolved by D40453 , at least on my Ubuntu 
18.04.1 installation:

1. IsDebian() doesn't include IsUbuntu(), so D40453 
 doesn't help me.

2. When `--cuda-path=/usr` is meant to find the nvidia-cuda-toolkit 
installation, the split installation isn't handled.

Issue 2 occurs when I follow step 4 in the following guide to rebuild
the OpenMP runtime with clang to build bitcode libraries:

https://www.hahnjo.de/blog/2018/10/08/clang-7.0-openmp-offloading-nvidia.html

The reason is that
`libomptarget/cmake/Modules/LibomptargetNVPTXBitcodeLibrary.cmake`
then specifies `--cuda-path=/usr` when testing clang, but it would
need to leave `--cuda-path` unspecified to trigger D40453 
's fix.
Perhaps that cmake file could be adjusted instead, but the fix in this
patch is more general.

Obviously, this isn't the first time this issue has been discussed,
but googling didn't reveal to me a definitive answer on the path
forward.  Proposing this patch seems like the easiest way to ask.


Repository:
  rC Clang

https://reviews.llvm.org/D55269

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -80,9 +80,19 @@
   // In decreasing order so we prefer newer versions to older versions.
   std::initializer_list Versions = {"8.0", "7.5", "7.0"};
 
+  // Special case for Debian to have nvidia-cuda-toolkit work
+  // out of the box. More info on http://bugs.debian.org/882505
+  const char *NvidiaCudaToolkit =
+  (Distro(D.getVFS()).IsDebian() || Distro(D.getVFS()).IsUbuntu())
+  ? "/usr/lib/cuda"
+  : nullptr;
+
   if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) {
-Candidates.emplace_back(
-Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str());
+std::string CudaPath =
+Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str();
+Candidates.emplace_back(CudaPath);
+if (NvidiaCudaToolkit && CudaPath == "/usr")
+  Candidates.emplace_back(D.SysRoot + NvidiaCudaToolkit);
   } else if (HostTriple.isOSWindows()) {
 for (const char *Ver : Versions)
   Candidates.emplace_back(
@@ -114,10 +124,8 @@
 for (const char *Ver : Versions)
   Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
 
-if (Distro(D.getVFS()).IsDebian())
-  // Special case for Debian to have nvidia-cuda-toolkit work
-  // out of the box. More info on http://bugs.debian.org/882505
-  Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");
+if (NvidiaCudaToolkit)
+  Candidates.emplace_back(D.SysRoot + NvidiaCudaToolkit);
   }
 
   bool NoCudaLib = Args.hasArg(options::OPT_nocudalib);


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -80,9 +80,19 @@
   // In decreasing order so we prefer newer versions to older versions.
   std::initializer_list Versions = {"8.0", "7.5", "7.0"};
 
+  // Special case for Debian to have nvidia-cuda-toolkit work
+  // out of the box. More info on http://bugs.debian.org/882505
+  const char *NvidiaCudaToolkit =
+  (Distro(D.getVFS()).IsDebian() || Distro(D.getVFS()).IsUbuntu())
+  ? "/usr/lib/cuda"
+  : nullptr;
+
   if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) {
-Candidates.emplace_back(
-Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str());
+std::string CudaPath =
+Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str();
+Candidates.emplace_back(CudaPath);
+if (NvidiaCudaToolkit && CudaPath == "/usr")
+  Candidates.emplace_back(D.SysRoot + NvidiaCudaToolkit);
   } else if (HostTriple.isOSWindows()) {
 for (const char *Ver : Versions)
   Candidates.emplace_back(
@@ -114,10 +124,8 @@
 for (const char *Ver : Versions)
   Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
 
-if (Distro(D.getVFS()).IsDebian())
-  // Special case for Debian to have nvidia-cuda-toolkit work
-  // out of the box. More info on http://bugs.debian.org/882505
-  Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");
+if (NvidiaCudaToolkit)
+  Candidates.emplace_back(D.SysRoot + NvidiaCudaToolkit);
   }
 
   bool NoCudaLib = Args.hasArg(options::OPT_nocudalib);
___
cfe-commits mailing list
cfe-commits@lists.llvm.or

[PATCH] D55269: [CUDA][OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu

2018-12-04 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

@tra, @Hahnfeld: Thanks for your replies.

In D55269#1318901 , @tra wrote:

> I'm not sure that's something that needs to be fixed in clang.
>
> IIUIC, Debian has added a shim that pretends to be a monolithic CUDA install:
>  https://bugs.launchpad.net/ubuntu/+source/clang/+bug/1706326
>  That change seems to be in Ubuntu bionic (18.04) 
> https://packages.ubuntu.com/en/bionic/nvidia-cuda-toolkit


apt confirms that's what I have: nvidia-cuda-toolkit 9.1.85-3ubuntu1

> With that fix in place --cuda-path=/usr/lib/cuda should work.

Seems to.  To be clear, I'm trying to address the use case where cmake/clang 
finds the cuda installation automatically.

> --cuda-path=/usr was never supposed to work -- /usr is *not* the root of the 
> CUDA SDK.

/usr/lib/cuda/bin/nvcc doesn't exist, so that's probably why FindCUDA.cmake 
finds /usr/bin/nvcc (also installed by nvidia-cuda-toolkit).  Is it fair then 
to say that /usr/lib/cuda isn't the root either?

> I guess that just adding the check for isUbuntu() should make clang work on 
> Ubuntu 18.04+.

It fixes the first issue I reported.  It does not fix the second.

It seems that nvidia-cuda-toolkit still isn't installing a complete CUDA 
install in one location.  Even if it installed it all to /usr/lib/cuda, 
FindCUDA.cmake would probably still see /usr/bin/nvcc and assume /usr is the 
CUDA install root.

What's the path forward?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55269



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


[PATCH] D55269: [CUDA][OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu

2018-12-04 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

By the way, nvidia-cuda-toolkit does install the following, but there's no nvvm 
directory as clang currently expects:

  /usr/lib/nvidia-cuda-toolkit
  /usr/lib/nvidia-cuda-toolkit/bin
  /usr/lib/nvidia-cuda-toolkit/bin/cicc
  /usr/lib/nvidia-cuda-toolkit/bin/crt
  /usr/lib/nvidia-cuda-toolkit/bin/crt/link.stub
  /usr/lib/nvidia-cuda-toolkit/bin/crt/prelink.stub
  /usr/lib/nvidia-cuda-toolkit/bin/g++
  /usr/lib/nvidia-cuda-toolkit/bin/gcc
  /usr/lib/nvidia-cuda-toolkit/bin/nvcc
  /usr/lib/nvidia-cuda-toolkit/bin/nvcc.profile
  /usr/lib/nvidia-cuda-toolkit/libdevice
  /usr/lib/nvidia-cuda-toolkit/libdevice/libdevice.10.bc


Repository:
  rC Clang

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

https://reviews.llvm.org/D55269



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


[PATCH] D55269: [CUDA][OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu

2018-12-04 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D55269#1319252 , @tra wrote:

> It appears that what you're trying to do is to add "/usr/lib/cuda" on Ubuntu 
> and Debian when --cuda-path=/usr is specified.
>  This is a rather odd thing to do.


My real goal is to get clang and openmp working out of the box on Ubuntu.  
Treating --cuda-path=/usr as a special case was just a way to get there.  It's 
odd apparently because nvidia-cuda-toolkit is odd.

> In the end only one of those paths will be in effect and that's the path that 
> should be specified via --cuda-path. The fact that you want to add 
> /usr/cuda/lib in this case suggests that /usr is the wrong path and 
> /usr/lib/cuda is the correct one. It sounds like you need to change your 
> build system and tell clang the correct path.
> 
> I do not think that changing clang to work around an issue in cmake files of 
> one project is something we want to do.

I don't have a separate project using cmake.  The cmake files I'm referring to 
are clang's.  I'm just trying to make it easy to build clang and openmp and 
call clang on the command line under Ubuntu.

> There is also an easy workaround. Just download CUDA SDK, install it into a 
> local directory and point your build system there. This will work on any 
> linux distribution.

An easier workaround is to specify CUDA_TOOLKIT_ROOT_DIR when building llvm, 
but my goal is make building on Ubuntu work without special configuration.  
D40453  was my hint that people already agreed 
that's a worthwhile pursuit.

I'm not adamant that handling --cuda-path=/usr is the right solution.  But just 
adding IsUbuntu() is not a full solution, so I'm looking for advice on how to 
proceed.

Thanks for your responses.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55269



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


[PATCH] D55269: [CUDA][OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu

2018-12-04 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D55269#1319319 , @jdenny wrote:

> > I do not think that changing clang to work around an issue in cmake files 
> > of one project is something we want to do.
>
> I don't have a separate project using cmake.  The cmake files I'm referring 
> to are clang's.


... and opemp's.  Is that the one project you meant?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55269



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


[PATCH] D55269: [CUDA][OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu

2018-12-04 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D55269#1319382 , @tra wrote:

> Let's start with fixing OpenMP's cmake files. Once it no longer insists on 
> specifying --cuda-path=/usr, and isUbuntu is in place, what is the remaining 
> failure that you see?


I'm fairly certain I would see no remaining failure then, but it's not clear to 
me how we should convince OpenMP's cmake files to stop doing that.

openmp/libomptarget/cmake/Modules/LibomptargetNVPTXBitcodeLibrary.cmake is the 
file, and there's one occurrence of --cuda-path.

If CUDA_TOOLKIT_ROOT_DIR is specified explicitly to cmake, that --cuda-path is 
necessary, so we cannot just remove it.

If CUDA_TOOLKIT_ROOT_DIR is not specified explicitly, it is computed by cmake.  
So I believe this boils down to getting cmake to find the right CUDA root on 
Debian/Ubuntu.

Do you agree so far?

Would you recommend submitting a patch to cmake's CUDA support?  Or would you 
recommend replicating clang's logic from D40453 
 into openmp's cmake files, overriding cmake's 
own selection of CUDA_TOOLKIT_ROOT_DIR?


Repository:
  rC Clang

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

https://reviews.llvm.org/D55269



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


[PATCH] D55269: [CUDA][OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu

2018-12-04 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D55269#1319452 , @tra wrote:

> In D55269#1319437 , @jdenny wrote:
>
> >
>
>
> That may be a bigger can of works than a single patch can solve. The good 
> news is that the maintainer of CUDA support in cmake is working on adding 
> clang support. So, things may improve soon.


To summarize all this as I understand it: It sounds like anything we do now for 
the cmake issue would be a short-term solution because cmake might later 
present a better solution.  Originally, I figured the easiest place to work 
around this issue was clang as that would help anyone who detects a CUDA 
installation using current cmake support.  You prefer to do it in OpenMP's 
cmake files, which I suppose would help avoid any unexpected consequences from 
my change to clang.  A third alternative is to just wait for cmake to improve.

For now, I'll trim this patch to just the IsUbuntu() part (maybe tomorrow), and 
we can think more about the cmake side of things.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55269



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


[PATCH] D55269: [CUDA] Fix nvidia-cuda-toolkit detection on Ubuntu

2018-12-05 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 176916.
jdenny retitled this revision from "[CUDA][OpenMP] Fix nvidia-cuda-toolkit 
detection on Debian/Ubuntu" to "[CUDA] Fix nvidia-cuda-toolkit detection on 
Ubuntu".
jdenny edited the summary of this revision.
jdenny added a comment.

Apply reviewer suggestion.


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

https://reviews.llvm.org/D55269

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -114,7 +114,7 @@
 for (const char *Ver : Versions)
   Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
 
-if (Distro(D.getVFS()).IsDebian())
+if (Distro(D.getVFS()).IsDebian() || Distro(D.getVFS()).IsUbuntu())
   // Special case for Debian to have nvidia-cuda-toolkit work
   // out of the box. More info on http://bugs.debian.org/882505
   Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -114,7 +114,7 @@
 for (const char *Ver : Versions)
   Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
 
-if (Distro(D.getVFS()).IsDebian())
+if (Distro(D.getVFS()).IsDebian() || Distro(D.getVFS()).IsUbuntu())
   // Special case for Debian to have nvidia-cuda-toolkit work
   // out of the box. More info on http://bugs.debian.org/882505
   Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55269: [CUDA] Fix nvidia-cuda-toolkit detection on Ubuntu

2018-12-06 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348504: [CUDA] Fix nvidia-cuda-toolkit detection on Ubuntu 
(authored by jdenny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55269?vs=176916&id=176999#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55269

Files:
  cfe/trunk/lib/Driver/ToolChains/Cuda.cpp


Index: cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
@@ -114,7 +114,7 @@
 for (const char *Ver : Versions)
   Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
 
-if (Distro(D.getVFS()).IsDebian())
+if (Distro(D.getVFS()).IsDebian() || Distro(D.getVFS()).IsUbuntu())
   // Special case for Debian to have nvidia-cuda-toolkit work
   // out of the box. More info on http://bugs.debian.org/882505
   Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");


Index: cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
@@ -114,7 +114,7 @@
 for (const char *Ver : Versions)
   Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
 
-if (Distro(D.getVFS()).IsDebian())
+if (Distro(D.getVFS()).IsDebian() || Distro(D.getVFS()).IsUbuntu())
   // Special case for Debian to have nvidia-cuda-toolkit work
   // out of the box. More info on http://bugs.debian.org/882505
   Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55269: [CUDA] Fix nvidia-cuda-toolkit detection on Ubuntu

2018-12-06 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D55269#1320382 , @tra wrote:

> >> Let's start with fixing OpenMP's cmake files. Once it no longer insists on 
> >> specifying --cuda-path=/usr, and isUbuntu is in place, what is the 
> >> remaining failure that you see?
> > 
> > I disagree here: It's not OpenMP but CMake that's detecting the wrong path 
> > here. This is the place to fix it once and for all (and possibly get the 
> > shim package right in that process).
>
> It's somewhat orthogonal, IMO. I agree that it's not OpenMP's problem. Cmake 
> will fix it at some point in future, but, presumably, we want OpenMP 
> buildable *now*. Adding a temporary workaround for something that Cmake can't 
> handle now would make building OpenMP with clang somewhat easier which was 
> the end goal of this patch. In the end it's up to OpenMP maintainers what 
> they would want to do.


I don't know when I'll explore the cmake problem further.  If someone else 
decides to, please cc/subscribe me.

Thanks for the reviews.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55269



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


[PATCH] D59168: [runtimes] Move libunwind, libc++abi and libc++ to lib/clang/ and include/

2019-03-13 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny accepted this revision.
jdenny added a comment.

In D59168#1423587 , @phosek wrote:

> I'm not super enthusiastic about the duplicated triple, but the only way to 
> eliminate it would be to move the Clang resource directory inside of 
> `lib/clang/x86_64-linux-gnu`, i.e. we'd have 
> `lib/clang/x86_64-linux-gnu/9.0.0/{include,lib}`.


`lib/x86_64-linux-gnu/clang/9.0.0/{include,lib}` would mean less duplication of 
the triple within system directories.  Is there a reason not to do that?  I'm 
not necessarily advocating for this.  I'm just trying to understand what you've 
chosen.

In D59168#1425701 , @phosek wrote:

> In D59168#1424968 , @smeenai wrote:
>
> > I don't think the duplicated triple is too huge of a deal. I think the 
> > layout where the resource directory is moved inside the triple directory is 
> > a bit nicer, but I also don't know how much work that change would be and 
> > if it's worth it.
>
>
> One downside is that we would be duplicating Clang resource headers for each 
> target which may not be too big of a deal but something worth mentioning.


In that case, could we symlink the target-specific include directories to a 
common directory?

Regardless of these points, your patch appears to strictly improve the 
situation, so maybe we should see how things go with it and then make further 
changes later if desired.

So, LGTM modulo the question I added inline.  Thanks.




Comment at: libcxx/lib/CMakeLists.txt:407
   install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${filesystem_lib} 
${experimental_lib}
-LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} 
COMPONENT cxx
-ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} 
COMPONENT cxx
+LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} 
COMPONENT cxx
+ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} 
COMPONENT cxx

Assume LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=True.

Without your patch, it looks to me like specifying LIBCXX_INSTALL_PREFIX 
collapses the library destination from `$prefix/lib/clang/$version/$triple/lib` 
to `$prefix/lib`.

With your patch, it looks to me like the library destination is always 
`$prefix/lib/clang/$triple`, and specifying LIBCXX_INSTALL_PREFIX simply 
changes `$prefix`.

Is that correct?  If so, is that worthwhile to note in the summary?


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

https://reviews.llvm.org/D59168



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


[PATCH] D55269: [CUDA] Fix nvidia-cuda-toolkit detection on Ubuntu

2019-03-14 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.
Herald added a project: LLVM.

In D55269#1320382 , @tra wrote:

> In D55269#1320207 , @Hahnfeld wrote:
>
> > In D55269#1319109 , @jdenny wrote:
> >
> > > [...]
> > >
> > > In D55269#1318901 , @tra wrote:
> > >
> > > > --cuda-path=/usr was never supposed to work -- /usr is *not* the root 
> > > > of the CUDA SDK.
> > >
> > >
> > > /usr/lib/cuda/bin/nvcc doesn't exist, so that's probably why 
> > > FindCUDA.cmake finds /usr/bin/nvcc (also installed by 
> > > nvidia-cuda-toolkit).  Is it fair then to say that /usr/lib/cuda isn't 
> > > the root either?
> > >
> > > [...]
> > >
> > > It seems that nvidia-cuda-toolkit still isn't installing a complete CUDA 
> > > install in one location.  Even if it installed it all to /usr/lib/cuda, 
> > > FindCUDA.cmake would probably still see /usr/bin/nvcc and assume /usr is 
> > > the CUDA install root.
> >
> >
> > I think this needs to be fixed then: The shim package should provide links 
> > to all necessary things and CMake must be prepared to deal with it. IMO we 
> > shouldn't workaround broken build system detection in the compiler.
>
>
> That's exactly what I proposed to Debian folks 
> https://bugs.llvm.org/show_bug.cgi?id=26966#c6 and I was under impression 
> that that's what they did. It appears that they only created an empty 
> directory structure with version.txt in it. At least that's what I see when I 
> unpack nvidia-cuda-toolkit_9.1.85-3ubuntu1_amd64.deb. Perhaps they do 
> something extra in the install script, but I didn't find anything obvious in 
> the deb itself.
>
> > 
> > 
> > In D55269#1319116 , @jdenny wrote:
> > 
> >> By the way, nvidia-cuda-toolkit does install the following, but there's no 
> >> nvvm directory as clang currently expects:
> > 
> > 
> > Then again the distro's packaging is broken and needs to be adjusted.
>
> Perhaps we can build a shim package ourselves and distribute it along with 
> the clang. This would decouple usability of clang from the Ubuntu/Debian 
> release process and would make it possible to make clang work with CUDA on 
> older debian/Ubuntu versions.
>
> >> Let's start with fixing OpenMP's cmake files. Once it no longer insists on 
> >> specifying --cuda-path=/usr, and isUbuntu is in place, what is the 
> >> remaining failure that you see?
> > 
> > I disagree here: It's not OpenMP but CMake that's detecting the wrong path 
> > here. This is the place to fix it once and for all (and possibly get the 
> > shim package right in that process).
>
> It's somewhat orthogonal, IMO. I agree that it's not OpenMP's problem. Cmake 
> will fix it at some point in future, but, presumably, we want OpenMP 
> buildable *now*. Adding a temporary workaround for something that Cmake can't 
> handle now would make building OpenMP with clang somewhat easier which was 
> the end goal of this patch. In the end it's up to OpenMP maintainers what 
> they would want to do.


For openmp, I worked around the aforementioned cmake limitation in D55588 
.

I reported the aforementioned problem with the Ubuntu package 
nvidia-cuda-toolkit in December at:

https://bugs.launchpad.net/ubuntu/+source/nvidia-cuda-toolkit/+bug/1808999

Today, I received a response (included at the above link) that this is not a 
valid bug and that clang++ works fine with nvidia-cuda-toolkit.  I suppose the 
latter half is true, but the point is that we're having to work around the 
strange Debian/Ubuntu packaging in both Clang and our cmake files.  Do people 
here think it's worth pursuing this point further with Debian/Ubuntu package 
maintainers?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55269



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


[PATCH] D59712: [APSInt][OpenMP] Fix isNegative, etc. for unsigned types

2019-03-22 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: ABataev, chandlerc, craig.topper.
Herald added subscribers: jdoerfert, dexonsmith, guansong.
Herald added a project: LLVM.

Without this patch, APSInt inherits APInt::isNegative, which merely
checks the sign bit without regard to whether the type is actually
signed.  isNonNegative and isStrictlyPositive call isNegative and so
are also affected.

This patch adjusts APSInt to override isNegative, isNonNegative, and 
isStrictlyPositive with implementations that consider whether the type
is signed.

A large set of Clang OpenMP tests are affected.  Without this patch,
these tests assume that `true` is not a valid argument for clauses
like `collapse`.  Indeed, `true` fails APInt::isStrictlyPositive but 
not APSInt::isStrictlyPositive.  This patch adjusts those tests to
assume `true` should be accepted.


https://reviews.llvm.org/D59712

Files:
  clang/test/OpenMP/distribute_collapse_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_collapse_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_collapse_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_safelen_messages.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_simdlen_messages.cpp
  clang/test/OpenMP/distribute_simd_collapse_messages.cpp
  clang/test/OpenMP/distribute_simd_safelen_messages.cpp
  clang/test/OpenMP/distribute_simd_simdlen_messages.cpp
  clang/test/OpenMP/for_collapse_messages.cpp
  clang/test/OpenMP/for_ordered_clause.cpp
  clang/test/OpenMP/for_simd_collapse_messages.cpp
  clang/test/OpenMP/for_simd_safelen_messages.cpp
  clang/test/OpenMP/for_simd_simdlen_messages.cpp
  clang/test/OpenMP/parallel_for_collapse_messages.cpp
  clang/test/OpenMP/parallel_for_ordered_messages.cpp
  clang/test/OpenMP/parallel_for_simd_collapse_messages.cpp
  clang/test/OpenMP/parallel_for_simd_safelen_messages.cpp
  clang/test/OpenMP/parallel_for_simd_simdlen_messages.cpp
  clang/test/OpenMP/simd_collapse_messages.cpp
  clang/test/OpenMP/simd_safelen_messages.cpp
  clang/test/OpenMP/simd_simdlen_messages.cpp
  clang/test/OpenMP/target_parallel_for_collapse_messages.cpp
  clang/test/OpenMP/target_parallel_for_ordered_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_collapse_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_ordered_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_safelen_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_simdlen_messages.cpp
  clang/test/OpenMP/target_simd_collapse_messages.cpp
  clang/test/OpenMP/target_simd_safelen_messages.cpp
  clang/test/OpenMP/target_simd_simdlen_messages.cpp
  clang/test/OpenMP/target_teams_distribute_collapse_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_messages.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_collapse_messages.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_safelen_messages.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_simd_simdlen_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_collapse_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_safelen_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_simdlen_messages.cpp
  clang/test/OpenMP/taskloop_collapse_messages.cpp
  clang/test/OpenMP/taskloop_simd_collapse_messages.cpp
  clang/test/OpenMP/taskloop_simd_safelen_messages.cpp
  clang/test/OpenMP/taskloop_simd_simdlen_messages.cpp
  clang/test/OpenMP/teams_distribute_collapse_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_collapse_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_collapse_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_safelen_messages.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_simdlen_messages.cpp
  clang/test/OpenMP/teams_distribute_simd_collapse_messages.cpp
  clang/test/OpenMP/teams_distribute_simd_safelen_messages.cpp
  clang/test/OpenMP/teams_distribute_simd_simdlen_messages.cpp
  llvm/include/llvm/ADT/APSInt.h

Index: llvm/include/llvm/ADT/APSInt.h
===
--- llvm/include/llvm/ADT/APSInt.h
+++ llvm/include/llvm/ADT/APSInt.h
@@ -42,6 +42,24 @@
   /// \param Str the string to be interpreted.
   explicit APSInt(StringRef Str);
 
+  /// Determine sign of this APSInt.
+  ///
+  /// \returns true if this APSInt is negative, false otherwise
+  bool isNegative() const { return isSigned() && APInt::isNegative(); }
+
+  /// Determine if this APSInt Value is non-negative (>= 0)
+  ///
+  /// \returns true if this APSInt is non-negative, false otherwise
+  bool isNonNegative() const { return !isNegative(); }
+
+  /// Determine if this APSInt Value is positive.
+  ///
+  /// This tests if the value of this APSInt is positive (> 0). Note
+  /// that 0 is not a positive value.
+  ///
+  /// \returns true if this APSInt is positive.
+  bool isStrictlyPositive() const { return isNonNegative() && !isNullValue(); }
+
   

  1   2   3   4   5   >