ASAN: emit line information of stack variables. 77/210377/3
authormarxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 9 Oct 2018 08:34:52 +0000 (08:34 +0000)
committerDongkyun Son <dongkyun.s@samsung.com>
Mon, 22 Jul 2019 11:52:35 +0000 (11:52 +0000)
2018-10-09  Martin Liska  <mliska@suse.cz>

* asan.c (asan_emit_stack_protection): If a stack variable
is located in a same file as current function, then emit
line info into variable definition string.
2018-10-09  Martin Liska  <mliska@suse.cz>

* c-c++-common/asan/pr64820.c: Add line number to scanned
pattern.
* c-c++-common/asan/use-after-return-1.c: Likewise.
* g++.dg/asan/function-argument-1.C (main): Likewise.
* g++.dg/asan/function-argument-2.C (main): Likewise.
* g++.dg/asan/function-argument-3.C (main): Likewise.
* g++.dg/asan/use-after-scope-1.C (main): Likewise.
* g++.dg/asan/use-after-scope-2.C (main): Likewise.
* g++.dg/asan/use-after-scope-types-1.C (main): Likewise.
* g++.dg/asan/use-after-scope-types-2.C (main): Likewise.
* g++.dg/asan/use-after-scope-types-3.C (main): Likewise.
* g++.dg/asan/use-after-scope-types-4.C (main): Likewise.
* g++.dg/asan/use-after-scope-types-5.C (main): Likewise.
* gcc.dg/asan/pr78541.c (main): Likewise.
* gcc.dg/asan/use-after-scope-1.c (main): Likewise.
* gcc.dg/asan/use-after-scope-10.c (main): Likewise.
* gcc.dg/asan/use-after-scope-2.c (main): Likewise.
* gcc.dg/asan/use-after-scope-3.c (main): Likewise.
* gcc.dg/asan/use-after-scope-5.c (main): Likewise.
* gcc.dg/asan/use-after-scope-9.c (main): Likewise.

(backported 1db5adee4f01d05f3f1b9c09c04b9b772ace6859 without
  * g++.dg/asan/function-argument-1.C
  * g++.dg/asan/function-argument-2.C
  * g++.dg/asan/function-argument-3.C
  * gcc.dg/asan/pr78541.c
  * gcc.dg/asan/use-after-scope-10.c
test)

Change-Id: I03162f42275c2f3c0b92c6bfb397dbc91229a917
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@264951 138bc75d-0d04-0410-961f-82ee72b054a4

15 files changed:
gcc/asan.c
gcc/testsuite/c-c++-common/asan/pr64820.c
gcc/testsuite/c-c++-common/asan/use-after-return-1.c
gcc/testsuite/g++.dg/asan/use-after-scope-1.C
gcc/testsuite/g++.dg/asan/use-after-scope-2.C
gcc/testsuite/g++.dg/asan/use-after-scope-types-1.C
gcc/testsuite/g++.dg/asan/use-after-scope-types-2.C
gcc/testsuite/g++.dg/asan/use-after-scope-types-3.C
gcc/testsuite/g++.dg/asan/use-after-scope-types-4.C
gcc/testsuite/g++.dg/asan/use-after-scope-types-5.C
gcc/testsuite/gcc.dg/asan/use-after-scope-1.c
gcc/testsuite/gcc.dg/asan/use-after-scope-2.c
gcc/testsuite/gcc.dg/asan/use-after-scope-3.c
gcc/testsuite/gcc.dg/asan/use-after-scope-5.c
gcc/testsuite/gcc.dg/asan/use-after-scope-9.c

index cb5a21f..11c2b52 100644 (file)
@@ -1085,6 +1085,9 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb,
   if (shadow_ptr_types[0] == NULL_TREE)
     asan_init_shadow_ptr_types ();
 
+  expanded_location cfun_xloc
+    = expand_location (DECL_SOURCE_LOCATION (current_function_decl));
+
   /* First of all, prepare the description string.  */
   pretty_printer asan_pp;
 
@@ -1097,15 +1100,30 @@ asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb,
       pp_space (&asan_pp);
       pp_wide_integer (&asan_pp, offsets[l - 1] - offsets[l]);
       pp_space (&asan_pp);
+
+      expanded_location xloc
+       = expand_location (DECL_SOURCE_LOCATION (decl));
+      char location[32];
+
+      if (xloc.file == cfun_xloc.file)
+       sprintf (location, ":%d", xloc.line);
+      else
+       location[0] = '\0';
+
       if (DECL_P (decl) && DECL_NAME (decl))
        {
-         pp_decimal_int (&asan_pp, IDENTIFIER_LENGTH (DECL_NAME (decl)));
+         unsigned idlen
+           = IDENTIFIER_LENGTH (DECL_NAME (decl)) + strlen (location);
+         pp_decimal_int (&asan_pp, idlen);
          pp_space (&asan_pp);
          pp_tree_identifier (&asan_pp, DECL_NAME (decl));
+         pp_string (&asan_pp, location);
        }
       else
        pp_string (&asan_pp, "9 <unknown>");
-      pp_space (&asan_pp);
+
+      if (l > 2)
+       pp_space (&asan_pp);
     }
   str_cst = asan_pp_string (&asan_pp);
 
index c42f608..40cc573 100644 (file)
@@ -28,4 +28,4 @@ int main(int argc, char **argv) {
 /* { dg-output "\[^\n\r]*WRITE of size 1 at .* thread T0.*" } */
 /* { dg-output "    #0.*(Func2)?.*pr64820.(c:21)?.*" } */
 /* { dg-output "is located in stack of thread T0 at offset.*" } */
-/* { dg-output "\'local\'\[^\n\r]*<== Memory access at offset 32 is inside this variable" } */
+/* { dg-output "\'local\'\[^\n\r]* \\(line 14\\) <== Memory access at offset 32 is inside this variable" } */
index 49933e5..e1bb18a 100644 (file)
@@ -50,4 +50,4 @@ int main(int argc, char **argv) {
 /* { dg-output "WRITE of size 1 at .* thread T0.*" } */
 /* { dg-output "    #0.*(Func2)?.*use-after-return-1.(c:31)?.*" } */
 /* { dg-output "is located in stack of thread T0 at offset.*" } */
-/* { dg-output "\'local\' <== Memory access at offset 32 is inside this variable" } */
+/* { dg-output "\'local\' \\(line 24\\) <== Memory access at offset 32 is inside this variable" } */
index fd875ad..4cbc534 100644 (file)
@@ -18,4 +18,4 @@ int main() {
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "READ of size 4 at.*" }
-// { dg-output ".*'v' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'v' \\(line 9\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index 92a4bd1..5d11834 100644 (file)
@@ -37,4 +37,4 @@ int main(int argc, char **argv)
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "READ of size 4 at.*" }
-// { dg-output ".*'x' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'x' \\(line 31\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index bedcfa4..180804c 100644 (file)
@@ -14,4 +14,4 @@ int main()
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "WRITE of size " }
-// { dg-output ".*'x' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'x' \\(line 25\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index 75a01d9..172c5c0 100644 (file)
@@ -14,4 +14,4 @@ int main()
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "WRITE of size " }
-// { dg-output ".*'x' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'x' \\(line 25\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index 3350c69..d4ad0fc 100644 (file)
@@ -14,4 +14,4 @@ int main()
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "WRITE of size " }
-// { dg-output ".*'x' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'x' \\(line 25\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index 44f4d3b..7638107 100644 (file)
@@ -14,4 +14,4 @@ int main()
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "READ of size " }
-// { dg-output ".*'x' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'x' \\(line 25\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index 42abc2a..fe7c57f 100644 (file)
@@ -14,4 +14,4 @@ int main()
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "WRITE of size " }
-// { dg-output ".*'x' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'x' \\(line 25\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index bdbc97b..19a8379 100644 (file)
@@ -15,4 +15,4 @@ main (void)
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "READ of size 1 at.*" }
-// { dg-output ".*'my_char' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'my_char' \\(line 9\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index dedb734..1018581 100644 (file)
@@ -44,4 +44,4 @@ main (void)
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "READ of size 4 at.*" }
-// { dg-output ".*'c' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'c' \\(line 37\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index 9aeed51..838e421 100644 (file)
@@ -17,4 +17,4 @@ main (void)
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "WRITE of size 1 at.*" }
-// { dg-output ".*'my_char' <== Memory access at offset \[0-9\]* overflows this variable.*" }
+// { dg-output ".*'my_char' \\(line 11\\) <== Memory access at offset \[0-9\]* overflows this variable.*" }
index b53712d..1c2fafb 100644 (file)
@@ -24,4 +24,4 @@ main (int argc, char **argv)
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "READ of size 4 at.*" }
-// { dg-output ".*'values' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'values' \\(line 10\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }
index 2e30def..17c724f 100644 (file)
@@ -17,4 +17,4 @@ main (int argc, char **argv)
 
 // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
 // { dg-output "READ of size .*" }
-// { dg-output ".*'a' <== Memory access at offset \[0-9\]* is inside this variable.*" }
+// { dg-output ".*'a' \\(line 12\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }