Skip to content

Commit

Permalink
Merge pull request #1429 from stan-dev/fix/system-macro-clashes
Browse files Browse the repository at this point in the history
Add certain system-specific macros to backend name mangling
  • Loading branch information
WardBrian authored May 29, 2024
2 parents 3f0b2a6 + bf1881a commit 6feab53
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 138 deletions.
9 changes: 6 additions & 3 deletions src/stan_math_backend/Mangle.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ let cpp_kwrds =
; "static_assert"; "static_cast"; "switch"; "template"; "this"
; "thread_local"; "throw"; "try"; "typeid"; "typename"; "union"; "unsigned"
; "using"; "virtual"; "volatile"; "wchar_t"; "xor"; "xor_eq" ]
@ (* stan implementation keywords *)
[ "fvar"; "STAN_MAJOR"; "STAN_MINOR"; "STAN_PATCH"; "STAN_MATH_MAJOR"
; "STAN_MATH_MINOR"; "STAN_MATH_PATCH" ])
(* stan implementation keywords *)
@ [ "fvar"; "STAN_MAJOR"; "STAN_MINOR"; "STAN_PATCH"; "STAN_MATH_MAJOR"
; "STAN_MATH_MINOR"; "STAN_MATH_PATCH" ]
@ (* system macros *)
[ "BSD"; "BSD4_2"; "BSD4_3"; "BSD4_4"; "EMSCRIPTEN"; "hpux"; "sun"; "linux"
; "VMS"; "i386"; "mips" ])

let add_prefix_to_kwrds s = if Set.mem cpp_kwrds s then prepend_kwrd s else s
72 changes: 52 additions & 20 deletions test/integration/good/code-gen/cpp-reserved-words.stan
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
functions {
void alignas(int asm){}
void alignof(int char){}
int and(int STAN_MAJOR){
void alignas(int asm) {

}
void alignof(int char) {

}
int and(int STAN_MAJOR) {
return STAN_MAJOR;
}
void and_eq(real STAN_MINOR){}
void asm(vector class){}
void bitand(int constexpr){}
void bitor(){}
void bool(){}
void case(){}
void catch(){}
void char(){}
void char16_t(){}
void char32_t(){}
void and_eq(real STAN_MINOR) {

}
void asm(vector class) {

}
void bitand(int constexpr) {

}
void bitor() {

}
void bool() {

}
void case() {

}
void catch() {

}
void char() {

}
void char16_t() {

}
void char32_t() {

}
}

data {
real class;
real compl;
Expand All @@ -30,7 +53,6 @@ data {
real dynamic_cast;
real enum;
}

parameters {
real explicit;
real float;
Expand All @@ -48,7 +70,6 @@ parameters {
real operator;
real or;
}

model {
real or_eq;
real private;
Expand All @@ -66,7 +87,6 @@ model {
real this;
real thread_local;
}

generated quantities {
real throw;
real try;
Expand All @@ -84,11 +104,23 @@ generated quantities {
real STAN_MATH_MAJOR;
real STAN_MATH_MINOR;
real STAN_MATH_PATCH;

for(STAN_MAJOR in 1:2){
for (STAN_MAJOR in 1 : 2) {
int STAN_MINOR = 3;
int STAN_PATCH = STAN_MINOR;
alignas(STAN_PATCH);
STAN_MINOR=and(STAN_PATCH);
STAN_MINOR = and(STAN_PATCH);
}

int BSD;
int BSD4_2;
int BSD4_3;
int BSD4_4;
int EMSCRIPTEN;
int hpux;
int sun;
int linux;
int VMS;
int i386;
int mips;
}
Loading

0 comments on commit 6feab53

Please sign in to comment.