Skip to content

[llvm] fix: fix c++ narrowing conversion#183784

Closed
fzakaria wants to merge 1 commit intollvm:mainfrom
fzakaria:fix-narrowing
Closed

[llvm] fix: fix c++ narrowing conversion#183784
fzakaria wants to merge 1 commit intollvm:mainfrom
fzakaria:fix-narrowing

Conversation

@fzakaria
Copy link

@fzakaria fzakaria commented Feb 27, 2026

Fix for the following:

[103/200] Building CXX object lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o
FAILED: lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o
/home/fmzakari/fbsource/fbcode/third-party-buck/platform010/build/llvm-fb/19/bin/clang++ -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/fmzakari/llvm-build/lib/Transforms/IPO -I/home/fmzakari/local/server-llvm/llvm-project/llvm/lib/Transforms/IPO -I/home/fmzakari/llvm-build/include -I/home/fmzakari/local/server-llvm/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Xclang -fno-pch-timestamp -g -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -Winvalid-pch -Xclang -include-pch -Xclang /home/fmzakari/llvm-build/lib/IR/CMakeFiles/LLVMCore.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /home/fmzakari/llvm-build/lib/IR/CMakeFiles/LLVMCore.dir/cmake_pch.hxx -MD -MT lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o -MF lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o.d -o lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o -c /home/fmzakari/local/server-llvm/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
In file included from /home/fmzakari/local/server-llvm/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:97:
/home/fmzakari/local/server-llvm/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:277:15: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'bool' in initializer list [-Wc++11-narrowing]
  277 |               FSum->flags().ImportType,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~
/home/fmzakari/local/server-llvm/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:277:15: note: insert an explicit cast to silence this issue
  277 |               FSum->flags().ImportType,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~
      |               static_cast<bool>(      )

validation

> ninja lld
[151/151] Linking CXX executable bin/lld

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2026

@llvm/pr-subscribers-llvm-ir

Author: Farid Zakaria (fzakaria)

Changes

Fix for the following:

[103/200] Building CXX object lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o
FAILED: lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o
/home/fmzakari/fbsource/fbcode/third-party-buck/platform010/build/llvm-fb/19/bin/clang++ -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/fmzakari/llvm-build/lib/Transforms/IPO -I/home/fmzakari/local/server-llvm/llvm-project/llvm/lib/Transforms/IPO -I/home/fmzakari/llvm-build/include -I/home/fmzakari/local/server-llvm/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Xclang -fno-pch-timestamp -g -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -Winvalid-pch -Xclang -include-pch -Xclang /home/fmzakari/llvm-build/lib/IR/CMakeFiles/LLVMCore.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /home/fmzakari/llvm-build/lib/IR/CMakeFiles/LLVMCore.dir/cmake_pch.hxx -MD -MT lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o -MF lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o.d -o lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o -c /home/fmzakari/local/server-llvm/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
In file included from /home/fmzakari/local/server-llvm/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:97:
/home/fmzakari/local/server-llvm/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:277:15: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'bool' in initializer list [-Wc++11-narrowing]
  277 |               FSum-&gt;flags().ImportType,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~
/home/fmzakari/local/server-llvm/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:277:15: note: insert an explicit cast to silence this issue
  277 |               FSum-&gt;flags().ImportType,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~
      |               static_cast&lt;bool&gt;(      )

Full diff: https://github.com/llvm/llvm-project/pull/183784.diff

1 Files Affected:

  • (modified) llvm/include/llvm/IR/ModuleSummaryIndexYAML.h (+2-2)
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
index 546dbb6b64e20..51f959d2d60fb 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
@@ -274,7 +274,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
               static_cast<bool>(FSum->flags().Live),
               static_cast<bool>(FSum->flags().DSOLocal),
               static_cast<bool>(FSum->flags().CanAutoHide),
-              FSum->flags().ImportType,
+              static_cast<bool>(FSum->flags().ImportType),
               static_cast<bool>(FSum->flags().NoRenameOnPromotion),
               /*Aliasee=*/std::nullopt, Refs, FSum->type_tests(),
               FSum->type_test_assume_vcalls(), FSum->type_checked_load_vcalls(),
@@ -288,7 +288,7 @@ template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
               static_cast<bool>(ASum->flags().Live),
               static_cast<bool>(ASum->flags().DSOLocal),
               static_cast<bool>(ASum->flags().CanAutoHide),
-              ASum->flags().ImportType,
+              static_cast<bool>(ASum->flags().ImportType),
               static_cast<bool>(ASum->flags().NoRenameOnPromotion),
               /*Aliasee=*/ASum->getAliaseeGUID()});
         }

@boomanaiden154
Copy link
Contributor

#183782 will revert the patch that is causing breakage.

@fzakaria
Copy link
Author

@boomanaiden154 is the revert going in for sure?
Want me to close this?

@fzakaria fzakaria closed this Feb 27, 2026
@yonghong-song
Copy link
Contributor

#183782 will revert the patch that is causing breakage.

I reverted #178587 and then rebased on top of main branch and cannot trigger the compilation error.

BTW, for the following:

[103/200] Building CXX object lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o
FAILED: lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o
/home/fmzakari/fbsource/fbcode/third-party-buck/platform010/build/llvm-fb/19/bin/clang++ -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/fmzakari/llvm-build/lib/Transforms/IPO -I/home/fmzakari/local/server-llvm/llvm-project/llvm/lib/Transforms/IPO -I/home/fmzakari/llvm-build/include -I/home/fmzakari/local/server-llvm/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -Xclang -fno-pch-timestamp -g -std=c++17 -fPIC -fno-exceptions -funwind-tables -fno-rtti -Winvalid-pch -Xclang -include-pch -Xclang /home/fmzakari/llvm-build/lib/IR/CMakeFiles/LLVMCore.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /home/fmzakari/llvm-build/lib/IR/CMakeFiles/LLVMCore.dir/cmake_pch.hxx -MD -MT lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o -MF lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o.d -o lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/WholeProgramDevirt.cpp.o -c /home/fmzakari/local/server-llvm/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
In file included from /home/fmzakari/local/server-llvm/llvm-project/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp:97:
/home/fmzakari/local/server-llvm/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:277:15: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'bool' in initializer list [-Wc++11-narrowing]
  277 |               FSum->flags().ImportType,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~
/home/fmzakari/local/server-llvm/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:277:15: note: insert an explicit cast to silence this issue
  277 |               FSum->flags().ImportType,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~
      |               static_cast<bool>(      )

My patch is not involved with 'FSum->flags().ImportType'. Maybe something else go on?
Could you share you cmake command line which can trigger the above failure?

@yonghong-song
Copy link
Contributor

The new pull request (which is on top of latest main branch, about 10:30am)
#183793
seems building okay now.
Maybe I missed something for this build failure?

@fzakaria
Copy link
Author

@yonghong-song

cmake \
             -G Ninja \
             -DBUILD_SHARED_LIBS=true \
             -DCMAKE_ASM_COMPILER=$MYCLANG \
             -DCMAKE_ASM_COMPILER_ID=Clang \
             -DCMAKE_BUILD_TYPE=Debug \
             -DCMAKE_CXX_COMPILER={$MYCLANG}++ \
             -DCMAKE_C_COMPILER=$MYCLANG \
             -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-redhat-linux-gnu \
             -DLLVM_HOST_TRIPLE=x86_64-redhat-linux-gnu \
             -DLLVM_ENABLE_ASSERTIONS=ON \
             -DLLVM_ENABLE_BINDINGS=OFF \
             -DLLVM_ENABLE_LLD=ON \
             -DLLVM_ENABLE_PROJECTS="clang;lld" \
             -DLLVM_OPTIMIZED_TABLEGEN=true \
             -DLLVM_FORCE_ENABLE_STATS=ON \
             -DLLVM_ENABLE_DUMP=ON \
             -DCLANG_DEFAULT_PIE_ON_LINUX=OFF \
             $LLVMSRC

@yonghong-song
Copy link
Contributor

Thanks @fzakaria, I tried the following cmake command (slightly different from you as I added -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON, otherwise, cmake won't work for me):

cmake \
             -G Ninja \
             -DBUILD_SHARED_LIBS=true \
             -DCMAKE_ASM_COMPILER=/bin/clang \
             -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
             -DCMAKE_BUILD_TYPE=Debug \
             -DCMAKE_CXX_COMPILER=/bin/clang++ \
             -DCMAKE_C_COMPILER=/bin/clang \
             -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-redhat-linux-gnu \
             -DLLVM_HOST_TRIPLE=x86_64-redhat-linux-gnu \
             -DLLVM_ENABLE_ASSERTIONS=ON \
             -DLLVM_ENABLE_BINDINGS=OFF \
             -DLLVM_ENABLE_LLD=ON \
             -DLLVM_ENABLE_PROJECTS="clang;lld" \
             -DLLVM_OPTIMIZED_TABLEGEN=true \
             -DLLVM_FORCE_ENABLE_STATS=ON \
             -DLLVM_ENABLE_DUMP=ON \
             -DCLANG_DEFAULT_PIE_ON_LINUX=OFF \
             ..

The '..' points to llvm directory.

After cmake, I did 'ninja lld' and it works fine for with #183793 on opt of #183649 and the main branch with '[flang-rt] Enable more runtime functions for the GPU target (#183649)'. Both 'ninja lld' are successful.

Do you know which commit you are using which can trigger the error (as in this pull request)?

@yonghong-song
Copy link
Contributor

I also tried the commit
[ThinLTO] Reduce the number of renaming due to promotions (#178587)
which I merged it and llvmbot reports errors like in the description.
And I still cannot reproduce the build error.

Looks like you has identified the error with #178587, could you share how to reproduce?

@yonghong-song
Copy link
Contributor

Also,

/usr/bin/clang++ -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GLIBCXX_USE_CXX11_ABI=1 -D_GNU_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/build/lib/Transforms/IPO -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/llvm-project/llvm/lib/Transforms/IPO -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/build/include -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/llvm-project/llvm/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wno-pass-failed -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fno-exceptions -funwind-tables -fno-rtti -std=c++17 -MD -MT lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/LowerTypeTests.cpp.o -MF lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/LowerTypeTests.cpp.o.d -o lib/Transforms/IPO/CMakeFiles/LLVMipo.dir/LowerTypeTests.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/llvm-project/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/llvm-project/llvm/lib/Transforms/IPO/LowerTypeTests.cpp:55:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:277:15: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'bool' in initializer list [-Wc++11-narrowing]
              FSum->flags().ImportType,
              ^~~~~~~~~~~~~~~~~~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:277:15: note: insert an explicit cast to silence this issue
              FSum->flags().ImportType,
              ^~~~~~~~~~~~~~~~~~~~~~~~
              static_cast<bool>(      )
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:291:15: error: non-constant-expression cannot be narrowed from type 'unsigned int' to 'bool' in initializer list [-Wc++11-narrowing]
              ASum->flags().ImportType,
              ^~~~~~~~~~~~~~~~~~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h:291:15: note: insert an explicit cast to silence this issue
              ASum->flags().ImportType,
              ^~~~~~~~~~~~~~~~~~~~~~~~
              static_cast<bool>(      )

is not involved in my pull request #178587. So it is not clear why my patch is fixing this. It is very suspicious.

@yonghong-song
Copy link
Contributor

Okay, looks like a build compiler issue. llvm21 build compiler is ok but llvm19 build compiler can expose the warning/error. I will do some further debug.

@fzakaria
Copy link
Author

We can re-open this PR if you need please LMK.

@yonghong-song
Copy link
Contributor

Thanks @fzakaria! We did find the failure reason. This is a oversight for #178587. There is a bug in it. The fix is in #183793.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants