https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83244
Bug ID: 83244 Summary: inline assembly does not verify input operands allocation Product: gcc Version: 6.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: unjello at gmail dot com Target Milestone: --- Created attachment 42767 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42767&action=edit zip file with all the files to reproduce on x86 `int` instruction needs to receive `imm8`. g++ allows to pass an input operand in inline assembly as "register" too. Example: template<unsigned char int_no> void int_test_pass() { asm("int %0" : : "N"(int_no) :); } called with: int_test_pass<10>(); results in assembly (cutting out garbage): _Z13int_test_passILh10EEvv: int $10 but: template<unsigned char int_no> void int_test_fail() { asm("int %0" : : "r"(int_no) :); } quietly results in assembly like this. no errors: _Z13int_test_failILh10EEvv: movl $10, %eax int %al which is illigal. I've tested this on: g++-7 (Ubuntu 7.2.0-1ubuntu1~16.04) 7.2.0 g++-6 (Ubuntu/Linaro 6.3.0-18ubuntu2~16.04) 6.3.0 20170519 g++-5 (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904 g++-4.9 (Ubuntu 4.9.4-2ubuntu1~16.04) 4.9.4 g++-4.8 (Ubuntu 4.8.5-4ubuntu2) 4.8.5 g++-4.7 (Ubuntu/Linaro 4.7.4-3ubuntu12) 4.7.4 g++-4.6 (Ubuntu/Linaro 4.6.4-6ubuntu6) 4.6.4 on all above, this program compiles with no errors on -Wall -Werror. Clang on the other hands breaks compilation with an error: gcc_imm8_bug.cpp:9:7: error: invalid operand for instruction asm("int %0" ^ <inline asm>:1:6: note: instantiated into assembly here int %al ^~~ 1 error generated.