Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clang] skip consumed analysis for consteval conditions in control-flow terminators #117403

Merged
merged 3 commits into from
Nov 27, 2024

Conversation

a-tarasyuk
Copy link
Member

@a-tarasyuk a-tarasyuk commented Nov 22, 2024

Fixes #117385


These changes extend the work done in #116513. The changes add additional handling to ensure correct behavior by skipping further checks when a CFG contains a consteval condition, where no explicit expression is present, which is required to proceed with consumed analyses.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:analysis labels Nov 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 22, 2024

@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)

Changes

Fixes #117385


Full diff: https://github.com/llvm/llvm-project/pull/117403.diff

2 Files Affected:

  • (modified) clang/lib/Analysis/Consumed.cpp (+3)
  • (modified) clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp (+8-1)
diff --git a/clang/lib/Analysis/Consumed.cpp b/clang/lib/Analysis/Consumed.cpp
index 63c59432429447..3eb7e5abff7145 100644
--- a/clang/lib/Analysis/Consumed.cpp
+++ b/clang/lib/Analysis/Consumed.cpp
@@ -1229,6 +1229,9 @@ bool ConsumedAnalyzer::splitState(const CFGBlock *CurrBlock,
 
   if (const auto *IfNode =
           dyn_cast_or_null<IfStmt>(CurrBlock->getTerminator().getStmt())) {
+    if (IfNode->isConsteval())
+      return false;
+
     const Expr *Cond = IfNode->getCond();
 
     PInfo = Visitor.getInfo(Cond);
diff --git a/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp b/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
index 19e7d4976428a7..e3228dddef5f66 100644
--- a/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
+++ b/clang/test/SemaCXX/constexpr-return-non-void-cxx2b.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -Wimplicit-fallthrough -verify %s
+// RUN: %clang_cc1 -std=c++23 -fsyntax-only -Wimplicit-fallthrough -Wconsumed -verify %s
 
 constexpr int f() { } // expected-warning {{non-void function does not return a value}}
 static_assert(__is_same(decltype([] constexpr -> int { }( )), int)); // expected-warning {{non-void lambda does not return a value}}
@@ -34,3 +34,10 @@ constinit bool l = j(); // expected-error {{variable does not have a constant in
                         // expected-note {{in call to 'j()'}}
 
 }
+
+namespace GH117385 {
+void f() {
+  if consteval {
+  }
+}
+}

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a release note / commit description?

Otherwise, LGTM

@a-tarasyuk
Copy link
Member Author

@cor3ntin Thanks for there feedback. I've added release notes and updated the description.

@AaronBallman could you review these changes?

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@a-tarasyuk a-tarasyuk merged commit 32ff209 into llvm:main Nov 27, 2024
9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 27, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-darwin running on doug-worker-3 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/23/builds/5268

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: Analysis/scan-build/deduplication.test' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 3
rm -rf /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir && mkdir /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# executed command: rm -rf /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# executed command: mkdir /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# RUN: at line 4
'/usr/bin/perl' '/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/tools/scan-build/bin/scan-build' --use-analyzer=/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang-20  -o /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir              /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang -S /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/1.c                        /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/2.c      | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test -check-prefix CHECK-STDOUT
# executed command: /usr/bin/perl /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/tools/scan-build/bin/scan-build --use-analyzer=/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang-20 -o /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang -S /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/1.c /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/2.c
# .---command stderr------------
# | In file included from /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/1.c:1:
# | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/header.h:3:12: warning: Division by zero [core.DivideZero]
# |     3 |   return 1 / x;
# |       |          ~~^~~
# | 1 warning generated.
# | In file included from /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/2.c:1:
# | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/header.h:3:12: warning: Division by zero [core.DivideZero]
# |     3 |   return 1 / x;
# |       |          ~~^~~
# | 1 warning generated.
# `-----------------------------
# executed command: /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test -check-prefix CHECK-STDOUT
# RUN: at line 9
ls /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir/*/ | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test -check-prefix CHECK-FILENAMES
# executed command: ls '/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir/*/'
# executed command: /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test -check-prefix CHECK-FILENAMES
# RUN: at line 11
rm -rf /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir && mkdir /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# executed command: rm -rf /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# executed command: mkdir /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir
# RUN: at line 12
'/usr/bin/perl' '/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/tools/scan-build/bin/scan-build' --use-analyzer=/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang-20  -o /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir              -analyzer-config stable-report-filename=true              /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang -S /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/1.c                        /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/2.c      | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test -check-prefix CHECK-STDOUT
# executed command: /usr/bin/perl /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/tools/scan-build/bin/scan-build --use-analyzer=/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang-20 -o /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/clang/test/Analysis/scan-build/Output/deduplication.test.tmp.output_dir -analyzer-config stable-report-filename=true /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/clang -S /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/1.c /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/2.c
# .---command stderr------------
# | In file included from /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/1.c:1:
# | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/header.h:3:12: warning: Division by zero [core.DivideZero]
# |     3 |   return 1 / x;
# |       |          ~~^~~
# | 1 warning generated.
# | In file included from /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/2.c:1:
# | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/Inputs/deduplication/header.h:3:12: warning: Division by zero [core.DivideZero]
# |     3 |   return 1 / x;
# |       |          ~~^~~
# | 1 warning generated.
# `-----------------------------
# executed command: /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck /Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/clang/test/Analysis/scan-build/deduplication.test -check-prefix CHECK-STDOUT
# RUN: at line 18
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assertion failure with if consteval + -Wconsumed
5 participants