Assertion `SubtargetFeatures::hasFlag(Feature) && "Feature flags should start with '+' or '-'"' failed

environment: LLVM 10.0.0, Ubuntu 20.04
Input Command:
./llc -march=cpu0 -relocation-model=pic -filetype=asm ch2.bc -o ch2.cpu0.s

ErrorInfo:
/llvm-project-llvmorg-10.0.0/llvm/lib/MC/MCSubtargetInfo.cpp:63: void ApplyFeatureFlag(llvm::FeatureBitset &, llvm::StringRef, ArrayRef<llvm::SubtargetFeatureKV>): Assertion SubtargetFeatures::hasFlag(Feature) && “Feature flags should start with ‘+’ or ‘-’”’ failed.`

I now trying to build a new backend target for Cpu0, but got some troubles with target feature.
My deafault feature is “+cpu0II”.
I print the feature string before the ApplyFeatureFlag()
(in llvm-project-llvmorg-10.0.0/llvm/lib/MC/MCSubtargetInfo.cpp:188)
to confirm, it turns out to be “؆�F��”.
Why does it become random charactor?

This could be any number of things.

I would trying building a debug build (CMAKE_BUILD_TYPE=Debug) then running under a debugger.

Breakpoint at the place you did the print, and ask the debugger to print the same thing. If it agrees that it’s corrupted, go back up the callstack and see if there is a frame where it is not corrupted.

In lldb this is roughly:

lldb <path to llc> -- <arguments for llc>
break set <file>:<line number>
continue
p <the variable holding the feature>
up
p <the variable holding the feature>
...repeat as needed

You could avoid the debugger and stick print statements in various places but you have to figure out the callstack yourself then.

If the source of the feature name is not obvious, you might have to flip the approach and find where it is first created, and see where it goes from there.

1 Like