Open MorelSerge opened 5 years ago
Thanks for the report! Do you have a minimal example that throws the error? I couldn't seem to reproduce it with just the just your snippet, using the code below (with inputs and outputs to ensure the whole computation isn't optimized to nothing...):
#include <stdint.h>
#define MAX_TP_OBJ_LENGTH 5
#define MAX_TP 5
typedef struct triple_pattern {
uint8_t subject[MAX_TP_OBJ_LENGTH];
uint8_t predicate[MAX_TP_OBJ_LENGTH];
uint8_t object[MAX_TP_OBJ_LENGTH];
} triple_pattern_t;
triple_pattern_t triple_patterns[MAX_TP];
uint8_t c_tp_part[MAX_TP_OBJ_LENGTH];
struct In {
int a;
};
struct Out {
int b;
};
int compute(struct In *input, struct Out *output) {
int j;
for (j = 0; j < MAX_TP_OBJ_LENGTH; j++) {
c_tp_part[j] = input->a;
}
int state_a = input->a;
if (state_a < MAX_TP) {
triple_patterns[state_a].subject = c_tp_part;
output->b = triple_patterns[state_a].subject[0];
}
}
Hi, thanks for getting back to me! I reduced my code to the least amount possible that produces the same error:
#include <stdint.h>
#include "compute.h"
int compute(In_t *input, Out_t *output) {
output_t objects[MAX_TP];
extract(input->input, objects);
}
int extract(uint8_t input[MAX_INPUT], output_t objects[MAX_TP]) {
int i, j, k;
uint8_t c_char;
uint8_t c_tp_part[MAX_TP_OBJ_LENGTH];
k = 0;
j = 0;
for (i = 0; i < MAX_INPUT; i++) {
c_char = input[i];
if (c_char != UNDEFINED) {
if (j == 0) {
j = 1;
} else {
if (k == 0 && j - 1 < MAX_TP) {
objects[j - 1].a = c_tp_part;
}
}
}
}
return 1;
}
#define MAX_INPUT 500
#define MAX_RESULTS 10
#define MAX_TP_OBJ_LENGTH 10
#define MAX_TP_LENGTH 3 * MAX_TP_OBJ_LENGTH + 3
#define MAX_TP 3
#ifndef UNDEFINED
#define UNDEFINED 0
#endif
typedef struct In {
uint8_t input[MAX_INPUT];
} In_t;
typedef struct output {
uint8_t a[MAX_TP_OBJ_LENGTH];
uint8_t b[MAX_TP_OBJ_LENGTH];
uint8_t c[MAX_TP_OBJ_LENGTH];
} output_t;
typedef struct Out {
output_t results[MAX_RESULTS];
} Out_t;
Can you reproduce the exception with this?
I was able to reproduce the error you got, thanks.
It looks like this is a bug in the way that the compiler handles passing arrays of structs with array members to functions. I'll try to look into this a bit more deeply and get back to you, but as a workaround, you could try moving the declaration to a global variable.
For example, the following compiles without error:
#include <stdint.h>
#include "compute.h"
output_t objects[MAX_RESULTS];
int compute(In_t *input, Out_t *output) {
extract(input->input);
output->results = objects;
}
int extract(uint8_t input[MAX_INPUT]) {
int i, j, k;
uint8_t c_char;
uint8_t c_tp_part[MAX_TP_OBJ_LENGTH];
k = 0;
j = 0;
for (i = 0; i < MAX_INPUT; i++) {
c_char = input[i];
if (c_char != UNDEFINED) {
if (j == 0) {
j = 1;
} else {
if (k == 0 && j - 1 < MAX_TP) {
objects[j - 1].a = c_tp_part;
}
}
}
}
return 1;
}
This does compile successfully! Thank you.
One thing that might help you find the bug is that even removing 1 "if" statement in the code I previously posted, makes it work.
I'm stumbling on a weird error. I got an array of structs like this:
Now I have a separate state variable
int state_a
, which I then use to accesstriple_patterns
like this:This does not work, see stacktrace below. What does work is this:
What am I missing in the first example that makes it fail to compile?
Thanks
Stacktrace: