[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/74718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
https://github.com/tbaederr edited https://github.com/llvm/llvm-project/pull/74718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
@@ -61,6 +61,11 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) { MD->getParent()->getCaptureFields(LC, LTC); for (auto Cap : LC) { +// Static lambdas cannot have any captures. If this one does, +// it has already been diagnosed and we can only ignore it. +if (MD->isStatic()) puremourning wrote: Not sure we need to even enter this loop. https://github.com/llvm/llvm-project/pull/74718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
https://github.com/puremourning commented: Lgtm https://github.com/llvm/llvm-project/pull/74718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
https://github.com/puremourning edited https://github.com/llvm/llvm-project/pull/74718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/74718 >From cb0cb30f9caea7d73a2bb09068f7187ac3b94408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 7 Dec 2023 14:19:52 +0100 Subject: [PATCH] [clang][Interp] Reject static lambdas with captures A version of #74661 for the new interpreter. It didn't crash before, but we did emit a few non-sensical diagnostics. --- clang/lib/AST/Interp/ByteCodeEmitter.cpp | 5 + clang/test/AST/Interp/cxx23.cpp | 27 +--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index 89b7708c0c2a1..045263447cbc9 100644 --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -61,6 +61,11 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) { MD->getParent()->getCaptureFields(LC, LTC); for (auto Cap : LC) { +// Static lambdas cannot have any captures. If this one does, +// it has already been diagnosed and we can only ignore it. +if (MD->isStatic()) + return nullptr; + unsigned Offset = R->getField(Cap.second)->Offset; this->LambdaCaptures[Cap.first] = { Offset, Cap.second->getType()->isReferenceType()}; diff --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp index e284a66626fb3..bd1cf186d519c 100644 --- a/clang/test/AST/Interp/cxx23.cpp +++ b/clang/test/AST/Interp/cxx23.cpp @@ -4,9 +4,6 @@ // RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=expected23 %s -fexperimental-new-constant-interpreter -// expected23-no-diagnostics - - /// FIXME: The new interpreter is missing all the 'control flows through...' diagnostics. constexpr int f(int n) { // ref20-error {{constexpr function never produces a constant expression}} \ @@ -82,3 +79,27 @@ constexpr int k(int n) { return m; } constexpr int k0 = k(0); + +namespace StaticLambdas { + constexpr auto static_capture_constexpr() { +char n = 'n'; +return [n] static { return n; }(); // expected23-error {{a static lambda cannot have any captures}} \ + // expected20-error {{a static lambda cannot have any captures}} \ + // expected20-warning {{are a C++23 extension}} \ + // expected20-warning {{is a C++23 extension}} \ + // ref23-error {{a static lambda cannot have any captures}} \ + // ref20-error {{a static lambda cannot have any captures}} \ + // ref20-warning {{are a C++23 extension}} \ + // ref20-warning {{is a C++23 extension}} + } + static_assert(static_capture_constexpr()); // expected23-error {{static assertion expression is not an integral constant expression}} \ + // expected20-error {{static assertion expression is not an integral constant expression}} \ + // ref23-error {{static assertion expression is not an integral constant expression}} \ + // ref20-error {{static assertion expression is not an integral constant expression}} + + constexpr auto capture_constexpr() { +char n = 'n'; +return [n] { return n; }(); + } + static_assert(capture_constexpr()); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
shafik wrote: Can you please add more details to the description so folks reading the git log know what the change is without having to do more digging. https://github.com/llvm/llvm-project/pull/74718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
https://github.com/cor3ntin approved this pull request. https://github.com/llvm/llvm-project/pull/74718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes A version of #74661 for the new interpreter. It didn't crash before, but we did emit a few non-sensical diagnostics. --- Full diff: https://github.com/llvm/llvm-project/pull/74718.diff 2 Files Affected: - (modified) clang/lib/AST/Interp/ByteCodeEmitter.cpp (+5) - (modified) clang/test/AST/Interp/cxx23.cpp (+24-3) ``diff diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index 89b7708c0c2a1..045263447cbc9 100644 --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -61,6 +61,11 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) { MD->getParent()->getCaptureFields(LC, LTC); for (auto Cap : LC) { +// Static lambdas cannot have any captures. If this one does, +// it has already been diagnosed and we can only ignore it. +if (MD->isStatic()) + return nullptr; + unsigned Offset = R->getField(Cap.second)->Offset; this->LambdaCaptures[Cap.first] = { Offset, Cap.second->getType()->isReferenceType()}; diff --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp index e284a66626fb3..bd1cf186d519c 100644 --- a/clang/test/AST/Interp/cxx23.cpp +++ b/clang/test/AST/Interp/cxx23.cpp @@ -4,9 +4,6 @@ // RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=expected23 %s -fexperimental-new-constant-interpreter -// expected23-no-diagnostics - - /// FIXME: The new interpreter is missing all the 'control flows through...' diagnostics. constexpr int f(int n) { // ref20-error {{constexpr function never produces a constant expression}} \ @@ -82,3 +79,27 @@ constexpr int k(int n) { return m; } constexpr int k0 = k(0); + +namespace StaticLambdas { + constexpr auto static_capture_constexpr() { +char n = 'n'; +return [n] static { return n; }(); // expected23-error {{a static lambda cannot have any captures}} \ + // expected20-error {{a static lambda cannot have any captures}} \ + // expected20-warning {{are a C++23 extension}} \ + // expected20-warning {{is a C++23 extension}} \ + // ref23-error {{a static lambda cannot have any captures}} \ + // ref20-error {{a static lambda cannot have any captures}} \ + // ref20-warning {{are a C++23 extension}} \ + // ref20-warning {{is a C++23 extension}} + } + static_assert(static_capture_constexpr()); // expected23-error {{static assertion expression is not an integral constant expression}} \ + // expected20-error {{static assertion expression is not an integral constant expression}} \ + // ref23-error {{static assertion expression is not an integral constant expression}} \ + // ref20-error {{static assertion expression is not an integral constant expression}} + + constexpr auto capture_constexpr() { +char n = 'n'; +return [n] { return n; }(); + } + static_assert(capture_constexpr()); +} `` https://github.com/llvm/llvm-project/pull/74718 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Reject static lambdas with captures (PR #74718)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/74718 A version of #74661 for the new interpreter. It didn't crash before, but we did emit a few non-sensical diagnostics. >From 6ac52b644cbd5e12ad13e6c3c2bf84b96ec5f3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 7 Dec 2023 14:19:52 +0100 Subject: [PATCH] [clang][Interp] Reject static lambdas with captures A version of #74661 for the new interpreter. It didn't crash before, but we did emit a few non-sensical diagnostics. --- clang/lib/AST/Interp/ByteCodeEmitter.cpp | 5 + clang/test/AST/Interp/cxx23.cpp | 27 +--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index 89b7708c0c2a1..045263447cbc9 100644 --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -61,6 +61,11 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) { MD->getParent()->getCaptureFields(LC, LTC); for (auto Cap : LC) { +// Static lambdas cannot have any captures. If this one does, +// it has already been diagnosed and we can only ignore it. +if (MD->isStatic()) + return nullptr; + unsigned Offset = R->getField(Cap.second)->Offset; this->LambdaCaptures[Cap.first] = { Offset, Cap.second->getType()->isReferenceType()}; diff --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp index e284a66626fb3..bd1cf186d519c 100644 --- a/clang/test/AST/Interp/cxx23.cpp +++ b/clang/test/AST/Interp/cxx23.cpp @@ -4,9 +4,6 @@ // RUN: %clang_cc1 -std=c++23 -fsyntax-only -fcxx-exceptions -verify=expected23 %s -fexperimental-new-constant-interpreter -// expected23-no-diagnostics - - /// FIXME: The new interpreter is missing all the 'control flows through...' diagnostics. constexpr int f(int n) { // ref20-error {{constexpr function never produces a constant expression}} \ @@ -82,3 +79,27 @@ constexpr int k(int n) { return m; } constexpr int k0 = k(0); + +namespace StaticLambdas { + constexpr auto static_capture_constexpr() { +char n = 'n'; +return [n] static { return n; }(); // expected23-error {{a static lambda cannot have any captures}} \ + // expected20-error {{a static lambda cannot have any captures}} \ + // expected20-warning {{are a C++23 extension}} \ + // expected20-warning {{is a C++23 extension}} \ + // ref23-error {{a static lambda cannot have any captures}} \ + // ref20-error {{a static lambda cannot have any captures}} \ + // ref20-warning {{are a C++23 extension}} \ + // ref20-warning {{is a C++23 extension}} + } + static_assert(static_capture_constexpr()); // expected23-error {{static assertion expression is not an integral constant expression}} \ + // expected20-error {{static assertion expression is not an integral constant expression}} \ + // ref23-error {{static assertion expression is not an integral constant expression}} \ + // ref20-error {{static assertion expression is not an integral constant expression}} + + constexpr auto capture_constexpr() { +char n = 'n'; +return [n] { return n; }(); + } + static_assert(capture_constexpr()); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits