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

[analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers #67212

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@ Static Analyzer
Read the PR for the details.
(`#66086 <https://github.com/llvm/llvm-project/pull/66086>`_)

- A few crashes have been found and fixed using randomized testing related
to the use of ``_BitInt()`` in tidy checks and in clang analysis. See
`#67212 <https://github.com/llvm/llvm-project/pull/67212>`_,
`#66782 <https://github.com/llvm/llvm-project/pull/66782>`_,
`#65889 <https://github.com/llvm/llvm-project/pull/65889>`_,
`#65888 <https://github.com/llvm/llvm-project/pull/65888>`_, and
`#65887 <https://github.com/llvm/llvm-project/pull/65887>`_

.. _release-notes-sanitizers:

Sanitizers
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op,
// FIXME: This logic should probably go higher up, where we can
// test these conditions symbolically.

if (V2.isSigned() && V2.isNegative())
if (V2.isNegative() || V2.getBitWidth() > 64)
return nullptr;

uint64_t Amt = V2.getZExtValue();
Expand All @@ -287,7 +287,7 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op,
// FIXME: This logic should probably go higher up, where we can
// test these conditions symbolically.

if (V2.isSigned() && V2.isNegative())
if (V2.isNegative() || V2.getBitWidth() > 64)
return nullptr;

uint64_t Amt = V2.getZExtValue();
Expand Down
15 changes: 15 additions & 0 deletions clang/test/Analysis/int128-nocrash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=optin.portability.UnixAPI \
// RUN: -triple x86_64-pc-linux-gnu -x c %s

// Don't crash!
// expected-no-diagnostics
const __int128_t a = ( (__int128_t)1 << 64 );
const _BitInt(72) b = ( 1 << 72 );

void int128() {
2 >> a;
}

void withbitint() {
2 >> b;
}