[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] problem with -b option and ternary operator
From: |
Somchai Smythe |
Subject: |
[Tinycc-devel] problem with -b option and ternary operator |
Date: |
Wed, 22 Nov 2017 12:59:24 +0700 |
Hello tinycc-devel list,
Using 330c01bfc6fa6721fd455911a966bce041df31d8 version of tcc, I hit a
bug while trying to compile stuff using the '-b' option. Here is a
reduced test case:
------8< cut here 8<-------
// reduced test case for -b bug with ternary operator
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct token {
char *toketext;
};
struct tree_node {
struct token *leaftoken;
};
int main(void) {
struct tree_node *node=(struct tree_node *)malloc(sizeof(struct tree_node));
node->leaftoken=(struct token *)malloc(sizeof(struct token));
node->leaftoken->toketext=strdup("whatever");
// the ternary operator will cause
// 'error: unhandled size when dereferencing bounded pointer'
// when you compile with tcc and '-b' option
// true even for 330c01bfc6fa6721fd455911a966bce041df31d8
// set argument to if to 1 to see error, set it to 0 to see pass
#if 1
fprintf(stderr, "data->leaftoken->toketext = '%s'\n",
!(node->leaftoken->toketext) ? "null" : node->leaftoken->toketext);
#else
// but this works
fprintf(stderr, "data->leaftoken->toketext = '%s'\n",
node->leaftoken->toketext ? node->leaftoken->toketext : "null");
#endif
return EXIT_SUCCESS;
}
------8< cut here 8<-------
When compiled without '-b' option, both ways to do it run and work fine.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Tinycc-devel] problem with -b option and ternary operator,
Somchai Smythe <=