Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MAINT: fix implicit conversion warnings#31294

Merged
seberg merged 1 commit into
numpy:mainfrom
kumaraditya303:warn
Jun 1, 2026
Merged

MAINT: fix implicit conversion warnings#31294
seberg merged 1 commit into
numpy:mainfrom
kumaraditya303:warn

Conversation

@kumaraditya303
Copy link
Copy Markdown
Contributor

@kumaraditya303 kumaraditya303 commented Apr 21, 2026

PR summary

Fixes #31540

I get a lot of warnings from clang 22 and this PR fixes it:

../numpy/_core/src/multiarray/lowlevel_strided_loops.c.src:988:32: warning: implicit conversion from 'long long' to 'npy_longdouble' (aka 'double') changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-const-int-float-conversion]
  988 |    if (_TO_RTYPE1(src_value) > LLONG_MAX) {
      |                              ~ ^~~~~~~~~
/opt/homebrew/Cellar/llvm/22.1.3/lib/clang/22/include/limits.h:109:20: note: expanded from macro 'LLONG_MAX'
  109 | #define LLONG_MAX  __LONG_LONG_MAX__
      |                    ^~~~~~~~~~~~~~~~~
<built-in>:65:27: note: expanded from macro '__LONG_LONG_MAX__'
   65 | #define __LONG_LONG_MAX__ 9223372036854775807LL

No AI used.

@ngoldbaum
Copy link
Copy Markdown
Member

I think the warning is flagging a real issue - maybe we should just fix it?

Failing that, can you open an issue about the problem the warning is flagging and then add a comment here referring to that issue?

@kumaraditya303 kumaraditya303 changed the title MAINT: ignore implicit conversion warnings MAINT: fix implicit conversion warnings Apr 21, 2026
@ngoldbaum
Copy link
Copy Markdown
Member

Looks like the fix isn’t quite that simple

@ngoldbaum
Copy link
Copy Markdown
Member

Failing that, can you open an issue about the problem the warning is flagging and then add a comment here referring to that issue?

btw I'm also happy with doing this

@seberg
Copy link
Copy Markdown
Member

seberg commented Apr 24, 2026

@mattip just in case you have a quicker thought. Maybe ignoring the warning is even the best thing (so long the compiler doesn't say "this is UB, I'll do something random", I am pretty sure things are correct)...
In C++ I feel we might be able to do a trick like seeing which type is actually used for the comparison and cast to that, but I dunno that is nice.

(I.e. I think the cast is only right if we cast an integer to a float. In all other cases > will do promotion for the comparison and that is necessary?)

@mattip
Copy link
Copy Markdown
Member

mattip commented Apr 24, 2026

I think the problem is on the left side, not the right side, no?

@seberg
Copy link
Copy Markdown
Member

seberg commented Apr 24, 2026

I think the problem is on the left side, not the right side, no?

I don't think that is the problem, we have something like a double->long cast there, which gives us: double_value > LONG_MAX.
(IIRC, RTYPE is just there to cast half to float?)

Normally all is fine:

  • The left hand has a smaller range (e.g. many int->int casts) it is tautological but the compiler realizes that.
  • Both are integer values: I think things work out (but didn't think it fully through again, maybe there is an other branch that deals with signed/unsigned comparison shenanigans)
  • For float to integer casts: The imprecise casts here should be OK, I guess. But we get the new warning here now...

The problem is, adding the cast fixes the last one, but breaks some of the first two.

@kumaraditya303
Copy link
Copy Markdown
Contributor Author

btw I'm also happy with doing this

I opened #31540 and reverted the PR to ignore the warnings.

@seberg
Copy link
Copy Markdown
Member

seberg commented Jun 1, 2026

Thanks, just adding the warning filter makes sense. Really not sure there is a nice other pattern available, TBH.

@seberg seberg merged commit 55460a7 into numpy:main Jun 1, 2026
166 of 171 checks passed
@kumaraditya303 kumaraditya303 deleted the warn branch June 1, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAINT: implicit conversion warnings in lowlevel_strided_loops.c.src

5 participants