[mailto:jonathan@codesourcery.com] Sent: Tuesday, September 20, 2016
3:33 PM To: Lin, Jin <jin.lin@intel.com>; cfe-dev@lists.llvm.org
Subject: Re: [cfe-dev] question regarding the C++ test case under LLVM
test
I think a better solution is to extend the utility llvm-lit to
process the -target option. If the target option and the host match,
the script will be executed. Otherwise just ignore the test case.
What do you think?
That's actually not better.
The problem you're going to run into is that your host system's
headers are leaking into a target test. Now you have a testcase that
could pass on one machine, but fail on another (even if they're both
linux machines). The buildbots are very good at noticing this kind of
thing because they all run on different host platforms.
If you look through Clang's codegen tests, you'll find that none of
them include anything from the host system... that is not an accident.
It was done very purposefully: all of the codegen tests should behave
precisely the same, no matter what the host platform is, and no matter
what versions of libc/libm/c++ standard library/etc are installed.
There are solutions to the specific questions you're asking (about how
to prevent a testcase from running on a specific platform), but I'm
avoiding telling you them because I think they're solving the wrong
problem (specifically, this is a case of an XY problem:
http://http://xyproblem.info/).
************* The purpose of my test is to check whether the clang
generates the new intrinsic for STL containers such as vector.
Here is the LLVM IR of the vector constructor under Linux and windows.
We can see that the LLVM IR are different. In order to instrument the
new Intrinsic correctly, the clang has to call the utility
getTarget().getTriple().isKnownWindowsMSVCEnvironment() to understand
the OS and perform different action.
This ^ depends entirely on the '-target' triple, and not at all on the host.
For the STL iterator, it is more complicated. Under Linux it is in
gnucxx namespace and under Windows it is in std namespace.
Let's assume I create a file with minimal version of std::vector. Now
the question which version (windows/linux) should I include. One of
them will definitely fail if the script is blindly executed under
Linux and Windows.
Which one you use should depend only on the _target_ triple, and not at all on the _host_.
If you want to stick them in the same file, the preprocessor can be a good way to do that:
// RUN: %clangxx -target i686-pc-linux-gnu ... -DLINUX_32 | FileCheck %s // RUN: %clangxx -target x86_64-pc-mingw32 ... -DWIN_32 | FileCheck %s
#if defined(LINUX_32)
// linux-specific version of the stuff you want to test #elif defined(WIN_32)
// windows-specific version of the stuff you want to test #endif
That is very good suggestions. At least it works for my case.
My concern here is that the code size of test case may increase a lot if we keep adding new OS or platform support by following this approach.
Thanks,
Jin