This is an archive of the discontinued LLVM Phabricator instance.

Make Lit tests C++11 compatible - IR ordering
ClosedPublic

Authored by tigerleapgorge on Feb 27 2017, 2:16 PM.

Details

Summary

This test failure is caused by difference in IR ordering when compiling at C++98 vs C++11
Because there was a CHECK-NOT between the two CHECKs, just changing the CHECKs to CHECK-DAG would not work.

So to make FileCheck more flexible.
I have changed the CHECK to CHECK-DAG.
I have changed CHECK-NOT to go under a new check-prefix CHECK2 so they are CHECK2-NOT.

IR in C++98
@_ZN5test022implicit_instantiationE = global %"struct.test0::stdio_sync_filebuf.2" zeroinitializer, align 8
@__dso_handle = external hidden global i8
@_ZN7PR100011xE = global i32 0, align 4
@_ZTVN5test018stdio_sync_filebufIA3_iEE = weak_odr unnamed_addr constant { [5 x i8*] } { [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTIN5test018stdio_sync_filebufIA3_iEE to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.1"*)* @_ZN5test018stdio_sync_filebufIA3_iED1Ev to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.1"*)* @_ZN5test018stdio_sync_filebufIA3_iED0Ev to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.1"*)* @_ZN5test018stdio_sync_filebufIA3_iE6xsgetnEv to i8*)] }, align 8
@_ZTVN10__cxxabiv120__si_class_type_infoE = external global i8*
@_ZTSN5test018stdio_sync_filebufIA3_iEE = weak_odr constant [35 x i8] c"N5test018stdio_sync_filebufIA3_iEE\00"
@_ZTIN5test015basic_streambufE = external constant i8*
@_ZTIN5test018stdio_sync_filebufIA3_iEE = weak_odr constant { i8*, i8*, i8* } { i8* bitcast (i8 getelementptr inbounds (i8*, i8 @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @_ZTSN5test018stdio_sync_filebufIA3_iEE, i32 0, i32 0), i8* bitcast (i8 @_ZTIN5test015basic_streambufE to i8*) }
@_ZN7PR100011SIiE3arrE = linkonce_odr global [3 x i32] zeroinitializer, align 4
@_ZGVN7PR100011SIiE3arrE = linkonce_odr global i64 0, align 8
@_ZTVN5test018stdio_sync_filebufIA4_iEE = linkonce_odr unnamed_addr constant { [5 x i8*] } { [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTIN5test018stdio_sync_filebufIA4_iEE to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.2"*)* @_ZN5test018stdio_sync_filebufIA4_iED1Ev to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.2"*)* @_ZN5test018stdio_sync_filebufIA4_iED0Ev to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.2"*)* @_ZN5test018stdio_sync_filebufIA4_iE6xsgetnEv to i8*)] }, align 8
@_ZTSN5test018stdio_sync_filebufIA4_iEE = linkonce_odr constant [35 x i8] c"N5test018stdio_sync_filebufIA4_iEE\00"
@_ZTIN5test018stdio_sync_filebufIA4_iEE = linkonce_odr constant { i8*, i8*, i8* } { i8* bitcast (i8
getelementptr inbounds (i8*, i8 @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @_ZTSN5test018stdio_sync_filebufIA4_iEE, i32 0, i32 0), i8* bitcast (i8 @_ZTIN5test015basic_streambufE to i8*) }
@_ZTVN5test015basic_streambufE = available_externally unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* bitcast (i8 @_ZTIN5test015basic_streambufE to i8*), i8* bitcast (void (%"struct.test0::basic_streambuf"*)* @_ZN5test015basic_streambufD1Ev to i8*), i8* bitcast (void (%"struct.test0::basic_streambuf"*)* @_ZN5test015basic_streambufD0Ev to i8*)] }, align 8
@_ZTVN5test21CIiEE = available_externally unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* bitcast (i8
@_ZTIN5test21CIiEE to i8*), i8* bitcast (void (%"class.test2::C"*)* @_ZN5test21CIiED1Ev to i8*), i8* bitcast (void (%"class.test2::C"*)* @_ZN5test21CIiED0Ev to i8*)] }, align 8
@_ZTIN5test21CIiEE = external constant i8*
@llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init.2, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_template_instantiation.cpp, i8* null }]

IR in C++11
@_ZTVN5test018stdio_sync_filebufIA4_iEE = linkonce_odr unnamed_addr constant { [5 x i8*] } { [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTIN5test018stdio_sync_filebufIA4_iEE to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.2"*)* @_ZN5test018stdio_sync_filebufIA4_iED1Ev to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.2"*)* @_ZN5test018stdio_sync_filebufIA4_iED0Ev to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.2"*)* @_ZN5test018stdio_sync_filebufIA4_iE6xsgetnEv to i8*)] }, align 8
@_ZN5test022implicit_instantiationE = global { i8 } { i8 getelementptr inbounds ({ [5 x i8*] }, { [5 x i8*] }* @_ZTVN5test018stdio_sync_filebufIA4_iEE, i32 0, inrange i32 0, i32 2) }, align 8
@__dso_handle = external hidden global i8
@_ZN7PR100011xE = global i32 0, align 4
@_ZTVN5test018stdio_sync_filebufIA3_iEE = weak_odr unnamed_addr constant { [5 x i8*] } { [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTIN5test018stdio_sync_filebufIA3_iEE to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.1"*)* @_ZN5test018stdio_sync_filebufIA3_iED1Ev to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.1"*)* @_ZN5test018stdio_sync_filebufIA3_iED0Ev to i8*), i8* bitcast (void (%"struct.test0::stdio_sync_filebuf.1"*)* @_ZN5test018stdio_sync_filebufIA3_iE6xsgetnEv to i8*)] }, align 8
@_ZTVN10__cxxabiv120__si_class_type_infoE = external global i8*
@_ZTSN5test018stdio_sync_filebufIA3_iEE = weak_odr constant [35 x i8] c"N5test018stdio_sync_filebufIA3_iEE\00"
@_ZTIN5test015basic_streambufE = external constant i8*
@_ZTIN5test018stdio_sync_filebufIA3_iEE = weak_odr constant { i8*, i8*, i8* } { i8* bitcast (i8 getelementptr inbounds (i8*, i8 @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @_ZTSN5test018stdio_sync_filebufIA3_iEE, i32 0, i32 0), i8* bitcast (i8 @_ZTIN5test015basic_streambufE to i8*) }
@_ZN7PR100011SIiE3arrE = linkonce_odr global [3 x i32] zeroinitializer, align 4
@_ZGVN7PR100011SIiE3arrE = linkonce_odr global i64 0, align 8
@_ZTSN5test018stdio_sync_filebufIA4_iEE = linkonce_odr constant [35 x i8] c"N5test018stdio_sync_filebufIA4_iEE\00"
@_ZTIN5test018stdio_sync_filebufIA4_iEE = linkonce_odr constant { i8*, i8*, i8* } { i8* bitcast (i8
getelementptr inbounds (i8*, i8 @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @_ZTSN5test018stdio_sync_filebufIA4_iEE, i32 0, i32 0), i8* bitcast (i8 @_ZTIN5test015basic_streambufE to i8*) }
@_ZTVN5test21CIiEE = available_externally unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* bitcast (i8** @_ZTIN5test21CIiEE to i8*), i8* bitcast (void (%"class.test2::C"*)* @_ZN5test21CIiED1Ev to i8*), i8* bitcast (void (%"class.test2::C"*)* @_ZN5test21CIiED0Ev to i8*)] }, align 8
@_ZTIN5test21CIiEE = external constant i8*
@llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @__cxx_global_var_init.2, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_template_instantiation.cpp, i8* null }]

Diff Detail

Repository
rL LLVM

Event Timeline

tigerleapgorge created this revision.Feb 27 2017, 2:16 PM
rjmccall edited edge metadata.Feb 27 2017, 9:38 PM

The C++98 behavior here is not really vital to test precisely; it's just minor differences in what gets instantiated and when. I think it's fine to just update the run line to -std=c++11 for things like this. But if you really want to test both configurations, this LGTM, although please leave a comment in the test explaining that it's just trying to account for differences in instantiation order between C++98 and C++11.

Updated patch.

Test only runs in C++11.
Added comments to explain CHECK-DAG and CHECK2-NOT.

The C++98 behavior here is not really vital to test precisely; it's just minor differences in what gets instantiated and when.

Hi John, my main concern with CHECK-NOT appearing between CHECK lines is that it makes the test brittle to the order of the IR.
For this reason I have separated out the CHECK-NOTs to go under a seperate prefix with a separate RUN line.
If you would like to old way of a single RUN line, I can do that too.

I think it's fine to just update the run line to -std=c++11 for things like this.

Done. I have deleted C++98 RUN lines and default (no -std) RUN lines.

But if you really want to test both configurations, this LGTM, although please leave a comment in the test explaining that it's just trying to account for differences in instantiation order between C++98 and C++11.

I have added 2 lines of comments.
One explains why CHECK-DAG is used instead of CHECK.
Another explains why CHECK2-NOT is used instead of CHECK-NOT

This revision was automatically updated to reflect the committed changes.