[clang] c45466c - [clang][Interp] Only emit function_param_value_unknown in C++11 (#67990)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 24 00:28:35 PDT 2023


Author: Timm Baeder
Date: 2023-10-24T09:28:30+02:00
New Revision: c45466cd9a51fe384d2b31e124b77d14c821eb70

URL: https://github.com/llvm/llvm-project/commit/c45466cd9a51fe384d2b31e124b77d14c821eb70
DIFF: https://github.com/llvm/llvm-project/commit/c45466cd9a51fe384d2b31e124b77d14c821eb70.diff

LOG: [clang][Interp] Only emit function_param_value_unknown in C++11 (#67990)

This is also what the current interpreter does.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.cpp
    clang/test/SemaCXX/offsetof.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index a4d6844ebe61722..8b0e7beb4a1acc1 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -555,8 +555,12 @@ bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR) {
   const SourceInfo &E = S.Current->getSource(OpPC);
 
   if (isa<ParmVarDecl>(D)) {
-    S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
-    S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
+    if (S.getLangOpts().CPlusPlus11) {
+      S.FFDiag(E, diag::note_constexpr_function_param_value_unknown) << D;
+      S.Note(D->getLocation(), diag::note_declared_at) << D->getSourceRange();
+    } else {
+      S.FFDiag(E);
+    }
   } else if (const auto *VD = dyn_cast<VarDecl>(D)) {
     if (!VD->getType().isConstQualified()) {
       S.FFDiag(E,

diff  --git a/clang/test/SemaCXX/offsetof.cpp b/clang/test/SemaCXX/offsetof.cpp
index cb91f2bed0b9224..1722b91fafc8696 100644
--- a/clang/test/SemaCXX/offsetof.cpp
+++ b/clang/test/SemaCXX/offsetof.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s -Winvalid-offsetof -std=c++98
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify=expected,new-interp %s -Winvalid-offsetof -std=c++98 -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fsyntax-only -verify %s -Winvalid-offsetof -std=c++98 -fexperimental-new-constant-interpreter
 
 struct NonPOD {
   virtual void f();
@@ -25,10 +25,9 @@ struct HasArray {
 };
 
 // Constant and non-constant offsetof expressions
-void test_ice(int i) { // new-interp-note {{declared here}}
+void test_ice(int i) {
   int array0[__builtin_offsetof(HasArray, array[5])];
-  int array1[__builtin_offsetof(HasArray, array[i])]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \
-                                                         new-interp-note {{function parameter 'i' with unknown value cannot be used in a constant expression}}
+  int array1[__builtin_offsetof(HasArray, array[i])]; // expected-warning {{variable length arrays in C++ are a Clang extension}}
 }
 
 // Bitfields


        


More information about the cfe-commits mailing list