Cannot select: t11: f64 = fpow t9, ConstantFP:f64<-1.666667e-01> - llvm

We are getting below error when we are trying to compile dpc++ code using clang++ compiler.
Error message:
fatal error: error in backend: Cannot select: t11: f64 = fpow t9, ConstantFP:f64<-1.666667e-01>
t9: f64 = fma t8, t8, t6
t8: f64,ch = CopyFromReg t0, Register:f64 %117
t7: f64 = Register %117
t8: f64,ch = CopyFromReg t0, Register:f64 %117
t7: f64 = Register %117
t6: f64 = fmul t5, t5
t5: f64,ch = CopyFromReg t0, Register:f64 %118
t4: f64 = Register %118
t5: f64,ch = CopyFromReg t0, Register:f64 %118
t4: f64 = Register %118
t10: f64 = ConstantFP<-1.666667e-01>
In function: _ZN4quda8IdEEvRNS_6_7_EELi3EEES3_
llvm-foreach:
clang-15: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler/build/bin
clang-15: note: diagnostic msg: Error generating pre-processed source(s) - no pre processable inputs.
make: *** [Makefile_all.dpct:1186: libquda.so] Error 1
Help and guidance will be appreciated!

Related

std::function SIGILL_ILLOPC

I got some strange crash.
I cannot reproduce it, but it keeps reporting from customer
the platform is Arm64
gcc version is 6.4
the code is quite simple:
template <typename T, typename F, typename ...Args>
Timer::registerTimerTask(T interval, F func, bool once, Args... args) {
auto t = std::chrono::duration_cast<std::chrono::nanoseconds>(interval);
auto f = [=]() mutable {func(args...);};
auto task = std::make_shared<Task>(f, t, once);
addTask(task);
}
Task::Task(std::function<void()>func, std::chrono::nanoseconds timeout, bool once=false):
mFunc(func), mTimeout(timeout), mOnce(once) {}
the code is quite simple, but on some customer's machine, it keeps crashing at constructor Task::Task, and it's SIGILL_ILLOPC
as far as I can understand, ILLOPC only happened when I have problem with cross-compiling, but this time it's not (since the same elf file works fine on others)
the stack is like:
Operating system: Linux
0.0.0 Linux 4.9.191 #1 SMP PREEMPT Mon Oct 31 06:32:31 UTC 2022 aarch64
CPU: arm64
4 CPUs
GPU: UNKNOWN
Crash reason: SIGILL / ILL_ILLOPC
Crash address: 0x7f8e50dc14
Process uptime: not available
Thread 20 (crashed)
0 myso.so!std::_Function_base::_Base_manager<Timer::registerTimerTask(T&&, F, bool, Args&& ...) [with T = std::chrono::duration<long int, std::ratio<1l, 1000l> >&; F = Impl::socket(std::__cxx11::string, std::__cxx11::string, std::shared_ptr<Listener<std::__cxx11::basic_string<char> > >)::<lambda()>; Args = {}]::<lambda()> >::_M_manager [functional : 1591 + 0x4]
x0 = 0x0000007f6c002840 x1 = 0x0000007f767f5db8
x2 = 0x0000000000000002 x3 = 0x0000007f8e50dc10
x4 = 0x0000007f6c0054c0 x5 = 0x0000007f6c002b10
x6 = 0x0000000000000000 x7 = 0x0000007f8cf633c0
x8 = 0x0000007f767f5f48 x9 = 0x003b9aca00000000
x10 = 0x0101010101010101 x11 = 0x0000000000000023
x12 = 0x00000000767f6188 x13 = 0x00000003e8000000
x14 = 0x0001ab437f192700 x15 = 0x00006e641756376a
x16 = 0x0000007f8e56a618 x17 = 0x0000007f8e4eb91c
x18 = 0x0000000000000000 x19 = 0x0000007f6c002830
x20 = 0x0000007f6c002830 x21 = 0x0000007f767f5db8
x22 = 0x0000000000000001 x23 = 0x0000007f767f6188
x24 = 0x0000007f767f6137 x25 = 0x0000000000000003
x26 = 0x0000000000800000 x27 = 0x0000000000000000
x28 = 0x0000007f8c2a36f0 fp = 0x0000007f767f5cf0
lr = 0x0000007f8e50eb0c sp = 0x0000007f767f5cf0
pc = 0x0000007f8e50dc14
Found by: given as instruction pointer in context
1 myso.so!Task::Task(std::function<void ()>, std::chrono::duration<long, std::ratio<1l, 1000000000l> >, bool) [task.h : 124 + 0x24]
x19 = 0x0000007f6c002830 x20 = 0x0000007f6c002830
x21 = 0x0000007f767f5db8 x22 = 0x0000000000000001
x23 = 0x0000007f767f6188 x24 = 0x0000007f767f6137
x25 = 0x0000000000000003 x26 = 0x0000000000800000
x27 = 0x0000000000000000 x28 = 0x0000007f8c2a36f0
fp = 0x0000007f767f5d20 sp = 0x0000007f767f5d40
pc = 0x0000007f8e50e140
Found by: call frame info
I really don't know why SIGILL would happen, and I can't find anyone with similar occasion

How to interpret yaml error messa with Rmarkdown?

Does anybody have a clue on how to find the control character in this error:
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Reader error: control characters are not allowed: #9D at 2116
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load -> <Anonymous>
What's #9D and at 2116?

LLVM IR: expose variables to GDB?

I am writing a custom programming language. I am generating LLVM IR as an intermediate (via LLVMlite), and I want to expose variables to GDB. This is an example of the generated IR:
; ModuleID = "tests/debuginfo.xan"
source_filename = "debuginfo.xan"
target triple = "x86_64-unknown-linux-gnu"
target datalayout = ""
define void #"main"(i32 %".1", i8** %".2") !dbg !10
{
entry:
%"$argc" = alloca i32
store i32 %".1", i32* %"$argc"
%"$argv" = alloca i8**
store i8** %".2", i8*** %"$argv"
%"$a" = alloca i32
call void #"llvm.dbg.declare"(metadata i32* %"$a", metadata !12, metadata !13), !dbg !14
call void #"llvm.dbg.value"(metadata i32 0, metadata !12, metadata !13), !dbg !15
store i32 0, i32* %"$a"
ret void
}
declare i32 #"printf"(i8* %".1", ...)
declare void #"llvm.dbg.declare"(metadata %".1", metadata %".2", metadata %".3") nounwind readnone
declare void #"llvm.dbg.value"(metadata %".1", metadata %".2", metadata %".3") nounwind readnone
#"NULL" = internal constant i8* inttoptr (i32 0 to i8*)
!llvm.dbg.cu = !{ !2 }
!llvm.module.flags = !{ !3, !4, !5 }
!llvm.ident = !{ !6 }
!gen-by = !{ !16 }
!0 = !DIFile(directory: "/home/proc-daemon/Dropbox/Xanathar/xanathar/tests", filename: "debuginfo.xan")
!1 = !{ }
!2 = distinct !DICompileUnit(emissionKind: FullDebug, enums: !1, file: !0, isOptimized: false, language: DW_LANG_Python, producer: "Xanathar v. a0.0.1", runtimeVersion: 0)
!3 = !{ i32 2, !"Dwarf Version", i32 4 }
!4 = !{ i32 2, !"Debug Info Version", i32 3 }
!5 = !{ i32 1, !"wchar_size", i32 4 }
!6 = !{ !"Xanathar a0.0.1" }
!7 = !DIDerivedType(baseType: null, size: 64, tag: DW_TAG_pointer_type)
!8 = !{ !7 }
!9 = !DISubroutineType(types: !8)
!10 = distinct !DISubprogram(file: !0, isDefinition: true, isLocal: false, isOptimized: false, name: "main", scope: !0, scopeLine: 1, type: !9, unit: !2, variables: !1)
!11 = !DIBasicType(encoding: DW_ATE_signed, name: "int", size: 4)
!12 = !DILocalVariable(file: !0, line: 1, name: "a", scope: !10, type: !11)
!13 = !DIExpression()
!14 = !DILocation(column: 1, line: 1, scope: !10)
!15 = !DILocation(column: 1, line: 2, scope: !10)
!16 = !{ !"Xanathar" }
I removed the previous edits. The generation code can be found here. As you can see, I have a variable $a that I am trying to declare with llvm.dbg.declare. However, although objdump --sym lists debug info (pastebin), gdb gives No locals. upon running info locals. What is the correct way to export variables? How could I generate that with LLVMlite?
Here is the compilation code:
def compile(self, name, so):
sys.stderr.write('---COMPILE---\n')
if not so:
command = 'clang {0} -g -fstandalone-debug -O0 ' + name + '.ll '
else:
command = 'clang {0} -g -fstandalone-debug -O0 -shared -undefined dynamic_lookup ' + name + '.ll '
command = command.format(self.flags)
for i in self.LOADED_MODULES:
if i["type"] == 'LINKED_SO':
command += os.path.abspath(i["FILE"]) + ' '
command = command + '-o ' + name + ('.so' if so else '.o')
# print(command)
os.system(command)
Here is the LLVM confirmation code:
def _compile_ir(self, builder):
"""
Compile the LLVM IR string with the given engine.
The compiled module object is returned.
"""
# Create a LLVM module object from the IR
self.builder = builder
self.builder.ret_void()
self.module.add_named_metadata("gen-by", ["Xanathar"])
llvm_ir = str(self.module)
try:
mod = self.binding.parse_assembly(llvm_ir)
except RuntimeError as e:
sys.stderr.write("[ERR] LLVM parsing error!\n")
sys.stderr.write(str(e))
if "expected instruction opcode" in str(e):
sys.stderr.write("\nDid you forget to return from a function?")
exit(1)
mod = 0 # Otherwise PyCharm complains about mod's usage below
mod.verify()
# Now add the module and make sure it is ready for execution
self.engine.add_module(mod)
self.engine.finalize_object()
self.engine.run_static_constructors()
return mod
(After this, the module is written to a file)
EDIT 5 (or 6, idk): As Chirag Patel suggested, I added a new debug statement to the ret instruction. Then, this happened.
(gdb) r
Starting program: /home/proc-daemon/Dropbox/Xanathar/xanathar/tests/debuginfo.xan.o
Breakpoint 1, main () at debuginfo.xan:1
1 declare $a as int32;
(gdb) info locals
Segmentation fault (core dumped)

boost::context for arm64?

I am trying to compile boost::context for iOS(armv7, armv7s, arm64):
errors
jump_arm_aapcs_macho_gas.S:52:18: error: ',' expected
stmia a1, {v1-v8,sp-lr} # save V1-V8,SP-LR
^
jump_arm_aapcs_macho_gas.S:53:14: error: register expected
str lr, [a1,#40] # save LR as PC
^
jump_arm_aapcs_macho_gas.S:69:18: error: invalid variant 'use'
mov a1, a3 # use third arg as return value after jump
^
jump_arm_aapcs_macho_gas.S:70:39: error: unexpected token at start of statement
# and as first arg in context function
^
jump_arm_aapcs_macho_gas.S:71:18: error: ',' expected
ldmia a2, {v1-v8,sp-pc} # restore v1-V8,SP-PC
^
jump_arm_aapcs_macho_gas.S
.text
.globl _jump_fcontext
.align 2
_jump_fcontext:
stmia a1, {v1-v8,sp-lr} # save V1-V8,SP-LR
str lr, [a1,#40] # save LR as PC
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
cmp a4, #0 # test if fpu env should be preserved
beq 1f
mov a4, a1
add a4, #52
vstmia a4, {d8-d15} # save S16-S31
mov a4, a2
add a4, #52
vldmia a4, {d8-d15} # restore S16-S31
1:
#endif
mov a1, a3 # use third arg as return value after jump
# and as first arg in context function
ldmia a2, {v1-v8,sp-pc} # restore v1-V8,SP-PC
If I remove arm64, and set the architecture to armv7 only, it compiles, so the code should be fine.
Is there any way to get this to compile for arm64?
ARM64 (AArch64) is pretty different from ARM32 (A32), both in instructions and the register set. The calling conventions (ABI) differs too. You'd need to rewrite the assembler snippets. I would recommend contacting the developer(s) since you don't seem to be familiar with the low-level details to do it yourself.

How can clang avoid to analyze the builtin type/function in C/C++?

/usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/stdarg.h:40:9: error: unknown type name '__builtin_va_list'; did you mean '__builtin_va_list'?
typedef __builtin_va_list __gnuc_va_list;
^
note: '__builtin_va_list' declared here
When I try to use the RecursiveASTVisitor to visit the AST, I got the above problem. And at the end, the program abort with the following message.
type: Typedef of __gnuc_va_list size CItutorial5: /home/lotay/libs/clang/llvm/include/llvm/Support/Casting.h:239: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = clang::ConstantArrayType, Y = const clang::Type]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Aborted (core dumped)
Really thanks for help
and I have the langoptions with following confs.
langOpts.GNUMode = 1 ;
langOpts.CXXExceptions = 1 ;
langOpts.RTTI = 1 ;
langOpts.Bool = 1 ;
langOpts.CPlusPlus = 1 ;
langOpts.WChar = 1 ;