This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix gcc 9.3.0 warning from -Wtype-limits
Needs ReviewPublic

Authored by vabridgers on Aug 28 2021, 3:54 AM.

Details

Summary

Fixes this warning when using gcc 9.3.0

lib/Target/AMDGPU/R600GenSubtargetInfo.inc:282:62: warning: comparison
of unsigned expression < 0 is always false [-Wtype-limits]
if (Bits[R600::FeatureLocalMemorySize0] && LocalMemorySize <0)

LocalMemorySize = 0;

Diff Detail

Event Timeline

vabridgers created this revision.Aug 28 2021, 3:54 AM
vabridgers requested review of this revision.Aug 28 2021, 3:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 28 2021, 3:54 AM

Can we fix the inc file instead?

Agreed it's better to fix in the inc file. This is generated, any ideas where the source is for the generated file? Perhaps a maintainer could point me in the right direction?

Agreed it's better to fix in the inc file. This is generated, any ideas where the source is for the generated file? Perhaps a maintainer could point me in the right direction?

The code that provokes the warning was generated by SubtargetEmitter::ParseFeaturesFunction in utils/TableGen/SubtargetEmitter.cpp. I'm not sure whether this code knows the exact type of Attribute, e.g. whether it's int or unsigned.

Maybe instead of:

if (Bits[R600::FeatureLocalMemorySize0] && LocalMemorySize < 0) LocalMemorySize = 0;

it could generate:

if (Bits[R600::FeatureLocalMemorySize0]) LocalMemorySize = std::max(LocalMemorySize, 0);

and the warning would go away?