From 146c7bf59c4959f780e9bcc756097eb315ed11e9 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 12 Apr 2016 15:03:15 +0200 Subject: [PATCH] remove "const" qualifier from the type of a scalar A scalar that is qualified "const" may still be initialized inside the code. Users of pet, e.g., PPCG, may need to break up the declaration with initialization into a pure declaration and an assignment. Such assignments are not allowed on variables of "const" type. Since it is easier to remove the "const" qualifier in pet, do it here. This solves a problem in PPCG reported by Bruno bodin . Signed-off-by: Sven Verdoolaege --- scan.cc | 7 +++++++ tests/const.c | 6 ++++++ tests/const.scop | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 tests/const.c create mode 100644 tests/const.scop diff --git a/scan.cc b/scan.cc index 2000077..2ebf6a8 100644 --- a/scan.cc +++ b/scan.cc @@ -2765,6 +2765,11 @@ static void insert_intermediate_typedefs(PetTypes *types, QualType type) * * If the base type is that of a record with no top-level definition, * then we replace it by "". + * + * If the variable is a scalar, i.e., a zero-dimensional array, + * then the "const" qualifier, if any, is removed from the base type. + * This makes it easier for users of pet to turn initializations + * into assignments. */ struct pet_array *PetScan::extract_array(__isl_keep isl_id *id, PetTypes *types, __isl_keep pet_context *pc) @@ -2792,6 +2797,8 @@ struct pet_array *PetScan::extract_array(__isl_keep isl_id *id, if (!array) return NULL; + if (depth == 0) + base.removeLocalConst(); name = base.getAsString(); if (types) { diff --git a/tests/const.c b/tests/const.c new file mode 100644 index 0000000..6b24d3f --- /dev/null +++ b/tests/const.c @@ -0,0 +1,6 @@ +void foo() +{ +#pragma scop + const int a = 3; +#pragma endscop +} diff --git a/tests/const.scop b/tests/const.scop new file mode 100644 index 0000000..8bef526 --- /dev/null +++ b/tests/const.scop @@ -0,0 +1,42 @@ +start: 13 +end: 60 +indent: "\t" +context: '{ : }' +schedule: '{ domain: "{ S_0[]; S_1[] }", child: { sequence: [ { filter: "{ S_0[] }" + }, { filter: "{ S_1[] }" } ] } }' +arrays: +- context: '{ : }' + extent: '{ a[] }' + element_type: int + element_size: 4 + declared: 1 + exposed: 1 +statements: +- line: 4 + domain: '{ S_0[] }' + body: + type: expression + expr: + type: op + operation: kill + arguments: + - type: access + killed: '{ S_0[] -> a[] }' + index: '{ S_0[] -> a[] }' + reference: __pet_ref_0 + kill: 1 +- line: 4 + domain: '{ S_1[] }' + body: + type: expression + expr: + type: op + operation: = + arguments: + - type: access + index: '{ S_1[] -> a[] }' + reference: __pet_ref_1 + read: 0 + write: 1 + - type: int + value: 3 -- 2.11.4.GIT