简体   繁体   中英

GCC- Invalid use of Register

I am compiling a project under VS2012 and GCC (CodeBlocks) for Windows. On VS2012 everything works perfect. Under GCC I am obtaining the following compiling error:

C:\Users\Piotrek\AppData\Local\Temp\ccfdl0Ye.s|164|Error: invalid use of register|
C:\Users\Piotrek\AppData\Local\Temp\ccfdl0Ye.s|166|Error: invalid use of register|
C:\Users\Piotrek\AppData\Local\Temp\ccfdl0Ye.s|221|Error: invalid use of register|
||=== Build finished: 3 errors, 14 warnings (0 minutes, 0 seconds) ===|

I am using the compiler option -fpermissive - It should have nothing to do with the error.

I just can't understand why is it pointing to a temporary file under the Local Temp folder, and saying that I am using a wrong register??

Does anybody have any idea on what's happening?

It looks like you've encountered a bug in the compiler. The error messages (judging from the "source" file name) are from the assembler. The only time the assembler should generate an error message is when there is something illegal in the assembler, and the C++ compiler should never generate illegal assembler; if it can't generate legal assembler, it should output an error message and fail.

The real problem, when you get this sort of message, is to figure out what in your code is triggering it. g++ has an option which tells it to not delete any of the intermediate files. Use this, then try and see what is going on in the assember files at these lines. (When you ask g++ to output assembler, it puts nice comments in to help finding the corresponding source. I don't know if it also does this when generating assembler as an intermediate file.) And then try cutting code (if worse comes to worse, using binary search) until you can get the error for a program of one or two lines. Try to guess what's special about them, and change them to do the same thing, in a different way.

And don't fail to report the error to g++.

Thanks to James Kanze's recommendation, I decided to tell to the compiler not to delete temporary files. This is done by the flag:

-save-temps

As James said, the assembler generates some nice comments which inform exactly which line on our C++ code is throwing the error. In my case, it looks like it is not accepting such instruction:

asm
(
    ".intel_syntax noprefix\n"
    "lock dec [DWORD PTR eax]\n"
    ".att_syntax \n"
    :
    : "a" (data)
    :
);

I don't know why he is not accepting Intel Syntax anymore, since it was working with previous GCC version, and now that I updated it it doesn't anymore.

Anyway, the solution for such problems is the one mentioned by James: Just dont delete intermediate files so that you can spy directly into Assembly code what's wrong.

About the problem of the INTEL syntax, any idea why it doesn't work anymore?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM