This is an archive of the discontinued LLVM Phabricator instance.

[LLVM][Casting.h] Don't create a temporary while casting.
ClosedPublic

Authored by bzcheeseman on May 12 2022, 10:41 AM.

Details

Summary

C-style casting can create a temporary when compiled by a C++ compiler, which was emitting a warning casting a reference to another reference. We can't use C++-style casting directly because it doesn't always work with incomplete types. In order to support the current use-cases, for references we switch to pointer space to perform the cast.

Diff Detail

Event Timeline

bzcheeseman created this revision.May 12 2022, 10:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2022, 10:41 AM
bzcheeseman requested review of this revision.May 12 2022, 10:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2022, 10:41 AM
bzcheeseman retitled this revision from [LLVM][Casting.h] Don't create a temporary while casting. r=lattner,qiongsiwu1,uabelho to [LLVM][Casting.h] Don't create a temporary while casting..May 12 2022, 11:21 AM
bzcheeseman added a comment.EditedMay 12 2022, 12:04 PM

@qiongsiwu1 or @uabelho please let me know if this fixes the issue you saw. I don't think I see the warning emitted anywhere I was able to repro.

@qiongsiwu1 or @uabelho please let me know if this fixes the issue you saw. I don't think I see the warning emitted anywhere I was able to repro.

Thanks for the fast response @bzcheeseman ! I've tested this patch locally on a ppc machine. The warning is no longer there and all lit tests pass.

@qiongsiwu1 or @uabelho please let me know if this fixes the issue you saw. I don't think I see the warning emitted anywhere I was able to repro.

Thanks for the fast response @bzcheeseman ! I've tested this patch locally on a ppc machine. The warning is no longer there and all lit tests pass.

Great to hear! Once I get all green in CI I'll land this patch.

Hi, we're also getting the original error on AIX https://lab.llvm.org/buildbot/#/builders/214/builds/1255/steps/6/logs/stdio

I applied your patch here and it seems to fix the original error, but there is a new one:

/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:69:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyBaseType>(D);
  ^~~~~~~~~~~~~~~~ ~
/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:70:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyBaseType>(BD);
  ^~~~~~~~~~~~~~~~ ~~
/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:71:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyDerivedType>(BD);
  ^~~~~~~~~~~~~~~~~~~ ~~
bzcheeseman retitled this revision from [LLVM][Casting.h] Don't create a temporary while casting. to [LLVM][Casting.h] Don't create a temporary while casting. r=lattner,qiongsiwu1,uabelho.

Hi, we're also getting the original error on AIX https://lab.llvm.org/buildbot/#/builders/214/builds/1255/steps/6/logs/stdio

I applied your patch here and it seems to fix the original error, but there is a new one:

/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:69:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyBaseType>(D);
  ^~~~~~~~~~~~~~~~ ~
/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:70:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyBaseType>(BD);
  ^~~~~~~~~~~~~~~~ ~~
/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:71:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyDerivedType>(BD);
  ^~~~~~~~~~~~~~~~~~~ ~~

This commit went in last night it looks like to fix that: 52328dafda13711653fd15aa4db34db350471a1f

bzcheeseman retitled this revision from [LLVM][Casting.h] Don't create a temporary while casting. r=lattner,qiongsiwu1,uabelho to [LLVM][Casting.h] Don't create a temporary while casting..May 12 2022, 2:05 PM

Hi, we're also getting the original error on AIX https://lab.llvm.org/buildbot/#/builders/214/builds/1255/steps/6/logs/stdio

I applied your patch here and it seems to fix the original error, but there is a new one:

/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:69:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyBaseType>(D);
  ^~~~~~~~~~~~~~~~ ~
/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:70:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyBaseType>(BD);
  ^~~~~~~~~~~~~~~~ ~~
/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:71:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyDerivedType>(BD);
  ^~~~~~~~~~~~~~~~~~~ ~~

This commit went in last night it looks like to fix that: 52328dafda13711653fd15aa4db34db350471a1f

Oh my mistake, my branch was only up to the other commit. Thank you

Hi, we're also getting the original error on AIX https://lab.llvm.org/buildbot/#/builders/214/builds/1255/steps/6/logs/stdio

I applied your patch here and it seems to fix the original error, but there is a new one:

/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:69:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyBaseType>(D);
  ^~~~~~~~~~~~~~~~ ~
/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:70:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyBaseType>(BD);
  ^~~~~~~~~~~~~~~~ ~~
/llvm-project/llvm/unittests/Support/ExtensibleRTTITest.cpp:71:3: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
  cast<MyDerivedType>(BD);
  ^~~~~~~~~~~~~~~~~~~ ~~

This commit went in last night it looks like to fix that: 52328dafda13711653fd15aa4db34db350471a1f

Oh my mistake, my branch was only up to the other commit. Thank you

No worries! Thanks for bringing it up and repro-ing the fix :)

qiongsiwu1 accepted this revision.May 12 2022, 4:17 PM

LGTM! Thanks!

This revision is now accepted and ready to land.May 12 2022, 4:17 PM
bzcheeseman added a comment.EditedMay 12 2022, 4:30 PM

@qiongsiwu1 I assume you ran the whole test suite with no problems? My machine is rather slow so running check-all takes ~many hours for me

@qiongsiwu1 I assume you ran the whole test suite with no problems? My machine is rather slow so running check-all takes ~many hours for me

Good call - no I did not run the whole test suite. I did run ninja check-all. Let me give the test suite a try as well.

bzcheeseman added a comment.EditedMay 12 2022, 4:34 PM

@qiongsiwu1 I assume you ran the whole test suite with no problems? My machine is rather slow so running check-all takes ~many hours for me

Good call - no I did not run the whole test suite. I did run ninja check-all. Let me give the test suite a try as well.

That's what I meant. I think build kite is running ninja check-clang-tools check-bolt check-mlir check-flang check-all check-lld check-openmp check-clang check-polly check-libc check-llvm

build kite is being flaky right now so I'd love a clean bill of health before landing to unblock folks.

@qiongsiwu1 I assume you ran the whole test suite with no problems? My machine is rather slow so running check-all takes ~many hours for me

Good call - no I did not run the whole test suite. I did run ninja check-all. Let me give the test suite a try as well.

That's what I meant. I think build kite is running ninja check-clang-tools check-bolt check-mlir check-flang check-all check-lld check-openmp check-clang check-polly check-libc check-llvm

build kite is being flaky right now so I'd love a clean bill of health before landing to unblock folks.

Ah I see. I tested check-all, but I did not build flang/openmp/polly/libc for my local testing. Let me give those a go instead of running the "test-suite".

bzcheeseman added a comment.EditedMay 12 2022, 4:37 PM

@qiongsiwu1 I assume you ran the whole test suite with no problems? My machine is rather slow so running check-all takes ~many hours for me

Good call - no I did not run the whole test suite. I did run ninja check-all. Let me give the test suite a try as well.

That's what I meant. I think build kite is running ninja check-clang-tools check-bolt check-mlir check-flang check-all check-lld check-openmp check-clang check-polly check-libc check-llvm

build kite is being flaky right now so I'd love a clean bill of health before landing to unblock folks.

Ah I see. I tested check-all, but I did not build flang/openmp/polly/libc for my local testing. Let me give those a go instead of running the "test-suite".

Many thanks - I assume your build machine is better than mine :)

I got check-clang and check-llvm on my machine and both are all good (which is usually a good sign)

@qiongsiwu1 I assume you ran the whole test suite with no problems? My machine is rather slow so running check-all takes ~many hours for me

Good call - no I did not run the whole test suite. I did run ninja check-all. Let me give the test suite a try as well.

That's what I meant. I think build kite is running ninja check-clang-tools check-bolt check-mlir check-flang check-all check-lld check-openmp check-clang check-polly check-libc check-llvm

build kite is being flaky right now so I'd love a clean bill of health before landing to unblock folks.

Ah I see. I tested check-all, but I did not build flang/openmp/polly/libc for my local testing. Let me give those a go instead of running the "test-suite".

Many thanks - I assume your build machine is better than mine :)

I got check-clang and check-llvm on my machine and both are all good (which is usually a good sign)

No problem! The ppc buildbot (e.g. https://lab.llvm.org/buildbot/#/builders/57/builds/17829/steps/6/logs/stdio) is only testing clang;llvm;clang-tools-extra;lld, and that was what included in my runs. Those were green!

My local OpenMP tests are having some hiccups but it does not seem to have anything to do with this patch. Bolt is not supported on PPC. polly, mlir and flang checks are green. So I am pretty confident that we are good for Linux on Power. @Jake-Egan can comment more on on AIX but it seems we are good there as well.

check-all is green on AIX.

Finally got green on Debian build (seems like check-all on build kite only works at night?) https://buildkite.com/llvm-project/premerge-checks/builds/92657#5c473a5a-6e3d-4247-a307-30df72a6482d

I'll land this to unblock folks, thanks all for helping test!

This revision was landed with ongoing or failed builds.May 12 2022, 8:11 PM
This revision was automatically updated to reflect the committed changes.