How is target_triple/default_triple handled in tests?

As part of trying to fix PR30610 (ThinLTO with module inline asm), I wanted to add an assert that we have a Target and an MCAsmParser when we have non-null module inline asm in IRObjectFile::CollectAsmUndefinedRefs. Otherwise it silently fails to parse the module inline asm, which I initially found when trying to add an ‘opt’ based test for my fix (because ‘opt’ wasn’t initializing asm parsers, something I am fixing).

However, I had a test case failure in test/LTO/X86/current-section.ll, which has module asm, but no target triple. However, it does have a “REQUIRES: default_triple”. Mehdi, looks like you added this as part of D12660. I found that this is set to true in test/lit.cfg, and when I print out the config.target_triple there it is x86_64-unknown-linux-gnu. But when I print out the target triple on the Module in CollectAsmUndefinedRefs it is null. How is the config.target_triple supposed to propagate into the test - I assume that is the intention of requiring a default_triple?

Thanks,
Teresa

Tools are usually adding the default triple when there is none. This is not a “feature” I like though.
The “default” triple is defined at configuration time, either you supply the cmake option otherwise it default to your host.
It is likely that llvm-lto is not overriding the triple (I rather have it asserting that there is a triple by the way).

Adding a triple to any test that relies on inline module asm seem the right thing to do to me, otherwise the test would break if someone were to configure with a default triple for a different target.

>
> As part of trying to fix PR30610 (ThinLTO with module inline asm), I
wanted to add an assert that we have a Target and an MCAsmParser when we
have non-null module inline asm in IRObjectFile::CollectAsmUndefinedRefs.
Otherwise it silently fails to parse the module inline asm, which I
initially found when trying to add an 'opt' based test for my fix (because
'opt' wasn't initializing asm parsers, something I am fixing).
>
> However, I had a test case failure in test/LTO/X86/current-section.ll,
which has module asm, but no target triple. However, it does have a
"REQUIRES: default_triple". Mehdi, looks like you added this as part of
D12660.
> I found that this is set to true in test/lit.cfg, and when I print out
the config.target_triple there it is x86_64-unknown-linux-gnu. But when I
print out the target triple on the Module in CollectAsmUndefinedRefs it is
null. How is the config.target_triple supposed to propagate into the test -
I assume that is the intention of requiring a default_triple?

Tools are usually adding the default triple when there is none. This is
not a “feature” I like though.
The “default” triple is defined at configuration time, either you supply
the cmake option otherwise it default to your host.
It is likely that llvm-lto is not overriding the triple (I rather have it
asserting that there is a triple by the way).

I see that 'opt' and 'llc' have an -mtriple option, is that what you meant?

Adding a triple to any test that relies on inline module asm seem the
right thing to do to me, otherwise the test would break if someone were to
configure with a default triple for a different target.

I'll go ahead and add a target triple to that test then.

Thanks!
Teresa

No: I was referring to https://github.com/llvm-project/llvm-project/blob/master/llvm/tools/llc/llc.cpp#L368