Skip to content

Fixes for #pragma warning #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions source/compiler/sc.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ int pc_compile(int argc, char **argv);
int pc_addconstant(char *name,cell value,int tag);
int pc_addtag(char *name);
int pc_enablewarning(int number,warnmode enable);
int pc_pushwarnings(void);
int pc_popwarnings(void);
void pc_pushwarnings(void);
void pc_popwarnings(void);
void pc_seterrorwarnings(int enable);
int pc_geterrorwarnings(void);

Expand Down Expand Up @@ -841,6 +841,8 @@ SC_FUNC void outinstr(const char *name,emit_outval params[],int numparams);
/* function prototypes in SC5.C */
SC_FUNC int error(long number,...);
SC_FUNC void errorset(int code,int line);
SC_FUNC void warnstack_init(void);
SC_FUNC void warnstack_cleanup(void);
SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type,int subtype);

/* function prototypes in SC6.C */
Expand Down
4 changes: 4 additions & 0 deletions source/compiler/sc1.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,10 @@ int pc_compile(int argc, char *argv[])
error(100,incfname); /* cannot read from ... (fatal error) */
} /* if */
} /* if */
warnstack_init();
preprocess(); /* fetch first line */
parse(); /* process all input */
warnstack_cleanup();
sc_parsenum++;
} while (sc_reparse);

Expand Down Expand Up @@ -700,8 +702,10 @@ int pc_compile(int argc, char *argv[])
else
plungequalifiedfile(incfname); /* parse implicit include file (again) */
} /* if */
warnstack_init();
preprocess(); /* fetch first line */
parse(); /* process all input */
warnstack_cleanup();
if (sc_listing)
goto cleanup;
/* inpf is already closed when readline() attempts to pop of a file */
Expand Down
8 changes: 5 additions & 3 deletions source/compiler/sc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ void parsesingleoption(char *argv);

static int command(void)
{
static const char str_if[]="#if...";
int tok,ret;
cell val;
char *str;
Expand Down Expand Up @@ -1024,7 +1025,7 @@ static int command(void)
ret=CMD_IF;
assert(iflevel>=0);
if (iflevel==0) {
error(26); /* no matching #if */
error(26,str_if); /* no matching #if */
errorset(sRESET,0);
} else {
/* check for earlier #else */
Expand Down Expand Up @@ -1077,7 +1078,7 @@ static int command(void)
case tpENDIF:
ret=CMD_IF;
if (iflevel==0){
error(26); /* no matching "#if" */
error(26,str_if); /* no matching "#if" */
errorset(sRESET,0);
} else {
clearassignments(1);
Expand Down Expand Up @@ -1307,9 +1308,10 @@ static int command(void)
if (ok) {
if (strcmp(str,"enable")==0 || strcmp(str,"disable")==0) {
cell val;
enum s_warnmode enable=(str[0]=='e') ? warnENABLE : warnDISABLE;
do {
preproc_expr(&val,NULL);
pc_enablewarning(val,(str[0]=='e') ? warnENABLE : warnDISABLE);
pc_enablewarning(val,enable);
} while (*lptr!='\0');
} else if (strcmp(str,"push")==0) {
pc_pushwarnings();
Expand Down
35 changes: 25 additions & 10 deletions source/compiler/sc5.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static char *errmsg[] = {
/*023*/ "array assignment must be simple assignment\n",
/*024*/ "\"break\" or \"continue\" is out of context\n",
/*025*/ "function heading differs from prototype\n",
/*026*/ "no matching \"#if...\"\n",
/*026*/ "no matching \"%s\"\n",
/*027*/ "invalid character constant\n",
/*028*/ "invalid subscript (not an array or too many subscripts): \"%s\"\n",
/*029*/ "invalid expression, assumed zero\n",
Expand Down Expand Up @@ -421,31 +421,46 @@ int pc_enablewarning(int number,warnmode enable)
/* pc_pushwarnings()
* Saves currently disabled warnings, used to implement #pragma warning push
*/
int pc_pushwarnings(void)
void pc_pushwarnings(void)
{
void *p;
p=calloc(sizeof(struct s_warnstack),1);
if (p==NULL) {
if (p==NULL)
error(103); /* insufficient memory */
return FALSE;
}
memmove(p,&warnstack,sizeof(struct s_warnstack));
warnstack.next=p;
return TRUE;
}

/* pc_popwarnings()
* This function is the reverse of pc_pushwarnings()
*/
int pc_popwarnings(void)
void pc_popwarnings(void)
{
void *p;
if (warnstack.next==NULL)
return FALSE; /* nothing to do */
if (warnstack.next==NULL) {
error(26,"#pragma warning push"); /* no matching "#pragma warning push" */
return; /* nothing to do */
} /* if */
p=warnstack.next;
memmove(&warnstack,p,sizeof(struct s_warnstack));
free(p);
return TRUE;
}

SC_FUNC void warnstack_init(void)
{
memset(&warnstack,0,sizeof(warnstack));
}

SC_FUNC void warnstack_cleanup(void)
{
struct s_warnstack *cur,*next;
if (warnstack.next!=NULL)
error(1,"#pragma warning pop","-end of file-");
for (cur=warnstack.next; cur!=NULL; cur=next) {
next=cur->next;
free(cur);
} /* for */
warnstack.next=NULL;
}

/* pc_seterrorwarnings()
Expand Down
7 changes: 7 additions & 0 deletions source/compiler/tests/pragma_warning_1.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
'test_type': 'output_check',
'errors': """
pragma_warning_1.pwn(1) : warning 238: meaningless combination of class specifiers (const reference)
pragma_warning_1.pwn(8) : warning 238: meaningless combination of class specifiers (const reference)
"""
}
13 changes: 13 additions & 0 deletions source/compiler/tests/pragma_warning_1.pwn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
forward Func(const &arg); // warning 238: meaningless combination of class specifiers (const reference)

#pragma warning disable 238
#pragma warning push
forward Func(const &arg); // shouldn't warn on this line

#pragma warning enable 238
forward Func(const &arg); // warning 238: meaningless combination of class specifiers (const reference)

#pragma warning pop
forward Func(const &arg); // shouldn't warn on this line

main(){}
6 changes: 6 additions & 0 deletions source/compiler/tests/pragma_warning_2.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
'test_type': 'output_check',
'errors': """
pragma_warning_2.pwn(5) : error 001: expected token: "#pragma warning pop", but found "-end of file-"
"""
}
4 changes: 4 additions & 0 deletions source/compiler/tests/pragma_warning_2.pwn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma warning disable 238
#pragma warning push
main(){}
// error 001: expected token: "#pragma warning pop", but found "-end of file-"
6 changes: 6 additions & 0 deletions source/compiler/tests/pragma_warning_3.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
'test_type': 'output_check',
'errors': """
pragma_warning_3.pwn(1) : error 026: no matching "#pragma warning push"
"""
}
2 changes: 2 additions & 0 deletions source/compiler/tests/pragma_warning_3.pwn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma warning pop // error 026: no matching "#pragma warning push"
main(){}