This is an archive of the discontinued LLVM Phabricator instance.

[Analyzer] Infer 0 value when the divisible is 0 (bug fix)
ClosedPublic

Authored by martong on Mar 25 2021, 8:06 AM.

Details

Summary

Currently, we infer 0 if the divisible of the modulo op is 0:

int a = x < 0; // a can be 0
int b = a % y; // b is either 1 % sym or 0

However, we don't when the op is / :

int a = x < 0; // a can be 0
int b = a / y; // b is either 1 / sym or 0 / sym

This commit fixes the discrepancy.

Diff Detail

Event Timeline

martong created this revision.Mar 25 2021, 8:06 AM
martong requested review of this revision.Mar 25 2021, 8:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2021, 8:06 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
martong added inline comments.Mar 25 2021, 8:12 AM
clang/test/Analysis/zero-operands.c
44

Note, this is the test that fails without this fix.

The preceding tests are here to demonstrate the current functionality with the other multiplicative operands and will be good for regression testing.

vsavchenko accepted this revision.Mar 25 2021, 8:17 AM

Looks great!

clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
655

I think we should either add: // 0 / x == 0 or modify the comment for BO_Rem

This revision is now accepted and ready to land.Mar 25 2021, 8:17 AM
martong marked an inline comment as done.Mar 25 2021, 10:25 AM

Thanks for the review!

clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
655

Okay, I added the new comment.

This revision was automatically updated to reflect the committed changes.
martong marked an inline comment as done.

Awesome! Thanks!