Skip to content

Commit 582fa94

Browse files
Update regression tests for #327.
Also change the unimplemented canWrite constraints case from a typedef to a crazy #include in anticipation of #408.
1 parent c7412d3 commit 582fa94

8 files changed

+102
-59
lines changed

clang/test/3C/base_subdir/canwrite_constraints_function_and_variable.c renamed to clang/test/3C/base_subdir/canwrite_constraints.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,21 @@
77
// TODO: Windows compatibility?
88

99
// "Lower" case: -base-dir should default to the working directory, so we should
10-
// not allow canwrite_constraints_function_and_variable.h to change, and the
11-
// internal types of q and the return should remain wild.
10+
// not allow canwrite_constraints.h to change, and the internal types of q and
11+
// the return should remain wild.
1212
//
13-
// RUN: cd %S && 3c -addcr -output-dir=%t.checked/base_subdir -warn-all-root-cause -verify %s
14-
// RUN: FileCheck -match-full-lines -check-prefixes=CHECK_LOWER --input-file %t.checked/base_subdir/canwrite_constraints_function_and_variable.c %s
15-
// RUN: test ! -f %t.checked/canwrite_constraints_function_and_variable.checked.h
13+
// RUN: cd %S && 3c -addcr -output-dir=%t.checked/base_subdir -warn-all-root-cause -verify %s --
14+
// RUN: FileCheck -match-full-lines -check-prefixes=CHECK_LOWER --input-file %t.checked/base_subdir/canwrite_constraints.c %s
15+
// RUN: test ! -f %t.checked/canwrite_constraints.checked.h
1616

1717
// "Higher" case: When -base-dir is set to the parent directory, we can change
18-
// canwrite_constraints_function_and_variable.h, so both q and the return should
19-
// become checked.
18+
// canwrite_constraints.h, so both q and the return should become checked.
2019
//
21-
// RUN: cd %S && 3c -addcr -base-dir=.. -output-dir=%t.checked2 %s
22-
// RUN: FileCheck -match-full-lines -check-prefixes=CHECK_HIGHER --input-file %t.checked2/base_subdir/canwrite_constraints_function_and_variable.c %s
23-
// RUN: FileCheck -match-full-lines -check-prefixes=CHECK_HIGHER --input-file %t.checked2/canwrite_constraints_function_and_variable.h %S/../canwrite_constraints_function_and_variable.h
20+
// RUN: cd %S && 3c -addcr -base-dir=.. -output-dir=%t.checked2 %s --
21+
// RUN: FileCheck -match-full-lines -check-prefixes=CHECK_HIGHER --input-file %t.checked2/base_subdir/canwrite_constraints.c %s
22+
// RUN: FileCheck -match-full-lines -check-prefixes=CHECK_HIGHER --input-file %t.checked2/canwrite_constraints.h %S/../canwrite_constraints.h
2423

25-
#include "../canwrite_constraints_function_and_variable.h"
24+
#include "../canwrite_constraints.h"
2625

2726
int *bar(int *q) {
2827
// CHECK_LOWER: int *bar(int *q : itype(_Ptr<int>)) : itype(_Ptr<int>) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Like canwrite_constraints_unimplemented.c but tests the third former base dir
2+
// matching bug from
3+
// https://github.com/correctcomputation/checkedc-clang/issues/327: symlinks.
4+
// See the comments in canwrite_constraints_unimplemented.c.
5+
6+
// We can't assume we can make symlinks on Windows.
7+
// UNSUPPORTED: system-windows
8+
9+
// Set up the following structure:
10+
//
11+
// %t.base/
12+
// canwrite_constraints_symlink.c : copy of this file
13+
// base_subdir_partial_defn.h -> clang/test/3C/base_subdir_partial_defn.h
14+
//
15+
// RUN: rm -rf %t*
16+
// RUN: mkdir %t.base
17+
// RUN: cp %s %t.base/canwrite_constraints_symlink.c
18+
// RUN: ln -s %S/../base_subdir_partial_defn.h %t.base/base_subdir_partial_defn.h
19+
20+
// Now 3C should know that it can't write to base_subdir_partial_defn.h because the symlink
21+
// goes out of the base dir.
22+
//
23+
// RUN: cd %t.base && 3c -addcr -verify canwrite_constraints_symlink.c --
24+
25+
// expected-error@base_subdir_partial_defn.h:1 {{3C internal error: 3C generated changes to this file even though it is not allowed to write to the file}}
26+
// expected-note@base_subdir_partial_defn.h:1 {{-dump-unwritable-changes}}
27+
28+
void
29+
#include "base_subdir_partial_defn.h"

clang/test/3C/base_subdir/canwrite_constraints_typedef.c

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// An example of a case that is not handled by the canWrite constraints code and
2+
// causes 3C to generate a change to an unwritable file. Test that 3C generates
3+
// an error diagnostic.
4+
// (https://github.com/correctcomputation/checkedc-clang/issues/387)
5+
6+
// TODO: Ditto the TODO comments from canwrite_constraints.c re the RUN
7+
// commands.
8+
// RUN: cd %S && 3c -addcr -verify %s --
9+
10+
// expected-error@../base_subdir_partial_defn.h:1 {{3C internal error: 3C generated changes to this file even though it is not allowed to write to the file}}
11+
// expected-note@../base_subdir_partial_defn.h:1 {{-dump-unwritable-changes}}
12+
13+
// The "../base_subdir_partial_defn.h" path is testing two former base dir matching bugs from
14+
// https://github.com/correctcomputation/checkedc-clang/issues/327:
15+
//
16+
// 1. 3C canonicalizes ".." path elements. Otherwise, it would think ".." is a
17+
// subdirectory of the current directory.
18+
//
19+
// 2. 3C compares entire path components and knows that
20+
// base_subdir_partial_defn.h is not under base_subdir.
21+
//
22+
// It would be valid to test these cases in combination with either code that is
23+
// correctly constrained or code for which constraining is unhandled. We choose
24+
// the latter in order to keep all the "weird" stuff in this test file and leave
25+
// canwrite_constraints.c sane.
26+
27+
// Since the declaration of foo begins with the "void" in this (writable) file,
28+
// 3C currently assumes the whole declaration is writable. Then 3C rewrites the
29+
// declaration of the parameter "x", which is wholly within
30+
// ../base_subdir_partial_defn.h; the rewriter seems to handle this with no
31+
// trouble. But then the proposed change to an unwritable file trips the error
32+
// we are testing.
33+
//
34+
// Changing 3C to handle such contrived preprocessor nonsense correctly is a low
35+
// priority, so this test hopefully won't have to be changed for a while, if
36+
// ever.
37+
38+
void
39+
#include "../base_subdir_partial_defn.h"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Used by base_subdir/canwrite_constraints_unimplemented.c and
2+
// stdout_mode_write_other.c .
3+
//
4+
// This file has a strange name so that
5+
// base_subdir/canwrite_constraints_unimplemented.c can test that 3C compares
6+
// entire path components and knows that base_subdir_partial_defn.h is not under
7+
// base_subdir (see
8+
// https://github.com/correctcomputation/checkedc-clang/issues/327).
9+
10+
// The lack of a return type here is intentional. The return type is in the file
11+
// that includes base_subdir_partial_defn.h.
12+
foo(int *x) {}

clang/test/3C/canwrite_constraints_function_and_variable.h renamed to clang/test/3C/canwrite_constraints.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Used by base_subdir/canwrite_constraints_function_and_variable.c .
1+
// Used by base_subdir/canwrite_constraints.c .
22

33
// Note: Only the test in which this file is non-writable verifies diagnostics
44
// and will use the expected warning comments below. The test in which this file

clang/test/3C/stdout_mode_typedef.c

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Like the base_subdir/canwrite_constraints_unimplemented test except that
2+
// writing base_subdir_partial_defn.h is not restricted by the base dir, so we
3+
// reach the stdout mode restriction.
4+
5+
// RUN: 3c -base-dir=%S -addcr -verify %s --
6+
7+
// expected-error@base_subdir_partial_defn.h:1 {{3C generated changes to this file, which is under the base dir but is not the main file and thus cannot be written in stdout mode}}
8+
// expected-note@base_subdir_partial_defn.h:1 {{-dump-unwritable-changes}}
9+
10+
void
11+
#include "base_subdir_partial_defn.h"

0 commit comments

Comments
 (0)