This is an archive of the discontinued LLVM Phabricator instance.

Fixed a build error when using CMake 3.15.1 + NDK-R20
ClosedPublic

Authored by azhuang on Dec 23 2020, 9:28 PM.

Details

Summary

std::decay_t used by llvm/utils/benchmark/include/benchmark/benchmark.h is a c++14 feature, but the CMakelist uses c++11, it's the root-cause of build error.

There are two options to fix the error.
1) change the CMakelist to support c++14.
2) change std::decay_t to std::decay, it's what the patch done.

This bug can only be reproduced by CMake 3.15, we didn't observer the bug with CMake 3.16. But based on the code's logic, it's an obvious bug of LLVM.

Diff Detail

Event Timeline

azhuang created this revision.Dec 23 2020, 9:28 PM
azhuang requested review of this revision.Dec 23 2020, 9:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 23 2020, 9:28 PM
lebedev.ri requested changes to this revision.Dec 23 2020, 11:17 PM

Please

  1. Proceed with 2) change std::decay_t to std::decay fix instead
  2. Please submit it upstream first
This revision now requires changes to proceed.Dec 23 2020, 11:17 PM
azhuang updated this revision to Diff 313660.Dec 23 2020, 11:41 PM
azhuang edited the summary of this revision. (Show Details)

Changed change std::decay_t to std::decay as per review.

Update the patch.

... will you please also submit this upstream?

I cannot push to the github.

haz20@hazpc:~/nvme0/git/llvm-project$ git push origin HEAD:main
Username for 'https://github.com': AnzhongHuang
Password for 'https://AnzhongHuang@github.com':
remote: Permission to llvm/llvm-project.git denied to AnzhongHuang.
fatal: unable to access 'https://github.com/llvm/llvm-project.git/': The requested URL returned error: 403

@lebedev.ri Can you tell me how to "submit this upstream"?

@lebedev.ri Can you tell me how to "submit this upstream"?

Err, by upstream i meant submit a PR to the https://github.com/google/benchmark

It looks like we only need to upgrade the file, it was corrected there: https://github.com/google/benchmark/blob/master/include/benchmark/benchmark.h

lebedev.ri accepted this revision.Dec 27 2020, 11:44 PM

Ah, so it's 1bd6123b781120c9190b9ba58b900cdcb718cdd1 that broke this.
Sorry for the noise, let's just go with this fix as is.
Please specify the name e@ma.il to be used for commit's Author: field.

This revision is now accepted and ready to land.Dec 27 2020, 11:44 PM

Author: AnZhong Huang <Anzhong.huang@amd.com>

danilaml added inline comments.
llvm/utils/benchmark/include/benchmark/benchmark.h
993

Shouldn't it be typename std::decay<Lambda>::type ?

@azhuang i guess i should have asked, can you show the build error that happens without this patch?

llvm/utils/benchmark/include/benchmark/benchmark.h
993

Hm, indeed. I'm surprised no bots complained yet.

lebedev.ri reopened this revision.Dec 28 2020, 9:20 AM

@azhuang i guess i should have asked, can you show the build error that happens without this patch?

I have temporarily reverted it for now.

This revision is now accepted and ready to land.Dec 28 2020, 9:20 AM
using BenchType =
    internal::LambdaBenchmark<typename std::decay<Lambda>::type>;

should be correct, I didn't see the original change, but my patch just passed the build, so I thought it's a correct fix.

The build error message without the patch.

00:32:57  /jenkins/workspace/DevOpsTest/Hongmei/vulkan/android_xgl_llpc-psdb/driver_build/drivers/xgl/icd/imported/llvm-project/llvm/utils/benchmark/include/benchmark/benchmark.h:993:52: error: no template named 'decay_t' in namespace 'std'; did you mean 'decay'?
00:32:57    using BenchType = internal::LambdaBenchmark<std::decay_t<Lambda>>;
00:32:57                                                ~~~~~^~~~~~~
00:32:57                                                     decay
00:32:57  /experiments/ndk/android-ndk-r20/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1/type_traits:1363:29: note: 'decay' declared here
00:32:57  struct _LIBCPP_TEMPLATE_VIS decay
00:32:57
azhuang updated this revision to Diff 314046.Dec 29 2020, 6:39 PM

Change the patch based on comments.

using BenchType = internal::LambdaBenchmark<typename std::decay<Lambda>::type>;
Should be a correct fix, but the previous change can also pass compiling :(

Interesting. But during compiling *which* binary does the error manifest? benchmark's tests ?

You can check the amd vulkan driver for the reference, the benchmark folder will be built by default,

00:32:57 [ 1%] Built target CREATE_LLVM_NATIVE
00:32:57 Scanning dependencies of target benchmark

compiler/llpc/llvm/utils/benchmark/src/CMakeFiles/benchmark.dir/benchmark.cc.o

Any further comments on this patch?

I'm being dense here, sorry. I thought benchmark is usually built with -std=c++14,
but as per llvm-project/llvm/utils/benchmark/CMakeLists.txt, that is not the case.
So i'll just reland this.