Skip to content

[clang-tidy] Crash with modernize-use-integer-sign-comparison #143927

@VReichelt

Description

@VReichelt

Running clang-tidy with -checks='-*,modernize-use-integer-sign-comparison' and '-std=c++20' (or above) on the code

struct A
{
  unsigned size() const;
};

struct B
{
  A a;

  bool foo(const A& a2) const { return (int)a2.size() == size();  }
  int size() const { return (int)a.size(); }
};

triggers an assertion: clang-tidy: /tmp/LLVM/llvm-project/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp:123: virtual void clang::tidy::modernize::UseIntegerSignComparisonCheck::check(const clang::ast_matchers::MatchFinder::MatchResult&): Assertion 'SignedCastExpression' failed.

This was introduced in the last two weeks, so I suspect this is due to the fix for #127471 .

@RiverDave , @vbvictor : Could you please have a look?

Stacktrace.txt

Activity

llvmbot

llvmbot commented on Jun 12, 2025

@llvmbot
Member

@llvm/issue-subscribers-clang-tidy

Author: None (VReichelt)

Running clang-tidy with -checks='-*,modernize-use-integer-sign-comparison' and '-std=c++20' (or above) on the code
struct A
{
  unsigned size() const;
};

struct B
{
  A a;

  bool foo(const A& a2) const { return (int)a2.size() == size();  }
  int size() const { return (int)a.size(); }
};

triggers an assertion: clang-tidy: /tmp/LLVM/llvm-project/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp:123: virtual void clang::tidy::modernize::UseIntegerSignComparisonCheck::check(const clang::ast_matchers::MatchFinder::MatchResult&): Assertion 'SignedCastExpression' failed.

This was introduced in the last two weeks, so I suspect this is due to the fix for #127471 .

@RiverDave , @vbvictor : Could you please have a look?

Stacktrace.txt

added
crashPrefer [crash-on-valid] or [crash-on-invalid]
on Jun 12, 2025
EugeneZelenko

EugeneZelenko commented on Jun 12, 2025

@EugeneZelenko
Contributor
self-assigned this
on Jun 12, 2025
RiverDave

RiverDave commented on Jun 12, 2025

@RiverDave
Contributor

Taking a look at this as soon as I have the time

vbvictor

vbvictor commented on Jun 12, 2025

@vbvictor
Contributor

Thank you for the quick catch of the bug.
I think we need to revert the changes.

vbvictor

vbvictor commented on Jun 12, 2025

@vbvictor
Contributor

@RiverDave , you could create a revert pr if you wish (I see you got member!), or I can do it in 2-3 hours

RiverDave

RiverDave commented on Jun 12, 2025

@RiverDave
Contributor

@RiverDave , you could create a revert pr if you wish (I see you got member!), or I can do it in 2-3 hours

Done. as a side note what is the general procedure when catching these bugs? I mean once the revert is done, under which issue should everything be resolved?

vbvictor

vbvictor commented on Jun 12, 2025

@vbvictor
Contributor

under which issue should everything be resolved?

I'm not 100% sure, but you may reopen previously closed issue and when reapplying fix mention both issues.

5 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

clang-tidyconfirmedVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @EugeneZelenko@llvmbot@vbvictor@VReichelt@RiverDave

    Issue actions

      [clang-tidy] Crash with modernize-use-integer-sign-comparison · Issue #143927 · llvm/llvm-project