Skip to content

Commit 8d7d3d0

Browse files
committed
merge check output code into master
2 parents 0ed0c71 + 7a4c423 commit 8d7d3d0

File tree

53 files changed

+1149
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1149
-347
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ valgrind also usually detect this type of error, e.g.:
140140
* Installation on Linux and Windows Subsystem for Linux
141141

142142
```bash
143-
curl -L https://github.com/COMP1511UNSW/dcc/releases/download/2.2/dcc_2.2_all.deb -o /tmp/dcc_2.2_all.deb
144-
sudo apt install /tmp/dcc_2.2_all.deb
143+
curl -L https://github.com/COMP1511UNSW/dcc/releases/download/2.5/dcc_2.5_all.deb -o /tmp/dcc_2.5_all.deb
144+
sudo apt install /tmp/dcc_2.5_all.deb
145145
# on WSL (not Linux) this might be necessary to run programs
146146
sudo bash -c "echo 0 > /proc/sys/kernel/yama/ptrace_scope;echo 1 >/proc/sys/vm/overcommit_memory"
147147
```
@@ -152,7 +152,7 @@ valgrind also usually detect this type of error, e.g.:
152152
Install gdb - see https://sourceware.org/gdb/wiki/PermissionsDarwin
153153

154154
```bash
155-
sudo curl -L https://github.com/COMP1511UNSW/dcc/releases/download/2.2/dcc -o /usr/local/bin/dcc
155+
sudo curl -L https://github.com/COMP1511UNSW/dcc/releases/download/2.5/dcc -o /usr/local/bin/dcc
156156
sudo chmod o+rx /usr/local/bin/dcc
157157
```
158158

__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main():
3333
signal.signal(signal.SIGINT, handler)
3434
debug = int(os.environ.get('DCC_DEBUG', '0'))
3535
colorize_output = sys.stderr.isatty() or os.environ.get('DCC_COLORIZE_OUTPUT', False)
36-
if debug: print(sys.argv, 'DCC_RUN_INSIDE_GDB="%s" DCC_PID="%s"' % (os.environ.get('DCC_RUN_INSIDE_GDB', ''), os.environ.get('DCC_PID', '')), file=sys.stderr)
36+
if debug > 1: print(sys.argv, 'DCC_RUN_INSIDE_GDB="%s" DCC_PID="%s"' % (os.environ.get('DCC_RUN_INSIDE_GDB', ''), os.environ.get('DCC_PID', '')), file=sys.stderr)
3737
if not sys.argv[1:] and 'DCC_RUN_INSIDE_GDB' in os.environ:
3838
drive_gdb()
3939
elif not sys.argv[1:] and 'DCC_PID' in os.environ:

compile.py

Lines changed: 391 additions & 298 deletions
Large diffs are not rendered by default.

compiler_explanations.py

Lines changed: 129 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ def get_short_explanation(self, message, colorize_output):
7979
if colorize_output:
8080
color = colors.color
8181
else:
82-
color = lambda text, color_name: text
82+
color = lambda text, *args, **kwargs: text
8383

8484
parameters = dict((name, getattr(message, name)) for name in dir(message) if not name.startswith('__'))
8585
parameters['match'] = match
8686
parameters['color'] = color
87-
parameters['emphasize'] = lambda text: color(text, 'red')
87+
parameters['emphasize'] = lambda text: color(text, style='bold')
88+
parameters['danger'] = lambda text: color(text, color='red', style='bold')
89+
parameters['info'] = lambda text: color(text, 'cyan', style='bold')
8890
return eval('f"' + self.explanation.replace('\n', '\\n') +'"', globals(), parameters)
8991

9092
explanations = [
@@ -450,14 +452,138 @@ def get_short_explanation(self, message, colorize_output):
450452

451453
regex = r"indirection requires pointer operand \('(.*)' invalid\)",
452454

453-
explanation = """ you are trying to use '{emphasize(underlined_word)}' as a pointer.
455+
explanation = """You are trying to use '{emphasize(underlined_word)}' as a pointer.
454456
You can not do this because '{emphasize(underlined_word)}' is of type {emphasize(match.group(1))}.
455457
""",
456458

457459
reproduce = """
458460
int main(int argc, char *argv[]) {
459461
return *argc;
460462
}
463+
""",
464+
),
465+
466+
Explanation(
467+
label = 'duplicated-cond',
468+
469+
regex = r"duplicated .*\bif\b.* condition",
470+
471+
explanation = """You have repeated the same condition in a chain of if statements.
472+
Only the first if statement using the condition can be executed.
473+
The others can never be executed.
474+
475+
""",
476+
477+
reproduce = """
478+
int main(int argc, char *argv[]) {
479+
if (argc == 1)
480+
return 42;
481+
else if (argc == 1)
482+
return 43;
483+
else
484+
return 44;
485+
}
486+
""",
487+
),
488+
489+
Explanation(
490+
label = 'duplicated-branches',
491+
492+
regex = r"condition has identical branches",
493+
494+
explanation = """Your if statement has identical then and else parts.
495+
It is pointless to have an if statement which executes the same code
496+
when its condition is true and also when its condition is false.
497+
498+
""",
499+
500+
reproduce = """
501+
int main(int argc, char *argv[]) {
502+
if (argc == 1)
503+
return 42;
504+
else
505+
return 42;
506+
}
507+
""",
508+
),
509+
510+
Explanation(
511+
label = 'logical-or-always-true',
512+
513+
regex = r"logical .?\bor\b.* is always true",
514+
515+
explanation = """Your '{emphasize('||')}' expression is always true, no matter what value variables have.
516+
Perhaps you meant to use '{emphasize('&&')}' ?
517+
518+
""",
519+
520+
reproduce = """
521+
int main(int argc, char *argv[]) {
522+
if (argc > 1 || argc < 3)
523+
return 42;
524+
else
525+
return 43;
526+
}
527+
""",
528+
),
529+
530+
Explanation(
531+
label = 'logical-and-always-false',
532+
533+
regex = r"logical .?\band\b.* is always false",
534+
535+
explanation = """Your '{emphasize('&&')}' expression is always false, no matter what value variables have.
536+
Perhaps you meant to use '{emphasize('||')}' ?
537+
538+
""",
539+
540+
reproduce = """
541+
int main(int argc, char *argv[]) {
542+
if (argc > 1 && argc < 1)
543+
return 42;
544+
else
545+
return 43;
546+
}
547+
""",
548+
),
549+
550+
Explanation(
551+
label = 'logical-equal-expressions',
552+
553+
regex = r"logical .?((and|or)).? of equal expressions",
554+
555+
explanation = """Your have used '{emphasize(highlighted_word)}' with same lefthand and righthand operands.
556+
If this what you meant, it can be simplified: {emphasize('x ' + highlighted_word + ' x')} can be replaced with just {emphasize('x')}.
557+
558+
""",
559+
560+
reproduce = """
561+
int main(int argc, char *argv[]) {
562+
if (argc > 1 ||argc > 1)
563+
return 42;
564+
else
565+
return 43;
566+
}
567+
""",
568+
),
569+
570+
Explanation(
571+
label = 'shadow-local-variable',
572+
573+
regex = r"declaration shadows a local variable",
574+
575+
explanation = """Your already have a variable named '{emphasize(highlighted_word)}'.
576+
It is confusing to have a second overlapping declaration of the same variable name.
577+
578+
""",
579+
580+
reproduce = """
581+
int main(int argc, char *argv[]) {
582+
{
583+
int argc = 42;
584+
return argc;
585+
}
586+
}
461587
""",
462588
),
463589
]

dcc_check_output.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static void __dcc_check_close(int fd) {
1111
}
1212

1313
static void __dcc_check_output_exit(void) {
14+
debug_printf(3, "__dcc_cleanup_before_exit\n");
1415
fflush(stdout);
1516
}
1617

@@ -26,14 +27,14 @@ static void disable_check_output(void) {
2627
//lins longer than this will produce an error if output checking enabled
2728
#define ACTUAL_LINE_MAX 65536
2829

30+
static unsigned char *expected_stdout;
31+
2932
static int ignore_case;
3033
static int ignore_empty_lines;
3134
static int ignore_trailing_white_space;
3235
static int ignore_characters[N_ASCII];
3336
static int max_stdout_bytes;
3437

35-
static unsigned char *expected_stdout;
36-
3738
static int getenv_boolean(const char *name, int default_value);
3839

3940
static int init_check_output(void) {
@@ -117,8 +118,9 @@ static void __dcc_check_close(int fd) {
117118
}
118119

119120
static void __dcc_check_output_exit(void) {
120-
fflush(stdout);
121+
debug_printf(3, "__dcc_cleanup_before_exit\n");
121122
if (expected_stdout) {
123+
fflush(stdout);
122124
__dcc_check_all_output_seen_at_exit();
123125
}
124126
}

dcc_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ int __wrap_main(int argc, char *argv[], char *envp[]) {
162162
return 1; // not reached
163163
}
164164

165+
165166
static void __dcc_main_sanitizer1(int argc, char *argv[], char *envp[]) {
166167
debug_printf(2, "main sanitizer1\n");
167168
close(to_sanitizer2_pipe[0]);

drive_gdb.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,12 @@ def parse_gdb_stack_frame(line):
374374
debug_print(3, 'parse_gdb_stack_frame', m != None, line)
375375
if m:
376376
filename = m.group('filename')
377-
if filename.startswith("/usr/") or filename.startswith("../sysdeps/") or filename.endswith("libioP.h"):
377+
if (
378+
filename.startswith("/usr/") or
379+
filename.startswith("../sysdeps/") or
380+
filename.endswith("libioP.h") or
381+
filename.endswith("iofclose.c")
382+
):
378383
m = None
379384
if m:
380385
return Location(m.group('filename'), m.group('line_number'), function=m.group('function'), params=m.group('params'), frame_number=m.group('frame_number'))

tests/check_output/check_birds.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export DCC_EXPECTED_STDOUT=" ___
1212

1313
for bird in "$bird_directory"/bird-*.c
1414
do
15-
basename "$bird"
15+
basename "$bird" 1>&2
1616
$dcc "$bird"
17-
./a.out || continue
18-
echo "Test $bird failed"
17+
./a.out >/dev/null || continue
18+
echo "Test $bird failed" 1>&2
1919
exit 1
2020
done
21-
echo "All Tests Correct"
21+
echo "All Tests Correct" 1>&2
2222
exit 0

tests/check_output/simple_check_output.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ function run_test {
1919
test_number=$((test_number + 1))
2020

2121
(
22-
echo "*** Test $test_number - $label"
23-
echo "*** Test Environment $environment_variables"
24-
echo "expected output: $DCC_EXPECTED_STDOUT"
25-
echo "actual output : $actual_output"
22+
echo "*** Test $test_number - $label" 1>&2
23+
echo "*** Test Environment $environment_variables" 1>&2
24+
echo "expected output: $DCC_EXPECTED_STDOUT" 1>&2
25+
echo "actual output : $actual_output" 1>&2
2626

27-
eval "$environment_variables"' ./a.out "$actual_output"'
27+
eval "$environment_variables"' ./a.out "$actual_output" >/dev/null'
2828
exit_status=$?
2929

3030
case "$label" in
@@ -34,7 +34,7 @@ function run_test {
3434

3535
if (((exit_status != 0) != $expected_result_status))
3636
then
37-
echo "*** Test failed ***"
37+
echo "*** Test failed ***" 1>&2
3838
exit 1
3939
fi
4040
) || exit 1
@@ -68,5 +68,5 @@ run_test compare-only-characters-3-fail "DCC_COMPARE_ONLY_CHARACTERS=hel"
6868
run_test compare-only-characters-4 "DCC_IGNORE_CASE=1 DCC_COMPARE_ONLY_CHARACTERS=hel" $'Hell\n'
6969

7070

71-
echo All Tests Correct
71+
echo All Tests Correct 1>&2
7272

tests/do_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ done
99
tests_dir=$(dirname $(readlink -f $0))
1010
cd "$tests_dir"
1111

12-
trap 'rm -fr tmp* a.out;exit' EXIT INT TERM
12+
trap 'exit_status=$?;rm -fr tmp* a.out;exit $exit_status' EXIT INT TERM
1313

1414
# some values reported in errors are not determinate (e.g. variable addresses)
1515
# and will vary between execution and definitely between platforms

0 commit comments

Comments
 (0)