rui314 / 8cc Goto Github PK
View Code? Open in Web Editor NEWA Small C Compiler
License: MIT License
A Small C Compiler
License: MIT License
The I
character is UTF8, supported by clang and gcc with -std=c11.
$ echo "typedef long Itid;" > utf8.c ; 8cc -c utf8.c[ERROR]
parse.c:2651: utf8.c:1:14: stray character in program: '�'
In push_struct function in gen.c, there are three for loops, but it seems that only first for loop is executed, the last two for loops is not executed
int i = 0;
for (; i < size; i += 8) {
emit("movq %d(#rcx), #r11", i);
emit("mov #r11, %d(#rsp)", i);
}
for (; i < size; i += 4) {
emit("movl %d(#rcx), #r11", i);
emit("movl #r11d, %d(#rsp)", i);
}
for (; i < size; i++) {
emit("movb %d(#rcx), #r11", i);
emit("movb #r11b, %d(#rsp)", i);
}
in the usage/help message
What would be really cool is if you wrote a vm module for it and have it generate vm code. That would make it easier to use as a portable C script vm. :-)
Incorrect pointer types in calloc, benign issue, but clang static analyser detected it.
diff --git a/map.c b/map.c
index b44e898..89346ac 100644
--- a/map.c
+++ b/map.c
@@ -24,8 +24,8 @@ static uint32_t hash(char *p) {
static Map *do_make_map(Map *parent, int size) {
Map *r = malloc(sizeof(Map));
r->parent = parent;
- r->key = calloc(size, sizeof(char **));
- r->val = calloc(size, sizeof(void **));
+ r->key = calloc(size, sizeof(char *));
+ r->val = calloc(size, sizeof(void *));
r->size = size;
r->nelem = 0;
r->nused = 0;
@@ -34,16 +34,16 @@ static Map *do_make_map(Map *parent, int size) {
static void maybe_rehash(Map *m) {
if (!m->key) {
- m->key = calloc(INIT_SIZE, sizeof(char **));
- m->val = calloc(INIT_SIZE, sizeof(void **));
+ m->key = calloc(INIT_SIZE, sizeof(char *));
+ m->val = calloc(INIT_SIZE, sizeof(void *));
m->size = INIT_SIZE;
return;
}
if (m->nused < m->size * 0.7)
return;
int newsize = (m->nelem < m->size * 0.35) ? m->size : m->size * 2;
- char **k = calloc(newsize, sizeof(char **));
- void **v = calloc(newsize, sizeof(void **));
+ char **k = calloc(newsize, sizeof(char *));
+ void **v = calloc(newsize, sizeof(void *));
int mask = newsize - 1;
for (int i = 0; i < m->size; i++) {
if (m->key[i] == NULL || m->key[i] == TOMBSTONE)
./stage1
exists with error code 1.
./stage1 -h
still exists with error code 1
First of all thank you very much for sharing your project.
I am on Ubuntu 14.04 32 bit platform. I compiled the source code but make test
fails with lots of errors.
make test all
./8cc -DBUILD_DIR='"/home/kenn/Desktop/8cc"' -c test/main/testmain.c
/tmp/8cc3MYo82.s: Assembler messages:
/tmp/8cc3MYo82.s:4: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:5: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:6: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:10: Error: `movswq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:11: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:12: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:13: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:14: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:16: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:17: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:18: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:19: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:20: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:21: Error: `movswq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:22: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:23: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:24: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:25: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:26: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:27: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:28: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:29: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:31: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:32: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:40: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:41: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:42: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:48: Error: `movslq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:49: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:52: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:53: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:54: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:55: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:56: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:57: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:58: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:60: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:63: Error: `movslq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:64: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:67: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:68: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:69: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:70: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:71: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:72: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:73: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:75: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:76: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:77: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:80: Error: `movslq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:81: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:84: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:85: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:86: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:87: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:88: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:89: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:90: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:92: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:93: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:94: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:97: Error: `movslq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:98: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:101: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:102: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:103: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:104: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:105: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:106: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:107: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:109: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:110: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:118: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:119: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:120: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:125: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:126: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:129: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:130: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:131: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:132: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:133: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:134: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:135: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:136: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:137: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:140: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:141: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:144: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:145: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:146: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:147: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:148: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:149: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:150: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:151: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:152: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:153: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:154: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:157: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:158: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:161: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:162: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:163: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:164: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:165: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:166: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:167: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:168: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:169: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:170: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:171: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:174: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:175: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:178: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:179: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:180: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:181: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:182: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:183: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:184: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:185: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:186: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:187: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:188: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:191: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:192: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:195: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:196: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:197: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:198: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:199: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:200: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:201: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:202: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:203: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:204: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:205: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:208: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:209: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:212: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:213: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:214: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:215: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:216: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:217: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:218: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:219: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:220: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:221: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:222: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:225: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:226: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:229: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:230: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:231: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:232: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:233: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:234: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:235: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:236: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:237: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:238: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:239: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:242: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:243: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:246: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:247: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:248: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:249: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:250: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:251: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:252: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:253: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:254: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:255: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:272: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:273: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:274: Error: bad register name `%dil'
/tmp/8cc3MYo82.s:275: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:281: Error: `movsbq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:290: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:291: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:292: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:297: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:298: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:299: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:304: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:305: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:308: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:309: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:310: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:311: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:314: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:315: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:316: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:319: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:320: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:321: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:322: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:324: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:331: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:332: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:335: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:336: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:337: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:338: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:339: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:340: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:341: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:342: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:343: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:345: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:346: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:347: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:348: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:350: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:351: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:352: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:358: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:365: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:367: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:368: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:371: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:372: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:379: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:380: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:381: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:386: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:388: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:391: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:392: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:393: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:398: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:399: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:402: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:403: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:404: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:405: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:408: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:409: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:410: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:413: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:414: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:415: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:416: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:418: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:425: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:426: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:427: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:428: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:435: Error: `movslq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:436: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:437: Error: `movslq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:438: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:442: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:445: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:454: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:455: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:456: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:457: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:462: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:463: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:466: Error: `movslq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:467: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:468: Error: `movslq' is only supported in 64-bit mode
/tmp/8cc3MYo82.s:469: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:470: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:471: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:472: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:475: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:476: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:477: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:478: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:481: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:482: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:483: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:484: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:485: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:487: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:488: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:496: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:497: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:498: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:499: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:504: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:505: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:508: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:509: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:510: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:511: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:512: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:513: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:515: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:516: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:517: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:526: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:527: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:528: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:529: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:534: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:535: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:538: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:539: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:540: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:541: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:542: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:543: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:544: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:547: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:548: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:549: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:550: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:553: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:554: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:555: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:556: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:557: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:559: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:560: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:568: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:569: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:570: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:571: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:572: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:573: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:580: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:581: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:582: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:583: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:584: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:585: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:589: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:592: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:601: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:602: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:603: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:608: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:609: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:612: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:614: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:615: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:620: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:622: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:623: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:624: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:625: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:626: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:627: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:628: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:631: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:632: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:633: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:636: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:637: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:638: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:639: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:640: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:642: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:643: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:651: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:652: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:653: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:654: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:655: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:656: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:663: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:664: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:665: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:666: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:667: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:668: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:672: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:675: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:684: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:685: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:686: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:691: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:692: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:695: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:696: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:697: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:698: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:699: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:700: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:701: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:702: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:703: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:704: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:705: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:708: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:709: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:710: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:713: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:714: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:715: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:716: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:717: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:719: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:720: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:728: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:729: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:730: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:731: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:738: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:739: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:740: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:741: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:742: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:745: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:748: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:757: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:758: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:759: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:760: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:765: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:766: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:769: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:770: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:775: Error: bad register name `%rbp)'
/tmp/8cc3MYo82.s:776: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:777: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:778: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:779: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:782: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:783: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:784: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:785: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:788: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:789: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:790: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:791: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:792: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:794: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:795: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:803: Error: bad register name `%rbp'
/tmp/8cc3MYo82.s:804: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:805: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:806: Error: bad register name `%rsi'
/tmp/8cc3MYo82.s:807: Error: bad register name `%rdx'
/tmp/8cc3MYo82.s:808: Error: bad register name `%rcx'
/tmp/8cc3MYo82.s:809: Error: bad register name `%r8'
/tmp/8cc3MYo82.s:810: Error: bad register name `%r9'
/tmp/8cc3MYo82.s:813: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:817: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:821: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:825: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:829: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:833: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:837: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:841: Error: bad register name `%rsp)'
/tmp/8cc3MYo82.s:845: Error: bad register name `%xmm8'
/tmp/8cc3MYo82.s:849: Error: bad register name `%xmm9'
/tmp/8cc3MYo82.s:853: Error: bad register name `%xmm10'
/tmp/8cc3MYo82.s:857: Error: bad register name `%xmm11'
/tmp/8cc3MYo82.s:861: Error: bad register name `%xmm12'
/tmp/8cc3MYo82.s:865: Error: bad register name `%xmm13'
/tmp/8cc3MYo82.s:869: Error: bad register name `%xmm14'
/tmp/8cc3MYo82.s:873: Error: bad register name `%xmm15'
/tmp/8cc3MYo82.s:876: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:884: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:885: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:886: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:887: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:888: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:889: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:890: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:891: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:892: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:894: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:895: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:896: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:897: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:899: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:900: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:901: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:907: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:914: Error: bad register name `%rip)'
/tmp/8cc3MYo82.s:916: Error: bad register name `%rax'
/tmp/8cc3MYo82.s:917: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:920: Error: bad register name `%rsp'
/tmp/8cc3MYo82.s:921: Error: bad register name `%rdi'
/tmp/8cc3MYo82.s:924: Error: bad register name `%rax'
./8cc -DBUILD_DIR='"/home/kenn/Desktop/8cc"' -c test/align.c
/tmp/8cchhZlCW.s: Assembler messages:
/tmp/8cchhZlCW.s:4: Error: bad register name `%rbp'
/tmp/8cchhZlCW.s:5: Error: bad register name `%rsp'
/tmp/8cchhZlCW.s:11: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:12: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:13: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:14: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:15: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:16: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:17: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:18: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:20: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:21: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:24: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:25: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:26: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:27: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:28: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:29: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:30: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:31: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:33: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:34: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:37: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:38: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:39: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:40: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:41: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:42: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:43: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:44: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:46: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:47: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:50: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:51: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:52: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:53: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:54: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:55: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:56: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:57: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:59: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:60: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:63: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:64: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:65: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:66: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:67: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:68: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:69: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:70: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:72: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:73: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:76: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:77: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:78: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:79: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:80: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:81: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:82: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:83: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:85: Error: bad register name `%rsi'
/tmp/8cchhZlCW.s:86: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:93: Error: bad register name `%rbp'
/tmp/8cchhZlCW.s:94: Error: bad register name `%rsp'
/tmp/8cchhZlCW.s:99: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:100: Error: bad register name `%rsp'
/tmp/8cchhZlCW.s:105: Error: bad register name `%rip)'
/tmp/8cchhZlCW.s:106: Error: bad register name `%rax'
/tmp/8cchhZlCW.s:107: Error: bad register name `%rdi'
/tmp/8cchhZlCW.s:109: Error: bad register name `%rsp'
/tmp/8cchhZlCW.s:110: Error: bad register name `%rdi'
cc -o test/align.bin test/align.o test/main/testmain.o
cc: error: test/align.o: No such file or directory
cc: error: test/main/testmain.o: No such file or directory
cc: fatal error: no input files
compilation terminated.
make: *** [test/align.bin] Error 4
I also tried to compile simple helloworld.c
without success.
What might be problem?
Regards.
Kenn
Hello,
I was using American Fuzzy Lop (afl-fuzz) to fuzz input to the 8cc program on Linux. Is fixing the crashes from these input files something you're interested in? The input files can be found here: https://github.com/rwhitworth/8cc-fuzz.
The files can be executed as ./8cc -c id_filename
to cause seg faults.
Let me know if I can provide any more information to help narrow down this issue.
Thanks for your contribution first. Recently I wanted to use 8cc to compile tinypy, a very tiny python interpreter, but failed due to the missing file of setjmp.h. I checked with the include directory of 8cc, and did not found setjmp.h.
I know a good compiler is not an easy work. But do you have any plan to fully support the standard c headers?
Or could I use another solution to build a libc implementation by 8cc? If it is yes, which one is a better choice?
Following code aborts with 8cc at runtime, works with gcc 4.9.2 and tcc 0.9.26.
void abort(void);
void exit(int status);
struct {
unsigned x2 : 2;
unsigned x3 : 3;
} a = {2, 3} , *b = &a;
int main() {
b->x3 += b->x2;
if (b->x3 != 5)
abort();
exit(0);
}
$ ./8cc -fdump-ast lex.c
((ushort)=>ushort)__bswap_16(ushort lv=__bsx){(return (conv ((int)=>(ushort) (| (& (conv (>> (conv lv=__bsx=>int) 8)=>int) 255) (<< (& (conv lv=__bsx=>int) 255) 8)))=>ushort));}((uint)=>uint)__bswap_32(uint lv=__bsx){(return (conv (| (| (| (>> (& lv=__bsx -16777216) 24) (>> (& lv=__bsx (conv 16711680=>uint)) 8)) (<< (& lv=__bsx (conv 65280=>uint)) 8)) (<< (& lv=__bsx (conv 255=>uint)) 24))=>uint));}[ERROR] debug.c:115: lex.c:540:2: internal error
These can be ignored safely by 8cc because 8cc reloads everything all the time anyway. They caused some more code to not compile.
typedef struct {
int x;
} S;
S func();
int func2() {
return func().x;
}
$ ./8cc -c t.c
[ERROR] gen.c:401: (null): internal error: ((struct (int)))func()
zsh: exit 1 ./8cc -c t.c
Hello.
This may be my local issue, however I have vanilla xubuntu 16.04.1 VM (installed today) so it can be widespread.
After cloning repo and make && make test
I get the following error:
... ./8cc -w -o test/line.o -c test/line.c ./8cc -w -o test/testmain.o -c test/testmain.c cc -o test/line.bin test/line.o test/testmain.o /usr/bin/ld: test/testmain.o: relocation R_X86_64_PC32 against symbol 'printf@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status Makefile:20: recipe for target 'test/line.bin' failed make: *** [test/line.bin] Error 1 rm test/line.o test/testmain.o
I've spent several hours on this but haven't found a solution. However in C/C++ I am total newb right now. Maybe it will be helpful to update makefile somehow to solve this problem or add some note to README.MD about the issue.
Happy new year!
I don't think 8cc handles line directives currently, so you can't pass code preprocessed by gcc.
I think a cool real world thing to compile successfully may be the sqlite3 amalgamation and shell.
'The amalgamation is a single C code file, named "sqlite3.c" ' ... 'This file contains about 149K lines of code (90K if you omit blank lines and comments) and is over 5.2 megabytes in size.'
http://www.sqlite.org/amalgamation.html
Using it as a test suite / benchmark would be fairly trivial once it compiles as it is only a few source files. (isolating runtime compile issues would be a challenge however.)
I think it would be a really powerful example to compile. I'm not sure how far 8cc is away from building it.
There is a cpp directive called #import implemented in both clang and gcc compilers. I noticed it was absent from your cpp.c
file. If you are unfamiliar, the semantics are as follows:
#import "header.h"
#import <header.h>
It has no real effect on dynamically linked libraries, but on statically linked libraries, it is basically a one time #include. Meaning that the current program will only ever import a file once, which removes the need for #ifndef blocks and making up #define names for every library.
Personally I find this very useful in writing C code, and much cleaner than the include guards in every header file.
./8cc -a xxx.c
is wrong.
./8cc xx.c
cannot work too.
how to link?
Currently I believe these are handled by the same code. I think it is best to have two different expression parsers, one for CPP expressions in #if directives, and a completely different one for constant C expressions.
The C constant expression evaluator is going to need to handle a lot more cases including casts and labels correctly iirc. The CPP one does not really need to operate on an AST at all.
I think this splitting needs to be done before #5 can be fixed.
Thoughts?
As a side note:
It is actually really easy to use this algorithm for CPP expressions:
http://en.wikipedia.org/wiki/Operator-precedence_parser#Precedence_climbing_method
The lack of right associative operators after ternary in CPP expressions means the algorithm is simplified even more than the wiki article.
I actually implemented this in Go for my own preprocessor. To get an idea of what it looks like:
https://github.com/andrewchambers/cc/blob/master/src/cc/cpp/cppexpr.go
https://github.com/andrewchambers/cc/blob/master/src/cc/cpp/cppexpr.go#L261 - actual algorithm.
https://github.com/andrewchambers/cc/blob/master/src/cc/cpp/cppexpr_test.go
I've just generated this piece of C code from a torture test of BF program interpreters. Obviously, being generated code it promises to be a bit of problem. I suspect this promise will be fulfilled.
https://gist.github.com/rdebath/ecd1454a259ece0a8ecf
The CPP define "C" can be declared, on the command line or inside, to be any integer type, signed or unsigned, for 8 bits to 128bits or more. The program, when run, should display one of a few variants of 'hello world' and then finish.
The default of integers complies and runs, but incorrectly.
Any type smaller then an integer gets a 'not an lvalue' error from a "-- * X" type construct.
Longs compile, but seem not to work at all, however, this appears to be a problem with 'stdint.h'.
Test run on Debian Wheezy.
This project seems perfect to make use or contribute to libFirm as their frontend is only C99 and their backend is only experimental for x86-64.
It would be nice if the test suite had a place for self contained bug files which have no output and return zero or nonzero for pass or failure respectively. We could name the files by issue number, or include issue descriptions in the files themselves. Being able to ignore expected failures with a comment would be nice too.
Doing this means we can refactor the normal test suite to not include ugly and obscure failures.
Using creduce to find bugs in 8cc. First one.
short a;
void fn1() { -a; }
-> 8cc: parse.c:525: usual_arith_conv: Assertion `is_inttype(t) && t->size >= type_int->size' failed.
void (*f(int *p))(void) {
return (void *)0;
}
$ 8cc -c t2.c
[ERROR] 8cc.h:426: t.c:1:25: ';' or ',' are expected, but got {
in parse.c
static Ctype *result_type(int op, Ctype *ctype) {
switch (op) {
case OP_LE: case OP_GE: case OP_EQ: case OP_NE: case '<': case '>':
return ctype_int;
default:
return larger_type(ctype, ctype);
}
shouldn't the default case for result_type actually be something like return larger_type(ctype, ctype_int) instead of larger_type(ctype, ctype)?
or am i misunderstanding
If you move/remove the source directory after a make install
, because the BUILD_DIR
has been hardcoded, 8cc tries to use other include dirs (and fails of course).
Maybe this should be the prefix that gets hardcoded, instead? (as an easy fix while still under development)
static void t7() {
int a;
int *p1 = &a + 1;
int *p2 = 1 + &a;
expectp(p1, p2);
}
found this in my fork. Fixing wasn't as straight forward as I thought.
Put this in test.c
long long a = 0LLU;
run 8cc -S ./test.c.
-> segfault.
I think reordering the Left and right children on a '+' node when the left side is a pointer is bad. This adds implicit assumptions about the structure of nodes.
Another way to solve this is to introduce a pointer arith node type. Have you considered that? Just close this issue if you disagree.
Hello After applying make and make test command, what should we do for linux ubuntu. And I went to the desktop and can you make a compiler from scratch using your compiler? Is there permission?
Certain classes of structs should be passed in registers, currently they are not.
From standard:
6.5.16.2 Compound assignment
A compound assignment of the form E1 op= E2 is equivalent to the simple assignment expression E1 = E1 op (E2) , except that the lvalue E1 is evaluated only once
Looking at the code, we are evaluating the lvalue twice, so things like side affecting functions on the lhs will be called twice.
Hi rui314,
I have been fuzzing your compiler and discovered a few crashers to submit.
Reproducer cmdline:
8cc -c $reproducer
In the tarball I have provided a gdblog for each reproducer. There are a total of 72 crashers. I'm not sure that there are not duplicates in this set, but I got this distilled from 1000
The version I am using is from commit 11dd5a5
System: AMD64 Ubuntu 14.04
Found using the fuzzer American Fuzzy Lop ( http://lcamtuf.coredump.cx/afl/ )
Regards,
-Jodie
int x;
int x = 0;
int x;
int
main()
{
x = 0;
return x;
}
Minor one for now, this should generate a "duplicate case label" or similar error.
int
func(int n)
{
switch (n) {
case 2 + 2:
return 1;
case 4:
return 2;
}
return 0;
}
Are you interested in any ports of 8cc? i386 would test that 8cc code generators can handle 32 bit code.
If you feel like working on it for fun I'd be willing to help in my spare time. I think that 8cc is probably the best option for hobbyists who need a toy c compiler for invented processors, but 8cc is pretty x86_64 specific at the moment.
In terms of design I would go for a design the same way the plan9 c compilers are done, without conditional compilation but separate binaries.
8cc doesn't clean up temporary files in /tmp
An issue in regards to constant initializers like:
int x;
int y;
int * a = &y + 1;
int * b = 1 - &y + 1;
int * c = &x - &x + 1;
The C standard states that initializers can be a label + or - a constant. All these expressions can be resolved to such a constant.
test/array.c t7 is implemented but not called in main.
Works with gcc/tcc, aborts on 8cc at runtime.
void abort(void);
void exit(int);
double x = 0x1.fp1;
int main() {
if (x != 3.875)
abort();
return 0;
}
Hello,
I am on OSX 10.9.5 and make test
is failing with
[WARN] cpp.c:628: /usr/include/sys/cdefs.h:81:0: #warning: "Unsupported compiler detected"
[ERROR] parse.c:1904: /usr/include/string.h:81:44: identifier, ( or * are expected, but got )
when I look there I see
But when running with
./8cc -D__GNUC__ -a -o h hello.c
I get
zsh: segmentation fault ./8cc -D__GNUC__ -a -o h hello.c
Should I be including a different set of header files?
Thanks
struct T;
struct T {
int x;
};
int
main()
{
struct T v;
{ struct T { int z; }; }
v.x = 2;
if(v.x != 2)
return 1;
return 0;
}
When running "make test" after compiling 8cc with GCC (4.8.2 on a current Linux Mint), I get the following failure:
Testing macros ... Failed test/macro.c:29: "Thu Apr 02 18:42:49 2015" expected, but got "Thu Apr 2 18:42:49 2015"
The day of the month is zero-padded in 8cc's get_timestamp function, but GCC's __TIMESTAMP__
macro is space-padded, as documented: https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
I note that Clang's documentation does not specify the format of __TIMESTAMP__
: http://clang.llvm.org/docs/LanguageExtensions.html but I can't check its actual behavior right now.
Don't know how many versions of gcc this affects, something to do anonymous inner structs and specified initializers maybe? Perhaps this should be re factored for portability, though its your decision Rui.
[andrewc@workstation 8cc]$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
...
[andrewc@workstation 8cc]$ make
cc -Wall -std=gnu99 -g -I. -O0 -DBUILD_DIR='"/home/andrewc/Desktop/8cc"' -c -o main.o main.c
cc -Wall -std=gnu99 -g -I. -O0 -DBUILD_DIR='"/home/andrewc/Desktop/8cc"' -c -o cpp.o cpp.c
cpp.c:23: error: unknown field ‘sval’ specified in initializer
cpp.c:23: warning: initialization makes integer from pointer without a cast
cpp.c:23: error: initializer element is not constant
cpp.c:23: error: (near initialization for ‘cpp_token_zero’)
cpp.c:24: error: unknown field ‘sval’ specified in initializer
cpp.c:24: warning: initialization makes integer from pointer without a cast
cpp.c:24: error: initializer element is not constant
cpp.c:24: error: (near initialization for ‘cpp_token_one’)
cpp.c: In function ‘make_number’:
cpp.c:108: error: unknown field ‘sval’ specified in initializer
cpp.c:108: warning: initialization makes integer from pointer without a cast
typedef struct {
int type;
int nspace;
bool bol;
bool is_vararg;
char *file;
int line;
int column;
Dict *hideset;
union {
char *sval; // XXX sval here in anonymous member
int punct;
char c;
int position;
};
} Token;
Following code aborts with 8cc at runtime, works with gcc 4.9.2 and tcc 0.9.26.
void abort(void);
int a[] = L"foo";
int b = 0;
int main() {
if (a[2] != L'o' || b)
abort();
return 0;
}
Is it worth adding free() calls to the code?
I assume free() calls are omitted to increase code clarity? Or is it because 8cc originally was going to experiment with garbage collection?
Compiles and executes with gcc and tcc, aborts at runtime on 8cc.
if you remove the function call, then there is no error, probably error in float argument handling.
void abort(void);
double a = 1.0;
double f(double p1, double p2) {
return p1 + p2;
}
int main() {
if (f(a, a) != 2.0)
abort();
return 0;
}
nitpick, but for educational value it may be worth changing.
"A declarator is the part of a declaration that specifies the name that is to be introduced into the program. It can include modifiers such as * (pointer-to)" [1]
A direct declarator does not include the prefix *'s .
An abstract declarator is a declarator without an identifier.
read_direct_declarator1 is not just reading a direct declarator, but a declarator and and abstract declarator as well, the function could be renamed, and maybe the reading of '*' could be shifted to read_declarator.
[1] https://msdn.microsoft.com/en-us/library/e5ace6tf.aspx
Tbh, those microsoft pages finally helped me understand some of this C spec terminology after reading a bunch of C parsers and not understanding. I could be wrong though.
I understand if you can't be bothered making this change yet.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.