[C++20] Add consteval-specific semantic for functions

Summary:
Changes:
 - Calls to consteval function are now evaluated in constant context but IR is still generated for them.
 - Add diagnostic for taking address of a consteval function in non-constexpr context.
 - Add diagnostic for address of consteval function accessible at runtime.
 - Add tests

Reviewers: rsmith, aaron.ballman

Reviewed By: rsmith

Subscribers: mgrang, riccibruno, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63960
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 51d29ae..0b6b1e3 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -280,7 +280,8 @@
 }
 
 ConstantExpr *ConstantExpr::Create(const ASTContext &Context, Expr *E,
-                                   ResultStorageKind StorageKind) {
+                                   ResultStorageKind StorageKind,
+                                   bool IsImmediateInvocation) {
   assert(!isa<ConstantExpr>(E));
   AssertResultStorageKind(StorageKind);
   unsigned Size = totalSizeToAlloc<APValue, uint64_t>(
@@ -288,6 +289,8 @@
       StorageKind == ConstantExpr::RSK_Int64);
   void *Mem = Context.Allocate(Size, alignof(ConstantExpr));
   ConstantExpr *Self = new (Mem) ConstantExpr(E, StorageKind);
+  Self->ConstantExprBits.IsImmediateInvocation =
+      IsImmediateInvocation;
   return Self;
 }
 
@@ -317,7 +320,7 @@
 }
 
 void ConstantExpr::MoveIntoResult(APValue &Value, const ASTContext &Context) {
-  assert(getStorageKind(Value) == ConstantExprBits.ResultKind &&
+  assert(getStorageKind(Value) <= ConstantExprBits.ResultKind &&
          "Invalid storage for this value kind");
   ConstantExprBits.APValueKind = Value.getKind();
   switch (ConstantExprBits.ResultKind) {