[PATCH] D66516: [clangd] Added highlighting to types dependant on templates.

2019-08-31 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:177
   return;
+if (TP->isPointerType() || TP->isLValueReferenceType())
+  // When highlighting dependant template types the type can be a pointer 
or

ilya-biryukov wrote:
> jvikstrom wrote:
> > ilya-biryukov wrote:
> > > ilya-biryukov wrote:
> > > > jvikstrom wrote:
> > > > > ilya-biryukov wrote:
> > > > > > jvikstrom wrote:
> > > > > > > ilya-biryukov wrote:
> > > > > > > > jvikstrom wrote:
> > > > > > > > > ilya-biryukov wrote:
> > > > > > > > > > `RecursiveASTVisitor` also traverses the pointer and 
> > > > > > > > > > reference types, why does it not reach the inner 
> > > > > > > > > > `TemplateTypeParmType` in the cases you describe?
> > > > > > > > > The D in `using D = ...` `typedef ... D` does not have a 
> > > > > > > > > TypeLoc (at least not one that is visited). Therefore we use 
> > > > > > > > > the VisitTypedefNameDecl (line 121) to get the location of 
> > > > > > > > > `D` to be able to highlight it. And we just send the typeLocs 
> > > > > > > > > typeptr to addType (which is a Pointer for `using D = T*;`)...
> > > > > > > > > 
> > > > > > > > > But maybe we should get the underlying type before we call 
> > > > > > > > > addType with TypePtr? Just a while loop on line 123 basically 
> > > > > > > > > (can we have multiple PointerTypes nested in each other 
> > > > > > > > > actually?)
> > > > > > > > > 
> > > > > > > > > Even if we keep it in addType the comment is actually wrong, 
> > > > > > > > > because it obviously works when for the actual "type 
> > > > > > > > > occurrences" for `D` (so will fix that no matter what). This 
> > > > > > > > > recursion will just make us add more duplicate tokens...
> > > > > > > > Could we investigate why `RecursiveASTVisitor` does not visit 
> > > > > > > > the `TypeLoc` of a corresponding decl?
> > > > > > > > Here's the code from `RecursiveASTVisitor.h` that should do the 
> > > > > > > > trick:
> > > > > > > > ```
> > > > > > > > DEF_TRAVERSE_DECL(TypeAliasDecl, {
> > > > > > > >   TRY_TO(TraverseTypeLoc(D->getTypeSourceInfo()->getTypeLoc()));
> > > > > > > >   // We shouldn't traverse D->getTypeForDecl(); it's a result of
> > > > > > > >   // declaring the type alias, not something that was written 
> > > > > > > > in the
> > > > > > > >   // source.
> > > > > > > > })
> > > > > > > > ```
> > > > > > > > 
> > > > > > > > If it doesn't, we are probably holding it wrong.
> > > > > > > There just doesn't seem to be a TypeLoc for the typedef'ed Decl.  
> > > > > > > We can get the `T*` TypeLoc (with 
> > > > > > > `D->getTypeSourceInfo()->getTypeLoc()`). But there isn't one for 
> > > > > > > `D`. Even the `D->getTypeForDecl` returns null.
> > > > > > > 
> > > > > > > And I have no idea where I'd even start debugging that. Or if 
> > > > > > > it's even a bug
> > > > > > > 
> > > > > > I may have misinterpreted the patch. Are we trying to add 
> > > > > > highlightings for the names of using aliases here? E.g. for the 
> > > > > > following range:
> > > > > > ```
> > > > > > template 
> > > > > > struct Foo {
> > > > > >   using [[D]] = T**;
> > > > > > };
> > > > > > ```
> > > > > > 
> > > > > > Why isn't this handled in `VisitNamedDecl`?
> > > > > > We don't seem to call this function for `TypedefNameDecl` at all 
> > > > > > and it actually weird. Is this because we attempt to highlight 
> > > > > > typedefs as their underlying types?
> > > > > So currently using aliases and typedefs are highlighted the same as 
> > > > > the underlying type (in most cases). One case where they aren't is 
> > > > > when the underlying type is a template parameter (which is what this 
> > > > > patch is trying to solve).
> > > > > 
> > > > > 
> > > > > > Why isn't this handled in VisitNamedDecl?
> > > > > 
> > > > > The Decl is actually visited in `VisitNamedDecl`, however as it is a 
> > > > > `TypeAliasDecl` which we do not have a check for in the addToken 
> > > > > function it will not get highlighted in that visit.
> > > > > 
> > > > > Actually, could add a check for `TypeAliasDecl` in `addToken` (should 
> > > > > probably be a check for `TypedefNameDecl` to cover both `using ...` 
> > > > > and `typedef ...`) and move the code from the `VisitTypedefNameDecl` 
> > > > > to the `addToken` function inside that check instead.
> > > > > 
> > > > > 
> > > > > 
> > > > > > We don't seem to call this function for TypedefNameDecl at all and 
> > > > > > it actually weird. Is this because we attempt to highlight typedefs 
> > > > > > as their underlying types?
> > > > > 
> > > > > 
> > > > > Don't understand what you mean. What function? 
> > > > > So currently using aliases and typedefs are highlighted the same as 
> > > > > the underlying type (in most cases). 
> > > > Thanks for clarifying this. This is where my confusion is coming from.
> > > > A few question to try understanding the approach taken (sorry if that's 
> > 

[PATCH] D66990: [clangd] Add distinct highlightings for declarations of functions and methods

2019-08-31 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

There is precedent for highlighting declarations and uses differently in other 
C++ editors. For example, Eclipse CDT has separate highlightings for function 
and functions declarations (see screenshot below).

Objectively speaking, I think it makes sense to style function declarations 
differently from function uses for emphasis. For example, you can use the same 
color for both, but make the declarations bold. I have found this to aid 
readability.

F9891365: cdt-syntax-color.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66990



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


[PATCH] D67031: [Clang][Bundler] Error reporting improvements

2019-08-31 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev updated this revision to Diff 218250.
sdmitriev added a comment.

Removed trailing '.' from error messages and added few additional changes for 
better error handling.


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

https://reviews.llvm.org/D67031

Files:
  clang/test/Driver/clang-offload-bundler.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -17,6 +17,7 @@
 #include "clang/Basic/Version.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -25,23 +26,23 @@
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/StringSaver.h"
-#include 
+#include "llvm/Support/WithColor.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
-#include 
+#include 
 
 using namespace llvm;
 using namespace llvm::object;
@@ -122,35 +123,36 @@
 
   /// Update the file handler with information from the header of the bundled
   /// file
-  virtual void ReadHeader(MemoryBuffer ) = 0;
+  virtual Error ReadHeader(MemoryBuffer ) = 0;
 
   /// Read the marker of the next bundled to be read in the file. The triple of
   /// the target associated with that bundle is returned. An empty string is
   /// returned if there are no more bundles to be read.
-  virtual StringRef ReadBundleStart(MemoryBuffer ) = 0;
+  virtual Expected>
+  ReadBundleStart(MemoryBuffer ) = 0;
 
   /// Read the marker that closes the current bundle.
-  virtual void ReadBundleEnd(MemoryBuffer ) = 0;
+  virtual Error ReadBundleEnd(MemoryBuffer ) = 0;
 
   /// Read the current bundle and write the result into the stream \a OS.
-  virtual void ReadBundle(raw_fd_ostream , MemoryBuffer ) = 0;
+  virtual Error ReadBundle(raw_fd_ostream , MemoryBuffer ) = 0;
 
   /// Write the header of the bundled file to \a OS based on the information
   /// gathered from \a Inputs.
-  virtual void WriteHeader(raw_fd_ostream ,
-   ArrayRef> Inputs) = 0;
+  virtual Error WriteHeader(raw_fd_ostream ,
+ArrayRef> Inputs) = 0;
 
   /// Write the marker that initiates a bundle for the triple \a TargetTriple to
   /// \a OS.
-  virtual void WriteBundleStart(raw_fd_ostream , StringRef TargetTriple) = 0;
+  virtual Error WriteBundleStart(raw_fd_ostream ,
+ StringRef TargetTriple) = 0;
 
   /// Write the marker that closes a bundle for the triple \a TargetTriple to \a
-  /// OS. Return true if any error was found.
-
-  virtual bool WriteBundleEnd(raw_fd_ostream , StringRef TargetTriple) = 0;
+  /// OS.
+  virtual Error WriteBundleEnd(raw_fd_ostream , StringRef TargetTriple) = 0;
 
   /// Write the bundle from \a Input into \a OS.
-  virtual void WriteBundle(raw_fd_ostream , MemoryBuffer ) = 0;
+  virtual Error WriteBundle(raw_fd_ostream , MemoryBuffer ) = 0;
 };
 
 /// Handler for binary files. The bundled file will have the following format
@@ -222,7 +224,7 @@
 
   ~BinaryFileHandler() final {}
 
-  void ReadHeader(MemoryBuffer ) final {
+  Error ReadHeader(MemoryBuffer ) final {
 StringRef FC = Input.getBuffer();
 
 // Initialize the current bundle with the end of the container.
@@ -231,16 +233,16 @@
 // Check if buffer is smaller than magic string.
 size_t ReadChars = sizeof(OFFLOAD_BUNDLER_MAGIC_STR) - 1;
 if (ReadChars > FC.size())
-  return;
+  return Error::success();
 
 // Check if no magic was found.
 StringRef Magic(FC.data(), sizeof(OFFLOAD_BUNDLER_MAGIC_STR) - 1);
 if (!Magic.equals(OFFLOAD_BUNDLER_MAGIC_STR))
-  return;
+  return Error::success();
 
 // Read number of bundles.
 if (ReadChars + 8 > FC.size())
-  return;
+  return Error::success();
 
 uint64_t NumberOfBundles = Read8byteIntegerFromBuffer(FC, ReadChars);
 ReadChars += 8;
@@ -250,35 +252,35 @@
 
   // Read offset.
   if (ReadChars + 8 > FC.size())
-return;
+return Error::success();
 
   uint64_t Offset = Read8byteIntegerFromBuffer(FC, ReadChars);
   ReadChars += 8;
 
   // Read size.
   if (ReadChars + 8 > FC.size())
-return;
+return Error::success();
 
   uint64_t Size = Read8byteIntegerFromBuffer(FC, 

[PATCH] D66862: Make lround builtin constexpr (and others)

2019-08-31 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver updated this revision to Diff 218231.
zoecarver added a comment.

- add roundl builtins
- add more tests
- address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66862

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/math-builtins.cpp


Index: clang/test/SemaCXX/math-builtins.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/math-builtins.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+int main()
+{
+  constexpr float f1 = 12345.6789;
+  constexpr float f2 = 12345.4321;
+  constexpr float f3 = 0.5;
+  constexpr float f4 = -0.5;
+
+  static_assert(__builtin_llround(f1) == 12346, "");
+  static_assert(__builtin_llroundf(f1) == 12346, "");
+  static_assert(__builtin_llroundl(f1) == 12346, "");
+
+  static_assert(__builtin_lround(f1) == 12346, "");
+  static_assert(__builtin_lroundf(f1) == 12346, "");
+  static_assert(__builtin_lroundl(f1) == 12346, "");
+
+  static_assert(__builtin_llround(f2) == 12345, "");
+  static_assert(__builtin_llroundf(f2) == 12345, "");
+  static_assert(__builtin_llroundl(f2) == 12345, "");
+
+  static_assert(__builtin_lround(f2) == 12345, "");
+  static_assert(__builtin_lroundf(f2) == 12345, "");
+  static_assert(__builtin_lroundl(f2) == 12345, "");
+
+  static_assert(__builtin_llround(f3) == 1, "");
+  static_assert(__builtin_llroundf(f3) == 1, "");
+  static_assert(__builtin_llroundl(f3) == 1, "");
+
+  static_assert(__builtin_lround(f3) == 1, "");
+  static_assert(__builtin_lroundf(f3) == 1, "");
+  static_assert(__builtin_lroundl(f3) == 1, "");
+
+  static_assert(__builtin_llround(f4) == -1, "");
+  static_assert(__builtin_llroundf(f4) == -1, "");
+  static_assert(__builtin_llroundl(f4) == -1, "");
+
+  static_assert(__builtin_lround(f4) == -1, "");
+  static_assert(__builtin_lroundf(f4) == -1, "");
+  static_assert(__builtin_lroundl(f4) == -1, "");
+
+  static_assert(__builtin_llround(__builtin_nanf("")) == 0, ""); // 
expected-error {{static_assert expression is not an integral constant 
expression}}
+  static_assert(__builtin_llroundf(__builtin_nanf("")) == 0, ""); // 
expected-error {{static_assert expression is not an integral constant 
expression}}
+  static_assert(__builtin_llroundl(__builtin_nanf("")) == 0, ""); // 
expected-error {{static_assert expression is not an integral constant 
expression}}
+
+  static_assert(__builtin_lround(__builtin_nanf("")) == 0, ""); // 
expected-error {{static_assert expression is not an integral constant 
expression}}
+  static_assert(__builtin_lroundf(__builtin_nanf("")) == 0, ""); // 
expected-error {{static_assert expression is not an integral constant 
expression}}
+  static_assert(__builtin_lroundl(__builtin_nanf("")) == 0, ""); // 
expected-error {{static_assert expression is not an integral constant 
expression}}
+
+  static_assert(__builtin_llround(__FLT_MAX__) == 0, ""); // expected-error 
{{static_assert expression is not an integral constant expression}}
+  static_assert(__builtin_llroundf(__FLT_MAX__) == 0, ""); // expected-error 
{{static_assert expression is not an integral constant expression}}
+  static_assert(__builtin_llroundl(__FLT_MAX__) == 0, ""); // expected-error 
{{static_assert expression is not an integral constant expression}}
+
+  static_assert(__builtin_lround(__FLT_MAX__) == 0, ""); // expected-error 
{{static_assert expression is not an integral constant expression}}
+  static_assert(__builtin_lroundf(__FLT_MAX__) == 0, ""); // expected-error 
{{static_assert expression is not an integral constant expression}}
+  static_assert(__builtin_lroundl(__FLT_MAX__) == 0, ""); // expected-error 
{{static_assert expression is not an integral constant expression}}
+
+}
\ No newline at end of file
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -9609,6 +9609,24 @@
 return Success(N == Val.getBitWidth() ? 0 : N + 1, E);
   }
 
+  case Builtin::BI__builtin_lround:
+  case Builtin::BI__builtin_lroundf:
+  case Builtin::BI__builtin_lroundl:
+  case Builtin::BI__builtin_llround:
+  case Builtin::BI__builtin_llroundf:
+  case Builtin::BI__builtin_llroundl: {
+APFloat FPVal(0.0);
+APSInt IVal(Info.Ctx.getIntWidth(E->getType()), 0);
+bool IsExact = true;
+
+if (!EvaluateFloat(E->getArg(0), FPVal, Info)) return false;
+APFloat::opStatus RoundStatus =
+FPVal.convertToInteger(IVal, APFloat::rmNearestTiesToAway, );
+if (RoundStatus != APFloat::opInexact && RoundStatus != APFloat::opOK) 
return false;
+
+return Success(IVal, E);
+  }
+
   case Builtin::BI__builtin_fpclassify: {
 APFloat Val(0.0);
 if (!EvaluateFloat(E->getArg(5), Val, Info))


Index: clang/test/SemaCXX/math-builtins.cpp
===
--- 

[PATCH] D66862: Make lround builtin constexpr (and others)

2019-08-31 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver marked an inline comment as done.
zoecarver added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:9617
+APFloat FPVal(0.0);
+APSInt IVal(Info.Ctx.getIntWidth(E->getType()), 0);
+bool isExact = true;

rsmith wrote:
> Please use `/*isUnsigned=*/false` for the second argument rather than `0`.
I'm using the default value of `isUnsigned` (false). Do you want me to specify 
it? The second argument (`0`) is the initial value (which is required). 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66862



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


[PATCH] D66862: Make lround builtin constexpr (and others)

2019-08-31 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver added a comment.

> Are you intentionally excluding __builtin_lroundl/__builtin_llroundl?

I //was// because `convertToDouble` could only return up to 64 bytes. But now 
that I am using the builtin APFloat round function, that works.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66862



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


[PATCH] D66621: [clang] Devirtualization for classes with destructors marked as 'final'

2019-08-31 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> For now, I need help committing this, if anyone would be so kind!

rL370597 


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66621



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


[PATCH] D66621: [clang] Devirtualization for classes with destructors marked as 'final'

2019-08-31 Thread Dávid Bolvanský via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370597: [clang] Devirtualization for classes with 
destructors marked as final (authored by xbolva00, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66621?vs=217009=218230#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66621

Files:
  cfe/trunk/lib/AST/DeclCXX.cpp
  cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp


Index: cfe/trunk/lib/AST/DeclCXX.cpp
===
--- cfe/trunk/lib/AST/DeclCXX.cpp
+++ cfe/trunk/lib/AST/DeclCXX.cpp
@@ -2067,10 +2067,15 @@
   if (DevirtualizedMethod->hasAttr())
 return DevirtualizedMethod;
 
-  // Similarly, if the class itself is marked 'final' it can't be overridden
-  // and we can therefore devirtualize the member function call.
+  // Similarly, if the class itself or its destructor is marked 'final',
+  // the class can't be derived from and we can therefore devirtualize the 
+  // member function call.
   if (BestDynamicDecl->hasAttr())
 return DevirtualizedMethod;
+  if (const auto *dtor = BestDynamicDecl->getDestructor()) {
+if (dtor->hasAttr())
+  return DevirtualizedMethod;
+  }
 
   if (const auto *DRE = dyn_cast(Base)) {
 if (const auto *VD = dyn_cast(DRE->getDecl()))
Index: cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
===
--- cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
+++ cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
@@ -24,11 +24,24 @@
   }
 }
 
-namespace Test3 {
+namespace Test2a {
   struct A {
+virtual ~A() final {}
 virtual int f();
   };
 
+  // CHECK-LABEL: define i32 @_ZN6Test2a1fEPNS_1AE
+  int f(A *a) {
+// CHECK: call i32 @_ZN6Test2a1A1fEv
+return a->f();
+  }
+}
+
+
+namespace Test3 {
+  struct A {
+virtual int f();  };
+
   struct B final : A { };
 
   // CHECK-LABEL: define i32 @_ZN5Test31fEPNS_1BE


Index: cfe/trunk/lib/AST/DeclCXX.cpp
===
--- cfe/trunk/lib/AST/DeclCXX.cpp
+++ cfe/trunk/lib/AST/DeclCXX.cpp
@@ -2067,10 +2067,15 @@
   if (DevirtualizedMethod->hasAttr())
 return DevirtualizedMethod;
 
-  // Similarly, if the class itself is marked 'final' it can't be overridden
-  // and we can therefore devirtualize the member function call.
+  // Similarly, if the class itself or its destructor is marked 'final',
+  // the class can't be derived from and we can therefore devirtualize the 
+  // member function call.
   if (BestDynamicDecl->hasAttr())
 return DevirtualizedMethod;
+  if (const auto *dtor = BestDynamicDecl->getDestructor()) {
+if (dtor->hasAttr())
+  return DevirtualizedMethod;
+  }
 
   if (const auto *DRE = dyn_cast(Base)) {
 if (const auto *VD = dyn_cast(DRE->getDecl()))
Index: cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
===
--- cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
+++ cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
@@ -24,11 +24,24 @@
   }
 }
 
-namespace Test3 {
+namespace Test2a {
   struct A {
+virtual ~A() final {}
 virtual int f();
   };
 
+  // CHECK-LABEL: define i32 @_ZN6Test2a1fEPNS_1AE
+  int f(A *a) {
+// CHECK: call i32 @_ZN6Test2a1A1fEv
+return a->f();
+  }
+}
+
+
+namespace Test3 {
+  struct A {
+virtual int f();  };
+
   struct B final : A { };
 
   // CHECK-LABEL: define i32 @_ZN5Test31fEPNS_1BE
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r370597 - [clang] Devirtualization for classes with destructors marked as 'final'

2019-08-31 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Sat Aug 31 11:52:44 2019
New Revision: 370597

URL: http://llvm.org/viewvc/llvm-project?rev=370597=rev
Log:
[clang] Devirtualization for classes with destructors marked as 'final'

A class with a destructor marked final cannot be derived from, so it should 
afford the same devirtualization opportunities as marking the entire class 
final.

Patch by logan-5 (Logan Smith)
Reviewed by rsmith

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

Modified:
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=370597=370596=370597=diff
==
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Sat Aug 31 11:52:44 2019
@@ -2067,10 +2067,15 @@ CXXMethodDecl *CXXMethodDecl::getDevirtu
   if (DevirtualizedMethod->hasAttr())
 return DevirtualizedMethod;
 
-  // Similarly, if the class itself is marked 'final' it can't be overridden
-  // and we can therefore devirtualize the member function call.
+  // Similarly, if the class itself or its destructor is marked 'final',
+  // the class can't be derived from and we can therefore devirtualize the 
+  // member function call.
   if (BestDynamicDecl->hasAttr())
 return DevirtualizedMethod;
+  if (const auto *dtor = BestDynamicDecl->getDestructor()) {
+if (dtor->hasAttr())
+  return DevirtualizedMethod;
+  }
 
   if (const auto *DRE = dyn_cast(Base)) {
 if (const auto *VD = dyn_cast(DRE->getDecl()))

Modified: 
cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp?rev=370597=370596=370597=diff
==
--- cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp 
(original)
+++ cfe/trunk/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp Sat 
Aug 31 11:52:44 2019
@@ -24,11 +24,24 @@ namespace Test2 {
   }
 }
 
-namespace Test3 {
+namespace Test2a {
   struct A {
+virtual ~A() final {}
 virtual int f();
   };
 
+  // CHECK-LABEL: define i32 @_ZN6Test2a1fEPNS_1AE
+  int f(A *a) {
+// CHECK: call i32 @_ZN6Test2a1A1fEv
+return a->f();
+  }
+}
+
+
+namespace Test3 {
+  struct A {
+virtual int f();  };
+
   struct B final : A { };
 
   // CHECK-LABEL: define i32 @_ZN5Test31fEPNS_1BE


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


[PATCH] D63960: [C++20] Add consteval-specifique semantic

2019-08-31 Thread Tyker via Phabricator via cfe-commits
Tyker marked 2 inline comments as done.
Tyker added a comment.

sorry i didn't realize the full complexity of immediate invocations.
i am working on a patch fixing issues.




Comment at: clang/lib/Sema/SemaExpr.cpp:5761-5762
   // in ArgExprs.
-  if ((FDecl =
-   rewriteBuiltinFunctionDecl(this, Context, FDecl, ArgExprs))) {
+  if ((FDecl = rewriteBuiltinFunctionDecl(this, Context, FDecl, ArgExprs,
+  /*Diagnose*/ false))) {
 NDecl = FDecl;

rsmith wrote:
> What's the purpose of this change?
this change was to prevent a double error message for code like:
```
consteval f() { return 0; }
auto* p = __builtin_addressof(f);
```
it is going to disappear because the error reporting locations are going to 
move.



Comment at: clang/lib/Sema/SemaOverload.cpp:9596-9607
+  if (!S.isConstantEvaluated() && FD->isConsteval()) {
+if (Complain) {
+  if (InOverloadResolution)
+S.Diag(FD->getBeginLoc(), diag::note_addrof_ovl_consteval);
+  else {
+S.Diag(Loc, diag::err_invalid_consteval_take_address) << FD;
+S.Diag(FD->getBeginLoc(), diag::note_declared_at);

rsmith wrote:
> This isn't the right way to deal with this, in part because we don't know 
> whether we're in an immediate invocation or not at this point. Instead, we 
> should track that we saw a use of a `consteval` function from 
> `Sema::DiagnoseUseOfDecl`, and issue a diagnostic if that use is not within 
> an immediate invocation / within a consteval function.
from what i understood Sema::DiagnoseUseOfDecl is called as soon as the Decl is 
used. but there is some cases similar to the one you gave in an other comment 
where we can't know yet if the use is during an immediate invokation. like the 
following
```
enum E {};
consteval int operator+(int (*f)(), E) { return f(); }
consteval int fn() { return 42; }

int k =  + E();
```
this should be valid i think. but at the point of call of 
Sema::DiagnoseUseOfDecl for the use of fn we don't know yet that we are in an 
immediate invokation. so i think this check should be delayed until we know the 
bounds of the immediate invokation.


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

https://reviews.llvm.org/D63960



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


r370595 - [NFC] Fix for rL370594

2019-08-31 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Sat Aug 31 11:35:44 2019
New Revision: 370595

URL: http://llvm.org/viewvc/llvm-project?rev=370595=rev
Log:
[NFC] Fix for rL370594

Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=370595=370594=370595=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Sat Aug 31 11:35:44 2019
@@ -113,6 +113,7 @@ def DeleteNonVirtualDtor : DiagGroup<"de
  [DeleteNonAbstractNonVirtualDtor,
   DeleteAbstractNonVirtualDtor]>;
 def AbstractFinalClass : DiagGroup<"abstract-final-class">;
+def FinalDtorNonFinalClass : DiagGroup<"final-dtor-non-final-class">;
 
 def CXX11CompatDeprecatedWritableStr :
   DiagGroup<"c++11-compat-deprecated-writable-strings">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=370595=370594=370595=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Aug 31 11:35:44 
2019
@@ -2224,6 +2224,11 @@ def err_class_marked_final_used_as_base
   "base %0 is marked '%select{final|sealed}1'">;
 def warn_abstract_final_class : Warning<
   "abstract class is marked '%select{final|sealed}0'">, 
InGroup;
+def warn_final_dtor_non_final_class : Warning<
+  "class with destructor marked '%select{final|sealed}0' cannot be inherited 
from">,
+  InGroup;
+def note_final_dtor_non_final_class_silence : Note<
+  "mark %0 as '%select{final|sealed}1' to silence this warning">;
 
 // C++11 attributes
 def err_repeat_attribute : Error<"%0 attribute cannot be repeated">;


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


[PATCH] D66711: [clang] Warning for non-final classes with final destructors

2019-08-31 Thread Dávid Bolvanský via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370594: [clang] Warning for non-final classes with final 
destructors (authored by xbolva00, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66711?vs=217049=218229#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66711

Files:
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
  cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp


Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -6236,6 +6236,19 @@
 }
   }
 
+  // Warn if the class has a final destructor but is not itself marked final.
+  if (!Record->hasAttr()) {
+if (const CXXDestructorDecl *dtor = Record->getDestructor()) {
+  if (const FinalAttr *FA = dtor->getAttr()) {
+Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class)
+  << FA->isSpelledAsSealed();
+Diag(Record->getLocation(), 
diag::note_final_dtor_non_final_class_silence)
+  << Context.getRecordType(Record)
+  << FA->isSpelledAsSealed();
+  }
+}
+  }
+
   // See if trivial_abi has to be dropped.
   if (Record->hasAttr())
 checkIllFormedTrivialABIStruct(*Record);
Index: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
===
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
@@ -440,6 +440,11 @@
 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
 struct InheritFromSealed : SealedType {};
 
+class SealedDestructor { // expected-note {{mark 'SealedDestructor' as 
'sealed' to silence this warning}}
+// expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
+virtual ~SealedDestructor() sealed; // expected-warning {{class with 
destructor marked 'sealed' cannot be inherited from}}
+};
+
 void AfterClassBody() {
   // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after 
"struct" to apply attribute to type declaration}}
   struct D {} __declspec(deprecated);
Index: cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp
===
--- cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp
+++ cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s 
-Wfinal-dtor-non-final-class
+
+class A {
+~A();
+};
+
+class B { // expected-note {{mark 'B' as 'final' to silence this warning}}
+virtual ~B() final; // expected-warning {{class with destructor marked 
'final' cannot be inherited from}}
+};
+
+class C final {
+virtual ~C() final;
+};


Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -6236,6 +6236,19 @@
 }
   }
 
+  // Warn if the class has a final destructor but is not itself marked final.
+  if (!Record->hasAttr()) {
+if (const CXXDestructorDecl *dtor = Record->getDestructor()) {
+  if (const FinalAttr *FA = dtor->getAttr()) {
+Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class)
+  << FA->isSpelledAsSealed();
+Diag(Record->getLocation(), diag::note_final_dtor_non_final_class_silence)
+  << Context.getRecordType(Record)
+  << FA->isSpelledAsSealed();
+  }
+}
+  }
+
   // See if trivial_abi has to be dropped.
   if (Record->hasAttr())
 checkIllFormedTrivialABIStruct(*Record);
Index: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
===
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
@@ -440,6 +440,11 @@
 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
 struct InheritFromSealed : SealedType {};
 
+class SealedDestructor { // expected-note {{mark 'SealedDestructor' as 'sealed' to silence this warning}}
+// expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
+virtual ~SealedDestructor() sealed; // expected-warning {{class with destructor marked 'sealed' cannot be inherited from}}
+};
+
 void AfterClassBody() {
   // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}}
   struct D {} __declspec(deprecated);
Index: cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp
===
--- cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp
+++ cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp
@@ 

r370594 - [clang] Warning for non-final classes with final destructors

2019-08-31 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Sat Aug 31 11:31:19 2019
New Revision: 370594

URL: http://llvm.org/viewvc/llvm-project?rev=370594=rev
Log:
[clang] Warning for non-final classes with final destructors

Marking a class' destructor final prevents the class from being inherited from. 
However, it is a subtle and awkward way to express that at best, and unintended 
at worst. It may also generate worse code (in other compilers) than marking the 
class itself final. For these reasons, this revision adds a warning for 
nonfinal classes with final destructors, with a note to suggest marking the 
class final to silence the warning.

See https://reviews.llvm.org/D66621 for more background.

Patch by logan-5 (Logan Smith)

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

Added:
cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=370594=370593=370594=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Aug 31 11:31:19 2019
@@ -6236,6 +6236,19 @@ void Sema::CheckCompletedCXXClass(CXXRec
 }
   }
 
+  // Warn if the class has a final destructor but is not itself marked final.
+  if (!Record->hasAttr()) {
+if (const CXXDestructorDecl *dtor = Record->getDestructor()) {
+  if (const FinalAttr *FA = dtor->getAttr()) {
+Diag(FA->getLocation(), diag::warn_final_dtor_non_final_class)
+  << FA->isSpelledAsSealed();
+Diag(Record->getLocation(), 
diag::note_final_dtor_non_final_class_silence)
+  << Context.getRecordType(Record)
+  << FA->isSpelledAsSealed();
+  }
+}
+  }
+
   // See if trivial_abi has to be dropped.
   if (Record->hasAttr())
 checkIllFormedTrivialABIStruct(*Record);

Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=370594=370593=370594=diff
==
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Sat Aug 31 11:31:19 2019
@@ -440,6 +440,11 @@ struct SealedType sealed : SomeBase {
 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
 struct InheritFromSealed : SealedType {};
 
+class SealedDestructor { // expected-note {{mark 'SealedDestructor' as 
'sealed' to silence this warning}}
+// expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
+virtual ~SealedDestructor() sealed; // expected-warning {{class with 
destructor marked 'sealed' cannot be inherited from}}
+};
+
 void AfterClassBody() {
   // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after 
"struct" to apply attribute to type declaration}}
   struct D {} __declspec(deprecated);

Added: cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp?rev=370594=auto
==
--- cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-final-dtor-non-final-class.cpp Sat Aug 31 
11:31:19 2019
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s 
-Wfinal-dtor-non-final-class
+
+class A {
+~A();
+};
+
+class B { // expected-note {{mark 'B' as 'final' to silence this warning}}
+virtual ~B() final; // expected-warning {{class with destructor marked 
'final' cannot be inherited from}}
+};
+
+class C final {
+virtual ~C() final;
+};


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


[PATCH] D67031: [Clang][Bundler] Error reporting improvements

2019-08-31 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev marked an inline comment as done.
sdmitriev added inline comments.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:906
+Msg << ", unknown target triple '" << Triple << "'";
+  reportError(createStringError(errc::invalid_argument, Msg.str() + "."));
 }

MaskRay wrote:
> I think trailing full stop is uncommon in error messages.
Maybe., but all error messages in this tool seem to be consistent in that 
sense)) Do you suggest removing trailing '.' from all error messages?


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

https://reviews.llvm.org/D67031



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


[PATCH] D59754: [Sema] Add c++2a designated initializer warnings

2019-08-31 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: cfe/trunk/lib/Sema/SemaInit.cpp:3112
   SmallVector InitExpressions;
+  bool HasArrayDesignator = false;
 

warning: variable ‘HasArrayDesignator’ set but not used 
[-Wunused-but-set-variable]
   bool HasArrayDesignator = false;



Repository:
  rL LLVM

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

https://reviews.llvm.org/D59754



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


[PATCH] D67031: [Clang][Bundler] Error reporting improvements

2019-08-31 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:906
+Msg << ", unknown target triple '" << Triple << "'";
+  reportError(createStringError(errc::invalid_argument, Msg.str() + "."));
 }

I think trailing full stop is uncommon in error messages.


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

https://reviews.llvm.org/D67031



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


[PATCH] D67031: [Clang][Bundler] Error reporting improvements

2019-08-31 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev marked an inline comment as done.
sdmitriev added inline comments.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:41-44
-#include 
-#include 
-#include 
-#include 

Hahnfeld wrote:
> The code still uses (in the order of marked includes)
>  * `std::unique_ptr`
>  * `std::string`
>  * `std::error_code`
>  * `std::vector`,
> so I don't think these lines should be removed. Same goes for `assert` and 
> probably also `cstddef` / `cstdint` (`uint64_t`?)
Right. Restored required system includes.


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

https://reviews.llvm.org/D67031



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


[PATCH] D67031: [Clang][Bundler] Error reporting improvements

2019-08-31 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev updated this revision to Diff 218224.
sdmitriev retitled this revision from "[Clang][Bundler] Error reporting 
improvements [NFC]" to "[Clang][Bundler] Error reporting improvements".
sdmitriev added a comment.

Addressed review comments.


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

https://reviews.llvm.org/D67031

Files:
  clang/test/Driver/clang-offload-bundler.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -17,6 +17,7 @@
 #include "clang/Basic/Version.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -25,23 +26,23 @@
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/StringSaver.h"
-#include 
+#include "llvm/Support/WithColor.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
-#include 
+#include 
 
 using namespace llvm;
 using namespace llvm::object;
@@ -98,6 +99,9 @@
 /// Path to the current binary.
 static std::string BundlerExecutable;
 
+/// Saved argv[0].
+static StringRef Argv0;
+
 /// Obtain the offload kind and real machine triple out of the target
 /// information specified by the user.
 static void getOffloadKindAndTriple(StringRef Target, StringRef ,
@@ -113,6 +117,15 @@
   return OffloadKind == "host";
 }
 
+/// Error reporting functions.
+static void reportError(Error E) {
+  logAllUnhandledErrors(std::move(E), WithColor::error(errs(), Argv0));
+}
+
+static void reportFileError(StringRef File, std::error_code EC) {
+  reportError(createFileError(File, EC));
+}
+
 /// Generic file handler interface.
 class FileHandler {
 public:
@@ -146,7 +159,6 @@
 
   /// Write the marker that closes a bundle for the triple \a TargetTriple to \a
   /// OS. Return true if any error was found.
-
   virtual bool WriteBundleEnd(raw_fd_ostream , StringRef TargetTriple) = 0;
 
   /// Write the bundle from \a Input into \a OS.
@@ -327,7 +339,7 @@
 
 unsigned Idx = 0;
 for (auto  : TargetNames) {
-  MemoryBuffer  = *Inputs[Idx++].get();
+  MemoryBuffer  = *Inputs[Idx++];
   // Bundle offset.
   Write8byteIntegerToBuffer(OS, HeaderSize);
   // Size of the bundle (adds to the next bundle's offset)
@@ -467,7 +479,8 @@
 ErrorOr Objcopy = sys::findProgramByName(
 "llvm-objcopy", sys::path::parent_path(BundlerExecutable));
 if (!Objcopy) {
-  errs() << "error: unable to find 'llvm-objcopy' in path.\n";
+  reportError(createStringError(Objcopy.getError(),
+"unable to find 'llvm-objcopy' in path."));
   return true;
 }
 
@@ -489,13 +502,14 @@
 // If the user asked for the commands to be printed out, we do that instead
 // of executing it.
 if (PrintExternalCommands) {
-  errs() << "\"" << Objcopy.get() << "\"";
+  errs() << "\"" << *Objcopy << "\"";
   for (StringRef Arg : drop_begin(ObjcopyArgs, 1))
 errs() << " \"" << Arg << "\"";
   errs() << "\n";
 } else {
-  if (sys::ExecuteAndWait(Objcopy.get(), ObjcopyArgs)) {
-errs() << "error: llvm-objcopy tool failed.\n";
+  if (sys::ExecuteAndWait(*Objcopy, ObjcopyArgs)) {
+reportError(createStringError(inconvertibleErrorCode(),
+  "'llvm-objcopy' tool failed."));
 return true;
   }
 }
@@ -622,13 +636,11 @@
   // We only support regular object files. If this is not an object file,
   // default to the binary handler. The handler will be owned by the client of
   // this function.
-  std::unique_ptr Obj(
-  dyn_cast(BinaryOrErr.get().release()));
-
-  if (!Obj)
-return new BinaryFileHandler();
-
-  return new ObjectFileHandler(std::move(Obj));
+  if (auto *Obj = dyn_cast(BinaryOrErr->get())) {
+  BinaryOrErr->release();
+  return new ObjectFileHandler(std::unique_ptr(Obj));
+  }
+  return new BinaryFileHandler();
 }
 
 /// Return an appropriate handler given the input files and options.
@@ -650,7 +662,10 @@
   if (FilesType == "ast")
 return new BinaryFileHandler();
 
-  errs() << "error: invalid file type specified.\n";
+  reportError(
+  createStringError(errc::invalid_argument,
+"'" + FilesType + "': 

r370588 - Revert [Clang Interpreter] Initial patch for the constexpr interpreter

2019-08-31 Thread Nandor Licker via cfe-commits
Author: nand
Date: Sat Aug 31 08:15:39 2019
New Revision: 370588

URL: http://llvm.org/viewvc/llvm-project?rev=370588=rev
Log:
Revert [Clang Interpreter] Initial patch for the constexpr interpreter

This reverts r370584 (git commit afcb3de117265a69d21e5673356e925a454d7d02)

Removed:
cfe/trunk/docs/ConstantInterpreter.rst
cfe/trunk/include/clang/AST/OptionalDiagnostic.h
cfe/trunk/lib/AST/Interp/
cfe/trunk/test/AST/Interp/
cfe/trunk/utils/TableGen/ClangOpcodesEmitter.cpp
Modified:
cfe/trunk/docs/index.rst
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/CMakeLists.txt
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp
cfe/trunk/test/SemaCXX/constexpr-many-arguments.cpp
cfe/trunk/test/SemaCXX/shift.cpp
cfe/trunk/utils/TableGen/CMakeLists.txt
cfe/trunk/utils/TableGen/TableGen.cpp
cfe/trunk/utils/TableGen/TableGenBackends.h

Removed: cfe/trunk/docs/ConstantInterpreter.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ConstantInterpreter.rst?rev=370587=auto
==
--- cfe/trunk/docs/ConstantInterpreter.rst (original)
+++ cfe/trunk/docs/ConstantInterpreter.rst (removed)
@@ -1,194 +0,0 @@
-
-Constant Interpreter
-
-
-.. contents::
-   :local:
-
-Introduction
-
-
-The constexpr interpreter aims to replace the existing tree evaluator in 
clang, improving performance on constructs which are executed inefficiently by 
the evaluator. The interpreter is activated using the following flags:
-
-* ``-fexperimental-new-constant-interpreter`` enables the interpreter, falling 
back to the evaluator for unsupported features
-* ``-fforce-experimental-new-constant-interpreter`` forces the use of the 
interpreter, bailing out if an unsupported feature is encountered
-
-Bytecode Compilation
-
-
-Bytecode compilation is handled in ``ByteCodeStmtGen.h`` for statements and 
``ByteCodeExprGen.h`` for expressions. The compiler has two different backends: 
one to generate bytecode for functions (``ByteCodeEmitter``) and one to 
directly evaluate expressions as they are compiled, without generating bytecode 
(``EvalEmitter``). All functions are compiled to bytecode, while toplevel 
expressions used in constant contexts are directly evaluated since the bytecode 
would never be reused. This mechanism aims to pave the way towards replacing 
the evaluator, improving its performance on functions and loops, while being 
just as fast on single-use toplevel expressions.
-
-The interpreter relies on stack-based, strongly-typed opcodes. The glue logic 
between the code generator, along with the enumeration and description of 
opcodes, can be found in ``Opcodes.td``. The opcodes are implemented as generic 
template methods in ``Interp.h`` and instantiated with the relevant primitive 
types by the interpreter loop or by the evaluating emitter.
-
-Primitive Types

-
-* ``PT_{U|S}int{8|16|32|64}``
-
-  Signed or unsigned integers of a specific bit width, implemented using the 
```Integral``` type.
-
-* ``PT_{U|S}intFP``
-
-  Signed or unsigned integers of an arbitrary, but fixed width used to 
implement
-  integral types which are required by the target, but are not supported by 
the host.
-  Under the hood, they rely on APValue. The ``Integral`` specialisation for 
these
-  types is required by opcodes to share an implementation with fixed integrals.
-
-* ``PT_Bool``
-
-  Representation for boolean types, essentially a 1-bit unsigned ``Integral``.
-
-* ``PT_RealFP``
-
-  Arbitrary, but fixed precision floating point numbers. Could be specialised 
in
-  the future similarly to integers in order to improve floating point 
performance.
-
-* ``PT_Ptr``
-
-  Pointer type, defined in ``"Pointer.h"``.
-
-* ``PT_FnPtr``
-
-  Function pointer type, can also be a null function pointer. Defined in 
``"Pointer.h"``.
-
-* ``PT_MemPtr``
-
-  Member pointer type, can also be a null member pointer. Defined in 
``"Pointer.h"``
-
-Composite types

-
-The interpreter distinguishes two kinds of composite types: arrays and 
records. Unions are represented as records, except a single field can be marked 
as active. The contents of inactive fields are kept until they
-are reactivated and overwritten.
-
-
-Bytecode Execution
-==
-
-Bytecode is executed using a stack-based interpreter. The execution context 
consists of an ``InterpStack``, along with a chain of ``InterpFrame`` objects 
storing the call frames. Frames are built by call instructions and destroyed by 
return instructions. They 

[PATCH] D67031: [Clang][Bundler] Error reporting improvements [NFC]

2019-08-31 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

This changes error messages, so I'd say it's not NFC.




Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:41-44
-#include 
-#include 
-#include 
-#include 

The code still uses (in the order of marked includes)
 * `std::unique_ptr`
 * `std::string`
 * `std::error_code`
 * `std::vector`,
so I don't think these lines should be removed. Same goes for `assert` and 
probably also `cstddef` / `cstdint` (`uint64_t`?)


Repository:
  rC Clang

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

https://reviews.llvm.org/D67031



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


[PATCH] D64644: [Sema] Fixes an assertion failure while instantiation a template with an incomplete typo corrected type

2019-08-31 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 218221.
Mordante retitled this revision from "Fixes an assertion failure while 
instantiation a template with an incomplete typo corrected type" to "[Sema] 
Fixes an assertion failure while instantiation a template with an incomplete 
typo corrected type".
Mordante added a comment.

Update bug number references:

- Removed from the source
- Use PR35682 in the test

Note: I tried to use `-verify` instead of `FileCheck` but that doesn't seem to 
work well since `-ferror-limit 1` reports no line number. Other tests with 
`-ferror-limit 1` also use `FileCheck`.


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

https://reviews.llvm.org/D64644

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp


Index: 
clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
===
--- /dev/null
+++ 
clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
@@ -0,0 +1,60 @@
+// RUN: not %clang -fsyntax-only -std=c++11 -ferror-limit=1 %s 2>&1 | 
FileCheck %s
+
+// Test case for PR35682.
+// The issue be caused by the typo correction that changes String to the
+// incomplete type string. The example is based on the std::pair code and
+// reduced to a minimal test case. When using std::pair the issue can only be
+// reproduced when using the -stdlib=libc++ compiler option.
+
+template  class allocator;
+
+template  struct char_traits;
+
+template ,
+  class Allocator = allocator>
+class basic_string;
+typedef basic_string, allocator> string;
+
+template  struct enable_if {};
+template  struct enable_if { typedef Tp type; };
+
+template  struct integral_constant {
+  static constexpr const Tp value = v;
+  typedef Tp value_type;
+  typedef integral_constant type;
+
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
+};
+
+template  constexpr const Tp integral_constant::value;
+
+using true_type = integral_constant;
+using false_type = integral_constant;
+
+template  struct is_same : public false_type {};
+template  struct is_same : public true_type {};
+
+template  struct single {
+  typedef T first_type;
+
+  T first;
+
+  struct CheckArgs {
+template  static constexpr bool enable_implicit() {
+  return is_same::value;
+}
+  };
+
+  template (),
+   bool>::type = false>
+  single(U1 &);
+};
+
+using SetKeyType = String;
+single v;
+
+// CHECK: error: unknown type name 'String'; did you mean 'string'?
+// CHECK: fatal error: too many errors emitted, stopping now [-ferror-limit=]
+// CHECK-NOT: Assertion{{.*}}failed
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -718,9 +718,13 @@
 SourceLocation TemplateKWLoc,
 const DeclarationNameInfo ,
 const TemplateArgumentListInfo *TemplateArgs) {
+  // DependentScopeDeclRefExpr::Create requires a valid QualifierLoc
+  NestedNameSpecifierLoc QualifierLoc = SS.getWithLocInContext(Context);
+  if (!QualifierLoc)
+return ExprError();
+
   return DependentScopeDeclRefExpr::Create(
-  Context, SS.getWithLocInContext(Context), TemplateKWLoc, NameInfo,
-  TemplateArgs);
+  Context, std::move(QualifierLoc), TemplateKWLoc, NameInfo, TemplateArgs);
 }
 
 


Index: clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
@@ -0,0 +1,60 @@
+// RUN: not %clang -fsyntax-only -std=c++11 -ferror-limit=1 %s 2>&1 | FileCheck %s
+
+// Test case for PR35682.
+// The issue be caused by the typo correction that changes String to the
+// incomplete type string. The example is based on the std::pair code and
+// reduced to a minimal test case. When using std::pair the issue can only be
+// reproduced when using the -stdlib=libc++ compiler option.
+
+template  class allocator;
+
+template  struct char_traits;
+
+template ,
+  class Allocator = allocator>
+class basic_string;
+typedef basic_string, allocator> string;
+
+template  struct enable_if {};
+template  struct enable_if { typedef Tp type; };
+
+template  struct integral_constant {
+  static constexpr const Tp value = v;
+  typedef Tp value_type;
+  typedef integral_constant type;
+
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
+};
+
+template  constexpr const Tp integral_constant::value;
+
+using true_type = integral_constant;
+using false_type = integral_constant;
+
+template  

[PATCH] D64480: [ASTImporter] Added visibility context check for TypedefNameDecl.

2019-08-31 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

It is worth noting that:

  typedef int T;
  typedef int T;

is not valid C99 see godbolt 


Repository:
  rC Clang

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

https://reviews.llvm.org/D64480



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


[PATCH] D65695: Implements CWG 1601 in [over.ics.rank/4.2]

2019-08-31 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 218216.
Mordante added a comment.

Addresses the review remarks:

- Use `S.Context.hasSameType` for the comparision
- Simplify an `if` statement


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

https://reviews.llvm.org/D65695

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/drs/dr16xx.cpp
  clang/test/CXX/drs/dr6xx.cpp

Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -987,14 +987,19 @@
 }
 #endif
 
-#if __cplusplus >= 201103L
 namespace dr685 { // dr685: yes
   enum E : long { e };
+#if __cplusplus < 201103L
+// expected-error@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
+#endif
   void f(int);
   int f(long);
   int a = f(e);
 
   enum G : short { g };
+#if __cplusplus < 201103L
+// expected-error@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
+#endif
   int h(short);
   void h(long);
   int b = h(g);
@@ -1007,11 +1012,11 @@
   void j(long); // expected-note {{candidate}}
   int d = j(g); // expected-error {{ambiguous}}
 
-  int k(short); // expected-note {{candidate}}
-  void k(int); // expected-note {{candidate}}
-  int x = k(g); // expected-error {{ambiguous}}
+  // Valid per dr1601
+  int k(short);
+  void k(int);
+  int x = k(g);
 }
-#endif
 
 namespace dr686 { // dr686: yes
   void f() {
Index: clang/test/CXX/drs/dr16xx.cpp
===
--- clang/test/CXX/drs/dr16xx.cpp
+++ clang/test/CXX/drs/dr16xx.cpp
@@ -23,6 +23,18 @@
 } // std
 #endif
 
+namespace dr1601 { // dr1601: 10
+enum E : char { e };
+#if __cplusplus < 201103L
+// expected-error@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
+#endif
+void f(char);
+void f(int);
+void g() {
+  f(e);
+}
+} // namespace dr1601
+
 namespace dr1611 { // dr1611: dup 1658
   struct A { A(int); };
   struct B : virtual A { virtual void f() = 0; };
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -3751,6 +3751,34 @@
   !SCS2.IsLvalueReference && SCS2.BindsToFunctionLvalue);
 }
 
+enum class FixedEnumPromotion {
+  None,
+  ToUnderlyingType,
+  ToPromotedUnderlyingType
+};
+
+/// Returns kind of fixed enum promotion the \a SCS uses.
+static FixedEnumPromotion
+getFixedEnumPromtion(Sema , const StandardConversionSequence ) {
+
+  if (SCS.Second != ICK_Integral_Promotion)
+return FixedEnumPromotion::None;
+
+  QualType FromType = SCS.getFromType();
+  if (!FromType->isEnumeralType())
+return FixedEnumPromotion::None;
+
+  EnumDecl *Enum = FromType->getAs()->getDecl();
+  if (!Enum->isFixed())
+return FixedEnumPromotion::None;
+
+  QualType UnderlyingType = Enum->getIntegerType();
+  if (S.Context.hasSameType(SCS.getToType(1), UnderlyingType))
+return FixedEnumPromotion::ToUnderlyingType;
+
+  return FixedEnumPromotion::ToPromotedUnderlyingType;
+}
+
 /// CompareStandardConversionSequences - Compare two standard
 /// conversion sequences to determine whether one is better than the
 /// other or if they are indistinguishable (C++ 13.3.3.2p3).
@@ -3792,6 +3820,20 @@
  ? ImplicitConversionSequence::Better
  : ImplicitConversionSequence::Worse;
 
+  // C++14 [over.ics.rank]p4b2:
+  // This is retroactively applied to C++11 by CWG 1601.
+  //
+  //   A conversion that promotes an enumeration whose underlying type is fixed
+  //   to its underlying type is better than one that promotes to the promoted
+  //   underlying type, if the two are different.
+  FixedEnumPromotion FEP1 = getFixedEnumPromtion(S, SCS1);
+  FixedEnumPromotion FEP2 = getFixedEnumPromtion(S, SCS2);
+  if (FEP1 != FixedEnumPromotion::None && FEP2 != FixedEnumPromotion::None &&
+  FEP1 != FEP2)
+return FEP1 == FixedEnumPromotion::ToUnderlyingType
+   ? ImplicitConversionSequence::Better
+   : ImplicitConversionSequence::Worse;
+
   // C++ [over.ics.rank]p4b2:
   //
   //   If class B is derived directly or indirectly from class A,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64874: [Sema] Improve handling of function pointer conversions

2019-08-31 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 218215.
Mordante added a comment.

Addresses the review remarks:

- resultTy -> ResultTy
- Move all unit tests in one file
- Change the unit test to use `-verify` instead of `FileCheck`
- Use PR40024 instead of link to Bugzilla


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

https://reviews.llvm.org/D64874

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/conv/conv.fctptr/template-noexcept.cpp


Index: clang/test/CXX/conv/conv.fctptr/template-noexcept.cpp
===
--- /dev/null
+++ clang/test/CXX/conv/conv.fctptr/template-noexcept.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s
+
+// Starting with C++17 the noexcept is part of the function signature but
+// a noexcept function can be converted to a noexcept(false) function.
+// The tests were added for PR40024.
+
+#if __cplusplus < 201703L
+// expected-no-diagnostics
+#endif
+
+namespace valid_conversion {
+struct S {
+  int f(void) noexcept { return 110; }
+} s;
+
+template 
+int f10(void) { return (s.*a)(); }
+
+int foo(void) {
+  return f10<::f>();
+}
+} // namespace valid_conversion
+
+namespace invalid_conversion {
+struct S {
+  int f(void) { return 110; }
+} s;
+
+#if __cplusplus >= 201703L
+// expected-note@+3 {{candidate template ignored: invalid explicitly-specified 
argument for template parameter 'a'}}
+#endif
+template 
+int f10(void) { return (s.*a)(); }
+
+#if __cplusplus >= 201703L
+// expected-error@+3 {{no matching function for call to 'f10'}}
+#endif
+int foo(void) {
+  return f10<::f>();
+}
+} // namespace invalid_conversion
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -6991,6 +6991,14 @@
 ObjCLifetimeConversion))
 RefExpr = ImpCastExprToType(RefExpr.get(), 
ParamType.getUnqualifiedType(), CK_NoOp);
 
+  // Starting with C++17 the noexcept is part of the function signature but
+  // a noexcept function can be converted to a noexcept(false) function.
+  QualType ResultTy;
+  if (getLangOpts().CPlusPlus17 &&
+  IsFunctionConversion(((Expr *)RefExpr.get())->getType(),
+   ParamType.getUnqualifiedType(), ResultTy))
+RefExpr = ImpCastExprToType(RefExpr.get(), ResultTy, CK_NoOp);
+
   assert(!RefExpr.isInvalid() &&
  Context.hasSameType(((Expr*) RefExpr.get())->getType(),
  ParamType.getUnqualifiedType()));


Index: clang/test/CXX/conv/conv.fctptr/template-noexcept.cpp
===
--- /dev/null
+++ clang/test/CXX/conv/conv.fctptr/template-noexcept.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s
+
+// Starting with C++17 the noexcept is part of the function signature but
+// a noexcept function can be converted to a noexcept(false) function.
+// The tests were added for PR40024.
+
+#if __cplusplus < 201703L
+// expected-no-diagnostics
+#endif
+
+namespace valid_conversion {
+struct S {
+  int f(void) noexcept { return 110; }
+} s;
+
+template 
+int f10(void) { return (s.*a)(); }
+
+int foo(void) {
+  return f10<::f>();
+}
+} // namespace valid_conversion
+
+namespace invalid_conversion {
+struct S {
+  int f(void) { return 110; }
+} s;
+
+#if __cplusplus >= 201703L
+// expected-note@+3 {{candidate template ignored: invalid explicitly-specified argument for template parameter 'a'}}
+#endif
+template 
+int f10(void) { return (s.*a)(); }
+
+#if __cplusplus >= 201703L
+// expected-error@+3 {{no matching function for call to 'f10'}}
+#endif
+int foo(void) {
+  return f10<::f>();
+}
+} // namespace invalid_conversion
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -6991,6 +6991,14 @@
 ObjCLifetimeConversion))
 RefExpr = ImpCastExprToType(RefExpr.get(), ParamType.getUnqualifiedType(), CK_NoOp);
 
+  // Starting with C++17 the noexcept is part of the function signature but
+  // a noexcept function can be converted to a noexcept(false) function.
+  QualType ResultTy;
+  if (getLangOpts().CPlusPlus17 &&
+  IsFunctionConversion(((Expr *)RefExpr.get())->getType(),
+   ParamType.getUnqualifiedType(), ResultTy))
+RefExpr = ImpCastExprToType(RefExpr.get(), ResultTy, 

[PATCH] D64820: [Sema] Avoids an assertion failure when an invalid conversion declaration is used

2019-08-31 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 218213.
Mordante added a comment.

Addresses the review remarks:

- Moved the unit test to SemaCXX (also use the PR as name of the file)
- Change the unit test to use `-verify` instead of `FileCheck`


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

https://reviews.llvm.org/D64820

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/PR31422.cpp


Index: clang/test/SemaCXX/PR31422.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR31422.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
+
+// expected-error@+3 {{cannot specify any part of a return type in the 
declaration of a conversion function; use an alias template to declare a 
conversion to 'auto (Ts &&...) const'}}
+// expected-error@+2 {{conversion function cannot convert to a function type}}
+struct S {
+  template  operator auto()(Ts &&... xs) const;
+};
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -8066,6 +8066,9 @@
 }
 
 SemaRef.CheckConversionDeclarator(D, R, SC);
+if (D.isInvalidType())
+  return nullptr;
+
 IsVirtualOkay = true;
 return CXXConversionDecl::Create(
 SemaRef.Context, cast(DC), D.getBeginLoc(), NameInfo, R,


Index: clang/test/SemaCXX/PR31422.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/PR31422.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
+
+// expected-error@+3 {{cannot specify any part of a return type in the declaration of a conversion function; use an alias template to declare a conversion to 'auto (Ts &&...) const'}}
+// expected-error@+2 {{conversion function cannot convert to a function type}}
+struct S {
+  template  operator auto()(Ts &&... xs) const;
+};
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -8066,6 +8066,9 @@
 }
 
 SemaRef.CheckConversionDeclarator(D, R, SC);
+if (D.isInvalidType())
+  return nullptr;
+
 IsVirtualOkay = true;
 return CXXConversionDecl::Create(
 SemaRef.Context, cast(DC), D.getBeginLoc(), NameInfo, R,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67037: [ClangFormat] Add new style option IndentGotoLabels

2019-08-31 Thread Alex Cameron via Phabricator via cfe-commits
tetsuo-cpp created this revision.
tetsuo-cpp added a reviewer: klimek.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This option determines whether goto labels are indented according to scope. 
Setting this option to false causes goto labels to be flushed to the left.
This is mostly copied from this patch 
 submitted 
by Christian Neukirchen that didn't make its way into trunk.

  true:  false:
  int f() {  vs. int f() {
if (foo()) {   if (foo()) {
label1:  label1:
  bar(); bar();
}  }
  label2:label2:
return 1;  return 1;
  }  }


Repository:
  rC Clang

https://reviews.llvm.org/D67037

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1408,6 +1408,30 @@
"test_label:;\n"
"  int i = 0;\n"
"}");
+  FormatStyle Style = getLLVMStyle();
+  Style.IndentGotoLabels = false;
+  verifyFormat("void f() {\n"
+   "  some_code();\n"
+   "test_label:\n"
+   "  some_other_code();\n"
+   "  {\n"
+   "some_more_code();\n"
+   "another_label:\n"
+   "some_more_code();\n"
+   "  }\n"
+   "}",
+   Style);
+  verifyFormat("{\n"
+   "  some_code();\n"
+   "test_label:\n"
+   "  some_other_code();\n"
+   "}",
+   Style);
+  verifyFormat("{\n"
+   "  some_code();\n"
+   "test_label:;\n"
+   "  int i = 0;\n"
+   "}");
 }
 
 //===--===//
@@ -11769,6 +11793,7 @@
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
   CHECK_PARSE_BOOL(IndentCaseLabels);
+  CHECK_PARSE_BOOL(IndentGotoLabels);
   CHECK_PARSE_BOOL(IndentWrappedFunctionNames);
   CHECK_PARSE_BOOL(KeepEmptyLinesAtTheStartOfBlocks);
   CHECK_PARSE_BOOL(ObjCSpaceAfterProperty);
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -106,7 +106,7 @@
   void parseTryCatch();
   void parseForOrWhileLoop();
   void parseDoWhile();
-  void parseLabel();
+  void parseLabel(bool GotoLabel = false);
   void parseCaseLabel();
   void parseSwitch();
   void parseNamespace();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1351,7 +1351,7 @@
   (TokenCount == 2 && Line->Tokens.front().Tok->is(tok::comment))) {
 if (FormatTok->Tok.is(tok::colon) && !Line->MustBeDeclaration) {
   Line->Tokens.begin()->Tok->MustBreakBefore = true;
-  parseLabel();
+  parseLabel(true);
   return;
 }
 // Recognize function-like macro usages without trailing semicolon as
@@ -1970,11 +1970,13 @@
   parseStructuralElement();
 }
 
-void UnwrappedLineParser::parseLabel() {
+void UnwrappedLineParser::parseLabel(bool GotoLabel) {
   nextToken();
   unsigned OldLineLevel = Line->Level;
   if (Line->Level > 1 || (!Line->InPPDirective && Line->Level > 0))
 --Line->Level;
+  if (GotoLabel && !Style.IndentGotoLabels)
+Line->Level = 0;
   if (CommentsBeforeNextToken.empty() && FormatTok->Tok.is(tok::l_brace)) {
 CompoundStatementIndenter Indenter(this, Line->Level,
Style.BraceWrapping.AfterCaseLabel,
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -453,6 +453,7 @@
 IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex);
 IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
+IO.mapOptional("IndentGotoLabels", Style.IndentGotoLabels);
 IO.mapOptional("IndentPPDirectives", Style.IndentPPDirectives);
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 

[PATCH] D65371: do not emit -Wunused-macros warnings in -frewrite-includes mode (PR15614)

2019-08-31 Thread Luboš Luňák via Phabricator via cfe-commits
llunak added a comment.

Ping?


Repository:
  rC Clang

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

https://reviews.llvm.org/D65371



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


[PATCH] D63508: make -frewrite-includes also rewrite conditions in #if/#elif

2019-08-31 Thread Luboš Luňák via Phabricator via cfe-commits
llunak added a comment.

Ping?


Repository:
  rC Clang

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

https://reviews.llvm.org/D63508



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