Skip to content

[analyzer][tests][z3] Fixing the test case bug for testing converting boolean expression to integer#183034

Merged
steakhal merged 1 commit intollvm:mainfrom
Snape3058:issue-181581-1
Feb 25, 2026
Merged

[analyzer][tests][z3] Fixing the test case bug for testing converting boolean expression to integer#183034
steakhal merged 1 commit intollvm:mainfrom
Snape3058:issue-181581-1

Conversation

@Snape3058
Copy link
Member

@Snape3058 Snape3058 commented Feb 24, 2026

… boolean expression to integer

* Fixing llvm#108900 for incorrect "REQUIRES" condition for Z3
* Fixing llvm#168034 for the test failure
* Adding more comments about the fixes in llvm#168034 for the tests
  introduced in llvm#158276
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Feb 24, 2026
@llvmbot
Copy link
Member

llvmbot commented Feb 24, 2026

@llvm/pr-subscribers-clang-static-analyzer-1

@llvm/pr-subscribers-clang

Author: Ella Ma (Snape3058)

Changes
  • Fixing #108900 for incorrect "REQUIRES" condition for Z3
  • Fixing #168034 for the test failure
  • Adding more comments about the fixes in #168034 for the tests introduced in #158276

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

1 Files Affected:

  • (modified) clang/test/Analysis/z3-unarysymexpr.c (+9-4)
diff --git a/clang/test/Analysis/z3-unarysymexpr.c b/clang/test/Analysis/z3-unarysymexpr.c
index 82b0fc988a383..efe558c3146e8 100644
--- a/clang/test/Analysis/z3-unarysymexpr.c
+++ b/clang/test/Analysis/z3-unarysymexpr.c
@@ -1,10 +1,10 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s \
-// RUN:  -analyzer-constraints=z3 
+// RUN:  -analyzer-constraints=z3
 // RUN: %clang_analyze_cc1 -verify %s \
 // RUN:  -analyzer-checker=core,debug.ExprInspection \
 // RUN:  -analyzer-config crosscheck-with-z3=true
 
-// REQUIRES: Z3
+// REQUIRES: z3
 //
 // Previously Z3 analysis crashed when it encountered an UnarySymExpr, validate
 // that this no longer happens.
@@ -25,6 +25,10 @@ int negate(int x, int y) {
 // then causes Z3 to crash. The accompanying patch just strips the negative
 // operator before submitting to Z3 to avoid the crash.
 //
+// In PR 168034, we fixed this problem by converting boolean expressions to
+// bitvec with Z3's ite operator "(ite THE_BOOL_EXPR #x00000000 #x00000001)"
+// and actually conducting the negation on the result.
+//
 // TODO: Find the root cause of this and fix it in symbol manager
 //
 void c();
@@ -49,9 +53,10 @@ int z3_crash2(int a) {
 }
 
 // Refer to issue 165779
-void z3_crash3(long a) {
+long z3_crash3(long a) {
   if (~-(5 && a)) {
     long *c;
-    *c; // expected-warning{{Dereference of undefined pointer value (loaded from variable 'c')}}
+    return *c; // expected-warning{{Dereference of undefined pointer value (loaded from variable 'c')}}
   }
+  return 0;
 }

@Snape3058
Copy link
Member Author

Thank you for the review. Please help me merge it if @vabridgers is not against it.

@steakhal steakhal requested a review from NagyDonat February 24, 2026 15:40
Copy link
Contributor

@NagyDonat NagyDonat left a comment

Choose a reason for hiding this comment

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

The change LGTM, but at first I was very confused by the PR description, more precisely the phrasing "Fixing <PR LINK> for <PROBLEM DESCRIPTION>" in the first two bullet points. I'm not a native English speaker, so this may be a valid expression that I'm not familiar with, but I would suggest rephrasing these sentences as "Fixing <PROBLEM DESCRIPTION> introduced in <PR LINK>".

@steakhal
Copy link
Contributor

The change LGTM, but at first I was very confused by the PR description, more precisely the phrasing "Fixing <PR LINK> for <PROBLEM DESCRIPTION>" in the first two bullet points. I'm not a native English speaker, so this may be a valid expression that I'm not familiar with, but I would suggest rephrasing these sentences as "Fixing <PROBLEM DESCRIPTION> introduced in <PR LINK>".

Could you edit the PR description and title as you see fit? @NagyDonat

@NagyDonat
Copy link
Contributor

I edited the PR description. I'm only 98% sure that this was the intended meaning of the original description, so @Snape3058 please check it and fix it if I misunderstood it.

@steakhal steakhal merged commit b91e832 into llvm:main Feb 25, 2026
13 checks passed
@steakhal
Copy link
Contributor

LGTM

Snape3058 added a commit to Snape3058/llvm-patch-revision that referenced this pull request Feb 27, 2026
…is/z3/` subdirectory

Addressing llvm#181581, continuing llvm#183034

This enables executing all test cases with the `REQUIRES: z3` tag via the
`check-clang-analysis-z3` target.
@Snape3058
Copy link
Member Author

Mentioning the original issue #181581 here to make them linked. Sorry for the spam.

steakhal pushed a commit that referenced this pull request Mar 2, 2026
…is/z3/` subdirectory (#183724)

Addressing #181581, continuing #183034

This enables executing all test cases with the `REQUIRES: z3` tag via
the `check-clang-analysis-z3` target.
nasherm pushed a commit to nasherm/llvm-project that referenced this pull request Mar 3, 2026
…is/z3/` subdirectory (llvm#183724)

Addressing llvm#181581, continuing llvm#183034

This enables executing all test cases with the `REQUIRES: z3` tag via
the `check-clang-analysis-z3` target.
sahas3 pushed a commit to sahas3/llvm-project that referenced this pull request Mar 4, 2026
…is/z3/` subdirectory (llvm#183724)

Addressing llvm#181581, continuing llvm#183034

This enables executing all test cases with the `REQUIRES: z3` tag via
the `check-clang-analysis-z3` target.
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
…is/z3/` subdirectory (llvm#183724)

Addressing llvm#181581, continuing llvm#183034

This enables executing all test cases with the `REQUIRES: z3` tag via
the `check-clang-analysis-z3` target.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:static analyzer clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants