DarthRubik
DarthRubik

Reputation: 3985

Using Clang and LLVM

I am compiling this:

int main(){
}

With clang, using this command line:

clang++.exe -S -o %OUTFILE%.clang -emit-llvm %INFILE% -I. -I%INCLUDE_PATH% -std=c++14 -ftemplate-depth=1000

Which gives me llvm byte-code.

Then I use llc like so, to convert the byte-code into c code:

llc "%IN_FILE%.clang" -march=c -o foo.c

And get this error:

error: unterminated attribute group
attributes #0 = { norecurse nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }

What I am doing wrong?

This is what clang++ is giving me:

; ModuleID = 'C:\Users\Owner\Documents\C++\SVN\prototypeInd\util\StaticBigInt.cpp'
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc18.0.0"

; Function Attrs: norecurse nounwind readnone uwtable
define i32 @main() #0 {
entry:
  ret i32 0
}

attributes #0 = { norecurse nounwind readnone uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"PIC Level", i32 2}
!1 = !{!"clang version 3.8.0 (branches/release_38)"}

Note: I am using clang version 3.8 and llc version 3.4

Upvotes: 1

Views: 1153

Answers (2)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

C backend in LLVM was removed several years ago. It seems that you're trying to feed LLVM IR from the recent LLVM version to llc from old LLVM. This is certainly not supported - the IR is not compatible between the versions.

Upvotes: 1

AlexDenisov
AlexDenisov

Reputation: 4117

When you run a command such as:

clang -S -emit-llvm ...

Then the compiler emits not an IR in a bitcode form, but human readable representation.

It makes sense if all tools you use have the same versions, or if you just want to inspect the output manually.

However, the human readable IR may be incompatible with old tools.

In this case I can recommend to use bitcode directly (note that there is no -S parameter anymore):

clang -emit-llvm

Upvotes: 1

Related Questions