llnl / llnl/rose

ROSE output for a struct return type is incorrect

Open
#355 0 comments 0 reactions 1 assignee View on GitHub

@pinnown is already working on this.

Since Sep 8, 2020.

Dominant language
C
Stars
688
Forks
144
PR merge metrics
No merged PRs in 30d

Description

ROSE fails to output valid c for the following ```test.c``` program:
```
#include
#include

#ifndef PRIVATE
#define PRIVATE static
#endif

typedef struct num2 num2;

PRIVATE struct num1* add_struct(num2*);

typedef struct num1 num1;

struct num1 {
int y;
};

struct num2 {
num1* x;
};

PRIVATE num1* add_struct(num2* a) {
return a->x;
}

int main() {
// Test 3: Weird struct error?
num1* d = malloc(sizeof(num1));
num2* e = malloc(sizeof(num2));
d->y = 4;
e->x = d;
d = add_struct(e);
printf("D should be 4 and is: %d\n", d->y);

free(d);
free(e);
return 0;
}

```
The resulting ```rose_test.c``` file is
```
#include
#include
#ifndef PRIVATE
#define PRIVATE static
#endif
struct num2 ;
typedef struct num2 num2;
struct num1 ;
static num1 *add_struct(num2 *);
typedef struct num1 num1;

struct num1
{
int y;
}
;

struct num2
{
num1 *x;
}
;

static num1 *add_struct(num2 *a)
{
return a -> x;
}

int main()
{
// Test 3: Weird struct error?
num1 *d = (malloc(sizeof(num1 )));
num2 *e = (malloc(sizeof(num2 )));
d -> y = 4;
e -> x = d;
d = add_struct(e);
printf("D should be 4 and is: %d\n",d -> y);
free(d);
free(e);
return 0;
}
```
The error when attempting to compile ```rose_test.c``` with gcc is as follows:
```
$ gcc ../rose_bug1.c
../rose_bug1.c:9:8: error: unknown type name ‘num1’
static num1 *add_struct(num2 *);
^~~~
../rose_bug1.c:24:14: error: conflicting types for ‘add_struct’
static num1 *add_struct(num2 *a)
^~~~~~~~~~
../rose_bug1.c:9:14: note: previous declaration of ‘add_struct’ was here
static num1 *add_struct(num2 *);
^~~~~~~~~~
```
This output boils down to one line I believe ```static num1 *add_struct(num2 *);``` in ```rose_test.c``` as ROSE replaced the correct return value of ```struct num1 *``` in the original file with a return value of ```num1 *``` and the typedef does not occur until after. This however is valid c.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.