Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8245777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:17:44+00:00 2026-06-07T22:17:44+00:00

Consider the following x86 code example: #include <stdlib.h> static int i; static inline __attribute__((always_inline))

  • 0

Consider the following x86 code example:

#include <stdlib.h>

static int i;

static inline __attribute__((always_inline)) test(int x)
{
    asm volatile("mov %1, %0" : "=r"(i): "i"(x));
}

int main(void)
{
    test(5);

    return i;
}

If I build it with:

gcc -O test.c

It builds fine.

If I build it with (no optimization):

gcc test.c

It fails during assembly phase, because the value '5' is not propagated as an immediate value to the inline function test, so we fail the constraint.

I wish to be able to compile this code without turning on other non related optimization, in order to make debugging easier.

In theory, -O is simply a short cut to enable a bunch of GCC optimization options at once that are documented in the fine GCC manual. Unfortunately, I was not able to find the specific GCC flag that turns this behavior on.

Any ideas?

Clarification: To relieve any doubt, the code snippet is just an example. It does not make much sense by itself except to show what I am trying to do. The actual use case involves an instruction on a custom processor that can only take an immediate as an argument which I am trying to wrap in a C construct. A macro will indeed do the trick, but suffers from all the usual draw backs of a macro, hence I am trying to avoid it.

Update: For those who wondered, a macro wont work either. It seems the inline function doesn’t play a part here at all. E.g., this doesn’t work either:

void foo (void)
{
  int i = 6;

  asm volatile ("" : : "i" (i));
}

I also fixed the question title to reflect this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:17:46+00:00Added an answer on June 7, 2026 at 10:17 pm

    Looks like -ftree-ter (Replace temporary expressions in the SSA->normal pass – whatever that is) does the trick:

    gcc -ftree-ter test.c   # no errors
    

    Here’s how I determined that:

    1. gcc -Q --help=optimizers tells you what optimizations are enabled/disabled by default (some are enabled)
    2. gcc -O -Q --help=optimizers tells you what optimizations are enabled/disabled for -O
    3. redirect the output of those commands to files and diff them.
    4. try the optimizations that are enabled only when -O is specified until one works.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following example: #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <hiredis/hiredis.h> int main(int argc,
Consider the following code: #include <stdlib.h> #ifndef TRY #define TRY struct #endif TRY testme
Consider following example. #include <iostream> #include <algorithm> #include <vector> #include <boost/bind.hpp> void func(int e,
Consider following example. #include <iostream> #include <boost/optional.hpp> template < typename A > int boo(
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
Consider following code: main.cpp: #include <iostream> typedef void ( * fncptr)(void); extern void externalfunc(void);
Consider following example: #include <iostream> #include <functional> #include <algorithm> #include <vector> #include <boost/bind.hpp> const
Consider following codes: #include <stdio.h> #include <malloc.h> void allocateMatrix(int **m, int l, int c)
Consider following class class test { public: test(int x){ cout<< test \n; } };

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.