LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 21158 - unsafe mix of type 'bool' and type 'unsigned __int64' in DebugInfo & StringRef
Summary: unsafe mix of type 'bool' and type 'unsigned __int64' in DebugInfo & StringRef
Status: RESOLVED FIXED
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: trunk
Hardware: PC Windows NT
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-04 10:09 PDT by Yaron Keren
Modified: 2014-10-04 14:58 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yaron Keren 2014-10-04 10:09:38 PDT
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<T>(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<bool>(unsigned int) const' being compiled
          with
          [
              T=bool
          ]


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

  static_cast<T>(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.
Comment 1 Duncan 2014-10-04 10:24:34 PDT
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?
Comment 2 Yaron Keren 2014-10-04 11:40:15 PDT
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.
Comment 3 Duncan 2014-10-04 11:45:33 PDT
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.
Comment 4 Yaron Keren 2014-10-04 14:58:56 PDT
Fixed in r219065.