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

unsafe mix of type 'bool' and type 'unsigned __int64' in DebugInfo & StringRef #21532

Closed
llvmbot opened this issue Oct 4, 2014 · 4 comments
Closed
Labels
bugzilla Issues migrated from bugzilla

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 4, 2014

Bugzilla Link 21158
Resolution FIXED
Resolved on Oct 04, 2014 14:58
Version trunk
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @dexonsmith

Extended Description

With trunk r219051 Visual C++ warns:

C:\llvm-clean\include\llvm/ADT/StringRef.h(351): warning C4805: '!=' : unsafe mix of type 'bool' and type 'unsigned __int64' in operation (......\lib\Analysis\ModuleDebugInfoPrinter.cpp) [C:\llvm-clean\msvc\lib\Analysis\LLVMAnalysis.vcxproj]
C:\llvm-clean\include\llvm/IR/DebugInfo.h(200) : see reference to function template instantiation 'bool llvm::Stri
ngRef::getAsInteger(unsigned int,T &) const' being compiled
with
[
T=bool
]
C:\llvm-clean\include\llvm/IR/DebugInfo.h(554) : see reference to function template instantiation 'T llvm::DIDescr
iptor::getHeaderFieldAs(unsigned int) const' being compiled
with
[
T=bool
]

the warning may have merit, when getHeaderFieldAs instantiates getAsInteger with T=bool ,the comparison logic

static_cast(ULLVal) != ULLVal)

which for integers checks if the ULLVal fits in a T sized integer will work somewhat differently for a bool. It will check if ULLVal was 0 or 1 and if not return an error code. This in incosistent with the usual C++ assumption that any non-zero is true.

@dexonsmith
Copy link
Mannequin

dexonsmith mannequin commented Oct 4, 2014

This looks to me like it's from my r219010.

Am I right that this warning is coming from StringRef::getAsInteger<bool>()?

If so, the behaviour I expect is: "0" gives false, "1" gives true, anything else is an error. From your description, it sounds like this is what we're getting -- good.

Any idea how to suppress the warning?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Oct 4, 2014

Maybe casting it back to long long so the comparison would be between two long longs:

  if (getAsUnsignedInteger(*this, Radix, ULLVal) ||
      static_cast<long long>(static_cast<T>(ULLVal)) != ULLVal)

I'm building and testing this first.

@dexonsmith
Copy link
Mannequin

dexonsmith mannequin commented Oct 4, 2014

Yup, that should work. You should probably use unsigned long long, since you're in the unsigned code there. Also, add a comment explaining that this is to hide an MSVC warning on bool, or someone is likely to remove the redundant explicit cast in the future.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Oct 4, 2014

Fixed in r219065.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

1 participant