JuliaHubOSS / llvm-cbe

resurrected LLVM "C Backend", with improvements
Other
811 stars 138 forks source link

error: unterminated attribute group #151

Closed Heath123 closed 2 years ago

Heath123 commented 2 years ago
$ ~/llvm-cbe/build/tools/llvm-cbe/llvm-cbe return123.ll
/home/heath/llvm-cbe/build/tools/llvm-cbe/llvm-cbe: return123.ll:11:19: error: unterminated attribute group
attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone sspstrong uwtable willreturn "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
                  ^

return123.c contents:

int main() {
  return 123;
}

Compiled with:

$ clang -S -emit-llvm -O2 -g return123.c

(the error does not happen when omitting -O2)

return123.ll contents:

; ModuleID = 'return123.c'
source_filename = "return123.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone sspstrong uwtable willreturn
define dso_local i32 @main() local_unnamed_addr #0 !dbg !10 {
  ret i32 123, !dbg !14
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone sspstrong uwtable willreturn "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5, !6, !7, !8}
!llvm.ident = !{!9}

!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "return123.c", directory: "/home/heath/ghidra-structure")
!2 = !{}
!3 = !{i32 7, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{i32 7, !"PIC Level", i32 2}
!7 = !{i32 7, !"PIE Level", i32 2}
!8 = !{i32 7, !"uwtable", i32 1}
!9 = !{!"clang version 13.0.0"}
!10 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!11 = !DISubroutineType(types: !12)
!12 = !{!13}
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!14 = !DILocation(line: 2, column: 3, scope: !10)
Heath123 commented 2 years ago

Removing mustprogress from the attributes seems to fix it. I have no idea what that does or if it would break the code

Heath123 commented 2 years ago

Wait, I think I see the problem:

$ clang --version
clang version 13.0.0

So I'm meant to use Clang 10 because this only supports LLVM 10

hikari-no-yume commented 2 years ago

Yeah indeed, you can't use LLVM IR from a newer LLVM with an older LLVM.