LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 802 - CBE lacks inline asm support
Summary: CBE lacks inline asm support
Status: RESOLVED WONTFIX
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: C (show other bugs)
Version: 1.0
Hardware: All All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: missing-feature
: 1212 1254 2102 2785 2839 4924 5877 9737 (view as bug list)
Depends on:
Blocks: 862
  Show dependency tree
 
Reported: 2006-06-07 17:21 PDT by Chris Lattner
Modified: 2012-03-26 05:56 PDT (History)
16 users (show)

See Also:
Fixed By Commit(s):


Attachments
Reduced testcase from the archie-client test (2.10 KB, text/x-csrc)
2008-06-20 04:17 PDT, Matthijs Kooijman
Details
CBE patch (1.51 KB, patch)
2011-02-02 13:18 PST, Jai Menon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2006-06-07 17:21:36 PDT
The C backend, at least when the C is compiled by GCC, should be able to change LLVM inline asm back 
into GCC-style inline asm in the cbe.c file.  Right now, we just output an unresolved symbol when inline 
asm is used.

-Chris
Comment 1 Chris Lattner 2007-02-19 16:27:04 PST
*** Bug 1212 has been marked as a duplicate of this bug. ***
Comment 2 Chris Lattner 2007-03-25 00:50:39 PDT
*** Bug 1254 has been marked as a duplicate of this bug. ***
Comment 3 Chris Lattner 2008-02-26 17:15:17 PST
*** Bug 2102 has been marked as a duplicate of this bug. ***
Comment 4 Matthijs Kooijman 2008-06-20 04:16:44 PDT
Since a few days, the MultiSource/Benchmarks/Prolangs-C/archie-client from the test suite is failing, probably due inline ASM being used. I just finished creating a reduced testcase for that, which might be redundant now I read this bug. I'll still attach it, feel free to thrash it if it is not helpful. If this a different issue, I'll open a new report instead.

The output of the attached program is as follows:
kooijman@eris:~$ llvm-gcc -c test.c -o - -emit-llvm | llc -march=c -f -o test.cbe.c; gcc test.cbe.c 
test.cbe.c:132: warning: conflicting types for built-in function ‘malloc’
test.cbe.c: In function ‘main’:
test.cbe.c:187: error: expected ‘:’ or ‘)’ before string constant
test.cbe.c:163: warning: return type of ‘main’ is not ‘int’
Comment 5 Matthijs Kooijman 2008-06-20 04:17:18 PDT
Created attachment 1759 [details]
Reduced testcase from the archie-client test
Comment 6 Anton Korobeynikov 2008-09-10 13:55:58 PDT
*** Bug 2785 has been marked as a duplicate of this bug. ***
Comment 7 Arif Kasim 2008-09-11 10:55:02 PDT
Is there any workaround for this issue? Thanks.

-Arif
Comment 8 Anton Korobeynikov 2008-09-11 11:15:09 PDT
(In reply to comment #7)
> Is there any workaround for this issue? Thanks.
Yes, surely. Don't use inline asm :)
Comment 9 Anton Korobeynikov 2008-09-29 14:43:37 PDT
*** Bug 2839 has been marked as a duplicate of this bug. ***
Comment 10 Tom Janssen 2009-05-20 09:40:43 PDT
I use llvm to instrument (C) programs and have bumped into this issue as well.
In fact, I had to edit the CBE generated .c file to fix the inline asm and I have traced the failures I encountered back to three separate bugs in lib/Target/CBackend/CBackend.cpp:

1) in the visitInlineAsm function there are three loops for traversing and printing constraints, which should be separated by commas. This fails because the 'IsFirst' boolean, which should make sure a comma is printed before the constraint if it is not the first in the line, is only set to false whenever the boolean is false (never happens). 
Simple fix is to set it false outside the if-statement...

2) in the same function the clobber constraints (third loop) are not preceded by a ':'. 

3) the gccifyAsm function somehow prints some register names with '%%regname' in stead of '$regname'


For the project I am working on, I limited to the use LLVM version 2.4 only, so right now I am not able to active develop or bugfix the LLVM tools, and I have checked the latest version of CBackend.cpp, but it did not contain fixes for the bugs. 
I hope that someone more involved will address it, since it takes up unnecessary time fixing the faults in the resulting files, and I'm sure more people have encountered it.

Greetings,
  Tom
Comment 11 Anton Korobeynikov 2009-09-08 03:33:27 PDT
*** Bug 4924 has been marked as a duplicate of this bug. ***
Comment 12 Anton Korobeynikov 2009-12-25 11:33:01 PST
*** Bug 5877 has been marked as a duplicate of this bug. ***
Comment 13 Jai Menon 2011-02-02 13:18:26 PST
Created attachment 6093 [details]
CBE patch

Attached patch fixes some of these issues. I sent this to llvm-commits but I guess I should've searched the bug tracker to see if anyone else came across this earlier.
Comment 14 Jai Menon 2011-02-15 11:19:26 PST
(In reply to comment #13)
> Created an attachment (id=6093) [details]
> CBE patch
> 
> Attached patch fixes some of these issues. I sent this to llvm-commits but I
> guess I should've searched the bug tracker to see if anyone else came across
> this earlier.

Ping?
Would it be possible to commit this?
Comment 15 Duncan Sands 2011-02-15 11:21:50 PST
Could you please add some testcases.
Comment 16 Chris Lattner 2011-04-16 10:58:34 PDT
*** Bug 9737 has been marked as a duplicate of this bug. ***
Comment 17 Dmitry N. Mikushin 2011-04-16 11:28:44 PDT
(In reply to comment #15)
> Could you please add some testcases.

The patch from Jai Menon fixes the case from bug 9737 http://llvm.org/bugs/show_bug.cgi?id=9737

Instead of invalid inline asm

  __asm__ volatile ("rorw %%8, %w0"
        :"=r"(llvm_cbe_asmtmp)
        :"0"(((unsigned short )15))"cc");

patched CBE generates

  __asm__ volatile ("rorw $8, %w0"
        :"=r"(llvm_cbe_asmtmp)
        :"0"(((unsigned short )15))
        :"cc");

and result is correct. Checked with llvm trunk r129558.
Comment 18 Dmitry N. Mikushin 2011-04-16 12:20:56 PDT
However, there are still fails with

Assertion `I->Codes.size() == 1 && "Too many asm constraint codes to handle"' failed.

So patch fixes only the issue specific to inline asm arguments, and to fix the assertion above somebody should implement

//TODO: work out platform independent constraints and factor those out
//      of the per target tables
//      handle multiple constraint codes
Comment 19 Benjamin Kramer 2012-03-26 05:56:36 PDT
The C backend was removed from svn trunk and is no longer maintained. Closing the bug.