r374285 - [clang] prevent crash for nonnull attribut in constant context (Bug 43601)

2019-10-10 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Thu Oct 10 00:13:20 2019
New Revision: 374285

URL: http://llvm.org/viewvc/llvm-project?rev=374285&view=rev
Log:
[clang] prevent crash for nonnull attribut in constant context (Bug 43601)

Summary:

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

Reviewers: rnk

Reviewed By: rnk

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/attr-nonnull.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=374285&r1=374284&r2=374285&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Oct 10 00:13:20 2019
@@ -5441,18 +5441,18 @@ static bool EvaluateArgs(ArrayRef::iterator I = Args.begin(), E = Args.end();
-   I != E; ++I) {
-if (!Evaluate(ArgValues[I - Args.begin()], Info, *I)) {
+  for (unsigned Idx = 0; Idx < Args.size(); Idx++) {
+if (!Evaluate(ArgValues[Idx], Info, Args[Idx])) {
   // If we're checking for a potential constant expression, evaluate all
   // initializers even if some of them fail.
   if (!Info.noteFailure())
 return false;
   Success = false;
 } else if (!ForbiddenNullArgs.empty() &&
-   ForbiddenNullArgs[I - Args.begin()] &&
-   ArgValues[I - Args.begin()].isNullPointer()) {
-  Info.CCEDiag(*I, diag::note_non_null_attribute_failed);
+   ForbiddenNullArgs[Idx] &&
+   ArgValues[Idx].isLValue() &&
+   ArgValues[Idx].isNullPointer()) {
+  Info.CCEDiag(Args[Idx], diag::note_non_null_attribute_failed);
   if (!Info.noteFailure())
 return false;
   Success = false;

Modified: cfe/trunk/test/SemaCXX/attr-nonnull.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-nonnull.cpp?rev=374285&r1=374284&r2=374285&view=diff
==
--- cfe/trunk/test/SemaCXX/attr-nonnull.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-nonnull.cpp Thu Oct 10 00:13:20 2019
@@ -77,10 +77,11 @@ constexpr int i3 = f3(&c, 0); //expected
 constexpr int i32 = f3(0, &c);
 
 __attribute__((nonnull(4))) __attribute__((nonnull)) //expected-error {{out of 
bounds}}
-constexpr int f4(const int*, const int*) {
+constexpr int f4(const int*, const int*, int) {
   return 0;
 }
-constexpr int i4 = f4(&c, 0); //expected-error {{constant expression}} 
expected-note {{null passed}}
-constexpr int i42 = f4(0, &c); //expected-error {{constant expression}} 
expected-note {{null passed}}
+constexpr int i4 = f4(&c, 0, 0); //expected-error {{constant expression}} 
expected-note {{null passed}}
+constexpr int i42 = f4(0, &c, 1); //expected-error {{constant expression}} 
expected-note {{null passed}}
+constexpr int i43 = f4(&c, &c, 0);
 
 }
\ No newline at end of file


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


r372530 - [clang] fixing conditional explicit for out-of-line definition PR42980

2019-09-22 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Sun Sep 22 14:59:10 2019
New Revision: 372530

URL: http://llvm.org/viewvc/llvm-project?rev=372530&view=rev
Log:
[clang] fixing conditional explicit for out-of-line definition PR42980

Summary: not every read in CXXConstructorDecl::getExplicitSpecifierInternal() 
was made on the canonical declaration.

Reviewers: rsmith, aaron.ballman

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=372530&r1=372529&r2=372530&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Sun Sep 22 14:59:10 2019
@@ -2555,9 +2555,9 @@ class CXXConstructorDecl final
 
   ExplicitSpecifier getExplicitSpecifierInternal() const {
 if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier)
-  return *getCanonicalDecl()->getTrailingObjects();
+  return *getTrailingObjects();
 return ExplicitSpecifier(
-nullptr, getCanonicalDecl()->CXXConstructorDeclBits.IsSimpleExplicit
+nullptr, CXXConstructorDeclBits.IsSimpleExplicit
  ? ExplicitSpecKind::ResolvedTrue
  : ExplicitSpecKind::ResolvedFalse);
   }
@@ -2598,10 +2598,10 @@ public:
  InheritedConstructor Inherited = InheritedConstructor());
 
   ExplicitSpecifier getExplicitSpecifier() {
-return getExplicitSpecifierInternal();
+return getCanonicalDecl()->getExplicitSpecifierInternal();
   }
   const ExplicitSpecifier getExplicitSpecifier() const {
-return getExplicitSpecifierInternal();
+return getCanonicalDecl()->getExplicitSpecifierInternal();
   }
 
   /// Return true if the declartion is already resolved to be explicit.

Modified: cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp?rev=372530&r1=372529&r2=372530&view=diff
==
--- cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx2a-explicit-bool.cpp Sun Sep 22 14:59:10 2019
@@ -717,3 +717,21 @@ A d2{0, 0};
 A d3 = {0.0, 0.0};// expected-error {{explicit deduction guide}}
 
 }
+
+namespace PR42980 {
+using size_t = decltype(sizeof(0));
+
+struct Str {// expected-note+ {{candidate constructor}}
+  template 
+  explicit(N > 7)// expected-note {{resolved to true}}
+  Str(char const (&str)[N]);
+};
+
+template 
+Str::Str(char const(&str)[N]) { }
+// expected-note@-1 {{candidate constructor}}
+
+Str a = "short";
+Str b = "not so short";// expected-error {{no viable conversion}}
+
+}
\ No newline at end of file


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


r364011 - [clang] Small improvments after Adding APValue to ConstantExpr

2019-06-21 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Fri Jun 21 01:26:21 2019
New Revision: 364011

URL: http://llvm.org/viewvc/llvm-project?rev=364011&view=rev
Log:
[clang] Small improvments after Adding APValue to ConstantExpr

Summary:
this patch has multiple small improvements related to the APValue in 
ConstantExpr.

changes:
 - APValue in ConstantExpr are now cleaned up using ASTContext::addDestruction 
instead of there own system.
 - ConstantExprBits Stores the ValueKind of the result beaing stored.
 - VerifyIntegerConstantExpression now stores the evaluated value in 
ConstantExpr.
 - the Constant Evaluator uses the stored value of ConstantExpr when available.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=364011&r1=364010&r2=364011&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Jun 21 01:26:21 2019
@@ -2751,12 +2751,11 @@ public:
   ///
   /// \param Data Pointer data that will be provided to the callback function
   /// when it is called.
-  void AddDeallocation(void (*Callback)(void*), void *Data);
+  void AddDeallocation(void (*Callback)(void *), void *Data) const;
 
   /// If T isn't trivially destructible, calls AddDeallocation to register it
   /// for destruction.
-  template 
-  void addDestruction(T *Ptr) {
+  template  void addDestruction(T *Ptr) const {
 if (!std::is_trivially_destructible::value) {
   auto DestroyPtr = [](void *V) { static_cast(V)->~T(); };
   AddDeallocation(DestroyPtr, Ptr);
@@ -2819,10 +2818,6 @@ public:
   APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E,
  bool MayCreate);
 
-  /// Adds an APValue that will be destructed during the destruction of the
-  /// ASTContext.
-  void AddAPValueCleanup(APValue *Ptr) const { APValueCleanups.push_back(Ptr); 
}
-
   /// Return a string representing the human readable name for the specified
   /// function declaration or file name. Used by SourceLocExpr and
   /// PredefinedExpr to cache evaluated results.
@@ -2989,7 +2984,7 @@ private:
   // in order to track and run destructors while we're tearing things down.
   using DeallocationFunctionsAndArguments =
   llvm::SmallVector, 16>;
-  DeallocationFunctionsAndArguments Deallocations;
+  mutable DeallocationFunctionsAndArguments Deallocations;
 
   // FIXME: This currently contains the set of StoredDeclMaps used
   // by DeclContext objects.  This probably should not be in ASTContext,

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=364011&r1=364010&r2=364011&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Jun 21 01:26:21 2019
@@ -998,6 +998,9 @@ public:
EmptyShell Empty);
 
   static ResultStorageKind getStorageKind(const APValue &Value);
+  static ResultStorageKind getStorageKind(const Type *T,
+  const ASTContext &Context);
+
   SourceLocation getBeginLoc() const LLVM_READONLY {
 return SubExpr->getBeginLoc();
   }
@@ -1009,25 +1012,20 @@ public:
 return T->getStmtClass() == ConstantExprClass;
   }
 
-  void SetResult(APValue Value) { MoveIntoResult(Value); }
-  void MoveIntoResult(APValue &Value);
+  void SetResult(APValue Value, const ASTContext &Context) {
+MoveIntoResult(Value, Context);
+  }
+  void MoveIntoResult(APValue &Value, const ASTContext &Context);
 
   APValue::ValueKind getResultAPValueKind() const {
-switch (ConstantExprBits.ResultKind) {
-case ConstantExpr::RSK_APValue:
-  return APValueResult().getKind();
-case ConstantExpr::RSK_Int64:
-  return APValue::Int;
-case ConstantExpr::RSK_None:
-  return APValue::None;
-}
-llvm_unreachable("invalid ResultKind");
+return static_cast(ConstantExprBits.APValueKind);
   }
   ResultStorageKind getResultStorageKind() const {
 return static_cast(ConstantExprBits.ResultKind);
   }
   APValue getAPValueResult() const;
-
+  const APValue &getResultAsAPValue() const { return APValueResult(); }
+  llvm::APSInt getResultAsAPSInt() const;
   // Iterators
   child_range children() { return child_range(&SubExpr, &SubExpr+1); }
   const_child_range children() const {


r363920 - Revert "[clang] Fixing windows buildbot after D61552"

2019-06-20 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Thu Jun 20 03:34:02 2019
New Revision: 363920

URL: http://llvm.org/viewvc/llvm-project?rev=363920&view=rev
Log:
Revert "[clang] Fixing windows buildbot after D61552"

This reverts commit 5d5d2ca69e2b29b36db1a7dd1993ead7b7d2680f.

has already been fixed by c230eea2f349533468e14672eee94c2016476784

Modified:
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=363920&r1=363919&r2=363920&view=diff
==
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Thu Jun 20 03:34:02 2019
@@ -603,8 +603,6 @@ const internal::VariadicDynCastAllOfMatc
 const internal::VariadicDynCastAllOfMatcher cxxMethodDecl;
 const internal::VariadicDynCastAllOfMatcher
 cxxConversionDecl;
-const internal::VariadicDynCastAllOfMatcher
-cxxDeductionGuideDecl;
 const internal::VariadicDynCastAllOfMatcher varDecl;
 const internal::VariadicDynCastAllOfMatcher fieldDecl;
 const internal::VariadicDynCastAllOfMatcher


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


r363919 - [clang] Fixing windows buildbot after D61552

2019-06-20 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Thu Jun 20 03:27:14 2019
New Revision: 363919

URL: http://llvm.org/viewvc/llvm-project?rev=363919&view=rev
Log:
[clang] Fixing windows buildbot after D61552

Summary:
original review : https://reviews.llvm.org/D61552

build bot faillure : 
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/110

this adds a missing definition of cxxDeductionGuideDecl.
surprisingly it was still working on linux with out it.

Reviewers: aaron.ballman

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

Modified:
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=363919&r1=363918&r2=363919&view=diff
==
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Thu Jun 20 03:27:14 2019
@@ -603,6 +603,8 @@ const internal::VariadicDynCastAllOfMatc
 const internal::VariadicDynCastAllOfMatcher cxxMethodDecl;
 const internal::VariadicDynCastAllOfMatcher
 cxxConversionDecl;
+const internal::VariadicDynCastAllOfMatcher
+cxxDeductionGuideDecl;
 const internal::VariadicDynCastAllOfMatcher varDecl;
 const internal::VariadicDynCastAllOfMatcher fieldDecl;
 const internal::VariadicDynCastAllOfMatcher


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


r363855 - [clang] Adapt ASTMatcher to explicit(bool) specifier

2019-06-19 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Wed Jun 19 11:27:56 2019
New Revision: 363855

URL: http://llvm.org/viewvc/llvm-project?rev=363855&view=rev
Log:
[clang] Adapt ASTMatcher to explicit(bool) specifier

Summary:
Changes:
 - add an ast matcher for deductiong guide.
 - allow isExplicit matcher for deductiong guide.
 - add hasExplicitSpecifier matcher which give access to the expression of the 
explicit specifier if present.

Reviewers: klimek, rsmith, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=363855&r1=363854&r2=363855&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed Jun 19 11:27:56 2019
@@ -194,6 +194,16 @@ Example matches the operator.
 
 
 
+MatcherDecl>cxxDeductionGuideDeclMatcherCXXDeductionGuideDecl>...
+Matches 
user-defined and implicitly generated deduction guide.
+
+Example matches the deduction guide.
+  template
+  class X { X(int) };
+  X(int) -> X;
+
+
+
 MatcherDecl>cxxDestructorDeclMatcherCXXDestructorDecl>...
 Matches explicit 
C++ destructor declarations.
 
@@ -,18 +2232,26 @@ cxxConstructorDecl(isDelegatingConstruct
 
 
 MatcherCXXConstructorDecl>isExplicit
-Matches constructor and 
conversion declarations that are marked with
-the explicit keyword.
+Matches constructor, 
conversion function, and deduction guide declarations
+that have an explicit specifier if this explicit specifier is resolved to
+true.
 
 Given
+  template
   struct S {
 S(int); // #1
 explicit S(double); // #2
 operator int(); // #3
 explicit operator bool(); // #4
-  };
-cxxConstructorDecl(isExplicit()) will match #2, but not #1.
+explicit(false) S(bool) // # 7
+explicit(true) S(char) // # 8
+explicit(b) S(S) // # 9
+  };
+  S(int) -> S // #5
+  explicit S(double) -> S // #6
+cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
 cxxConversionDecl(isExplicit()) will match #4, but not #3.
+cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
 
 
 
@@ -2251,18 +2269,26 @@ cxxConstructorDecl(isMoveConstructor())
 
 
 MatcherCXXConversionDecl>isExplicit
-Matches constructor and 
conversion declarations that are marked with
-the explicit keyword.
+Matches constructor, 
conversion function, and deduction guide declarations
+that have an explicit specifier if this explicit specifier is resolved to
+true.
 
 Given
+  template
   struct S {
 S(int); // #1
 explicit S(double); // #2
 operator int(); // #3
 explicit operator bool(); // #4
-  };
-cxxConstructorDecl(isExplicit()) will match #2, but not #1.
+explicit(false) S(bool) // # 7
+explicit(true) S(char) // # 8
+explicit(b) S(S) // # 9
+  };
+  S(int) -> S // #5
+  explicit S(double) -> S // #6
+cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
 cxxConversionDecl(isExplicit()) will match #4, but not #3.
+cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
 
 
 
@@ -2317,6 +2343,30 @@ cxxConstructorDecl(hasAnyConstructorInit
 
 
 
+MatcherCXXDeductionGuideDecl>isExplicit
+Matches constructor, 
conversion function, and deduction guide declarations
+that have an explicit specifier if this explicit specifier is resolved to
+true.
+
+Given
+  template
+  struct S {
+S(int); // #1
+explicit S(double); // #2
+operator int(); // #3
+explicit operator bool(); // #4
+explicit(false) S(bool) // # 7
+explicit(true) S(char) // # 8
+explicit(b) S(S) // # 9
+  };
+  S(int) -> S // #5
+  explicit S(double) -> S // #6
+cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
+cxxConversionDecl(isExplicit()) will match #4, but not #3.
+cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
+
+
+
 Matcher

r363493 - [clang] Add storage for APValue in ConstantExpr

2019-06-15 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Sat Jun 15 03:24:47 2019
New Revision: 363493

URL: http://llvm.org/viewvc/llvm-project?rev=363493&view=rev
Log:
[clang] Add storage for APValue in ConstantExpr

Summary:
When using ConstantExpr we often need the result of the expression to be kept 
in the AST. Currently this is done on a by the node that needs the result and 
has been done multiple times for enumerator, for constexpr variables... . This 
patch adds to ConstantExpr the ability to store the result of evaluating the 
expression. no functional changes expected.

Changes:
 - Add trailling object to ConstantExpr that can hold an APValue or an 
uint64_t. the uint64_t is here because most ConstantExpr yield integral values 
so there is an optimized layout for integral values.
 - Add basic* serialization support for the trailing result.
 - Move conversion functions from an enum to a fltSemantics from 
clang::FloatingLiteral to llvm::APFloatBase. this change is to make it usable 
for serializing APValues.
 - Add basic* Import support for the trailing result.
 - ConstantExpr created in CheckConvertedConstantExpression now stores the 
result in the ConstantExpr Node.
 - Adapt AST dump to print the result when present.

basic* : None, Indeterminate, Int, Float, FixedPoint, ComplexInt, ComplexFloat,
the result is not yet used anywhere but for -ast-dump.

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: rnkovacs, hiraditya, dexonsmith, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Modified:
cfe/trunk/include/clang/AST/APValue.h
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/AST/TextNodeDumper.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/AST/APValue.cpp
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/AST/ast-dump-color.cpp

Modified: cfe/trunk/include/clang/AST/APValue.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=363493&r1=363492&r2=363493&view=diff
==
--- cfe/trunk/include/clang/AST/APValue.h (original)
+++ cfe/trunk/include/clang/AST/APValue.h Sat Jun 15 03:24:47 2019
@@ -182,6 +182,10 @@ public:
   struct NoLValuePath {};
   struct UninitArray {};
   struct UninitStruct {};
+
+  friend class ASTReader;
+  friend class ASTWriter;
+
 private:
   ValueKind Kind;
 
@@ -326,8 +330,8 @@ public:
   void dump() const;
   void dump(raw_ostream &OS) const;
 
-  void printPretty(raw_ostream &OS, ASTContext &Ctx, QualType Ty) const;
-  std::string getAsString(ASTContext &Ctx, QualType Ty) const;
+  void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const;
+  std::string getAsString(const ASTContext &Ctx, QualType Ty) const;
 
   APSInt &getInt() {
 assert(isInt() && "Invalid accessor");

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=363493&r1=363492&r2=363493&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Jun 15 03:24:47 2019
@@ -271,6 +271,9 @@ private:
   llvm::DenseMap
 MaterializedTemporaryValues;
 
+  /// Used to cleanups APValues stored in the AST.
+  mutable llvm::SmallVector APValueCleanups;
+
   /// A cache mapping a string value to a StringLiteral object with the same
   /// value.
   ///
@@ -2816,6 +2819,10 @@ public:
   APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E,
  bool MayCreate);
 
+  /// Adds an APValue that will be destructed during the destruction of the
+  /// ASTContext.
+  void AddAPValueCleanup(APValue *Ptr) const { APValueCleanups.push_back(Ptr); 
}
+
   /// Return a string representing the human readable name for the specified
   /// function declaration or file name. Used by SourceLocExpr and
   /// PredefinedExpr to cache evaluated results.

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=363493&r1=363492&r2=363493&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jun 15 03:24:47 2019
@@ -943,21 +943,61 @@ public:
   }
 };
 
-/// ConstantExpr - An expression th

r363488 - [clang] perform semantic checking in constant context

2019-06-15 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Sat Jun 15 01:32:56 2019
New Revision: 363488

URL: http://llvm.org/viewvc/llvm-project?rev=363488&view=rev
Log:
[clang] perform semantic checking in constant context

Summary:
Since the addition of __builtin_is_constant_evaluated the result of an 
expression can change based on whether it is evaluated in constant context. a 
lot of semantic checking performs evaluations with out specifying context. 
which can lead to wrong diagnostics.
for example:
```
constexpr int i0 = (long long)__builtin_is_constant_evaluated() * (1ll << 33); 
//#1
constexpr int i1 = (long long)!__builtin_is_constant_evaluated() * (1ll << 33); 
//#2
```
before the patch, #2 was diagnosed incorrectly and #1 wasn't diagnosed.
after the patch #1 is diagnosed as it should and #2 isn't.

Changes:
 - add a flag to Sema to passe in constant context mode.
 - in SemaChecking.cpp calls to Expr::Evaluate* are now done in constant 
context when they should.
 - in SemaChecking.cpp diagnostics for UB are not checked for in constant 
context because an error will be emitted by the constant evaluator.
 - in SemaChecking.cpp diagnostics for construct that cannot appear in constant 
context are not checked for in constant context.
 - in SemaChecking.cpp diagnostics on constant expression are always emitted 
because constant expression are always evaluated.
 - semantic checking for initialization of constexpr variables is now done in 
constant context.
 - adapt test that were depending on warning changes.
 - add test.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/attr-nonnull.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=363488&r1=363487&r2=363488&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jun 15 01:32:56 2019
@@ -599,7 +599,8 @@ public:
   /// which we can fold and convert to a boolean condition using
   /// any crazy technique that we want to, even if the expression has
   /// side-effects.
-  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const;
+  bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx,
+  bool InConstantContext = false) const;
 
   enum SideEffectsKind {
 SE_NoSideEffects,  ///< Strictly evaluate the expression.
@@ -611,20 +612,21 @@ public:
   /// EvaluateAsInt - Return true if this is a constant which we can fold and
   /// convert to an integer, using any crazy technique that we want to.
   bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
- SideEffectsKind AllowSideEffects = SE_NoSideEffects) 
const;
+ SideEffectsKind AllowSideEffects = SE_NoSideEffects,
+ bool InConstantContext = false) const;
 
   /// EvaluateAsFloat - Return true if this is a constant which we can fold and
   /// convert to a floating point value, using any crazy technique that we
   /// want to.
-  bool
-  EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx,
-  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
+  bool EvaluateAsFloat(llvm::APFloat &Result, const ASTContext &Ctx,
+   SideEffectsKind AllowSideEffects = SE_NoSideEffects,
+   bool InConstantContext = false) const;
 
   /// EvaluateAsFloat - Return true if this is a constant which we can fold and
   /// convert to a fixed point value.
-  bool EvaluateAsFixedPoint(
-  EvalResult &Result, const ASTContext &Ctx,
-  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
+  bool EvaluateAsFixedPoint(EvalResult &Result, const ASTContext &Ctx,
+SideEffectsKind AllowSideEffects = 
SE_NoSideEffects,
+bool InConstantContext = false) const;
 
   /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
   /// constant folded without side-effects, but discard the result.
@@ -660,7 +662,8 @@ public:
 
   /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
   /// lvalue with link time known address, with no side-effects.
-  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const;
+  bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx,
+bool InConstantContext = false) const;
 
   /// EvaluateAsInitializer - Evaluate an expression as if it were the
   /// initializer of

r363362 - [C++20] add Basic consteval specifier

2019-06-15 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Fri Jun 14 01:56:20 2019
New Revision: 363362

URL: http://llvm.org/viewvc/llvm-project?rev=363362&view=rev
Log:
[C++20] add Basic consteval specifier

Summary:
this revision adds Lexing, Parsing and Basic Semantic for the consteval 
specifier as specified by 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1073r3.html

with this patch, the consteval specifier is treated as constexpr but can only 
be applied to function declaration.

Changes:
 - add the consteval keyword.
 - add parsing of consteval specifier for normal declarations and lambdas 
expressions.
 - add the whether a declaration is constexpr is now represented by and enum 
everywhere except for variable because they can't be consteval.
 - adapt diagnostic about constexpr to print constexpr or consteval depending 
on the case.
 - add tests for basic semantic.

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: eraman, efriedma, rnkovacs, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/SemaCXX/cxx2a-consteval.cpp
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaCoroutine.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/SemaCXX/cxx2a-compat.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=363362&r1=363361&r2=363362&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Jun 14 01:56:20 2019
@@ -1861,7 +1861,7 @@ protected:
   FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation 
StartLoc,
const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified,
-   bool isConstexprSpecified);
+   ConstexprSpecKind ConstexprKind);
 
   using redeclarable_base = Redeclarable;
 
@@ -1891,29 +1891,24 @@ public:
   using redeclarable_base::getMostRecentDecl;
   using redeclarable_base::isFirstDecl;
 
-  static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
-  SourceLocation StartLoc, SourceLocation NLoc,
-  DeclarationName N, QualType T,
-  TypeSourceInfo *TInfo,
-  StorageClass SC,
-  bool isInlineSpecified = false,
-  bool hasWrittenPrototype = true,
-  bool isConstexprSpecified = false) {
+  static FunctionDecl *
+  Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
+ SourceLocation NLoc, DeclarationName N, QualType T,
+ TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified = 
false,
+ bool hasWrittenPrototype = true,
+ ConstexprSpecKind ConstexprKind = CSK_unspecified) {
 DeclarationNameInfo NameInfo(N, NLoc);
-return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo,
-SC,
+return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
 isInlineSpecified, hasWrittenPrototype,
-isConstexprSpecified);
+ConstexprKind);
   }
 
   static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
   SourceLocation StartLoc,
-  const DeclarationNameInfo &NameInfo,
-  QualType T, TypeSourceInfo *TInfo,
-  StorageClass SC,
-  

r363361 - [clang] Fixing incorrect implicit deduction guides (PR41549)

2019-06-15 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Fri Jun 14 01:40:04 2019
New Revision: 363361

URL: http://llvm.org/viewvc/llvm-project?rev=363361&view=rev
Log:
[clang] Fixing incorrect implicit deduction guides (PR41549)

Summary:
[[ https://bugs.llvm.org/show_bug.cgi?id=41549 | bug report ]]

Before this patch, implicit deduction guides were generated from the first 
declaration found by lookup.
With this patch implicit deduction guides are generated from the definition of 
the class template.
Also added test that was previously failing.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits, Quuxplusone

Tags: #clang

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

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=363361&r1=363360&r2=363361&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Jun 14 01:40:04 2019
@@ -2052,6 +2052,12 @@ private:
 
 void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
   SourceLocation Loc) {
+  if (CXXRecordDecl *DefRecord =
+  cast(Template->getTemplatedDecl())->getDefinition()) {
+TemplateDecl *DescribedTemplate = DefRecord->getDescribedClassTemplate();
+Template = DescribedTemplate ? DescribedTemplate : Template;
+  }
+
   DeclContext *DC = Template->getDeclContext();
   if (DC->isDependentContext())
 return;

Modified: cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp?rev=363361&r1=363360&r2=363361&view=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp 
(original)
+++ cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Fri Jun 
14 01:40:04 2019
@@ -489,6 +489,21 @@ static_assert(__is_same(decltype(ta), Te
 }
 #pragma clang diagnostic pop
 
+namespace PR41549 {
+
+template  struct umm;
+
+template 
+struct umm {
+  umm(H h = 0, P p = 0);
+};
+
+template  struct umm;
+
+umm m(1);
+
+}
+
 #else
 
 // expected-no-diagnostics


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


r363360 - [clang] Don't segfault on incorrect using directive (PR41400)

2019-06-14 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Fri Jun 14 01:25:52 2019
New Revision: 363360

URL: http://llvm.org/viewvc/llvm-project?rev=363360&view=rev
Log:
[clang] Don't segfault on incorrect using directive (PR41400)

Summary:
this is a bugfixe for [[ https://bugs.llvm.org/show_bug.cgi?id=41400 | PR41400 
]]

added nullptr check at the relevent place and test

Reviewers: rsmith, riccibruno

Reviewed By: rsmith

Subscribers: jkooker, jkorous, riccibruno, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/using-decl-1.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=363360&r1=363359&r2=363360&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Jun 14 01:25:52 2019
@@ -90,7 +90,7 @@ ParsedType Sema::getConstructorName(Iden
   // When naming a constructor as a member of a dependent context (eg, in a
   // friend declaration or an inherited constructor declaration), form an
   // unresolved "typename" type.
-  if (CurClass->isDependentContext() && !EnteringContext) {
+  if (CurClass->isDependentContext() && !EnteringContext && SS.getScopeRep()) {
 QualType T = Context.getDependentNameType(ETK_None, SS.getScopeRep(), &II);
 return ParsedType::make(T);
   }

Modified: cfe/trunk/test/SemaCXX/using-decl-1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/using-decl-1.cpp?rev=363360&r1=363359&r2=363360&view=diff
==
--- cfe/trunk/test/SemaCXX/using-decl-1.cpp (original)
+++ cfe/trunk/test/SemaCXX/using-decl-1.cpp Fri Jun 14 01:25:52 2019
@@ -396,3 +396,10 @@ namespace tag_vs_var {
   using N::Y;
   using N::Z;
 }
+
+// expected-error@+5 {{requires a qualified name}}
+// expected-error@+4 {{expected ';'}}
+// expected-error@+3 {{expected '}'}}
+// expected-note@+2 {{to match this '{'}}
+// expected-error@+1 {{expected ';'}}
+template struct S { using S
\ No newline at end of file


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