diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg')
103 files changed, 2316 insertions, 185 deletions
diff --git a/gcc/testsuite/gcc.dg/20021014-1.c b/gcc/testsuite/gcc.dg/20021014-1.c index e43f7b2..ee5d459 100644 --- a/gcc/testsuite/gcc.dg/20021014-1.c +++ b/gcc/testsuite/gcc.dg/20021014-1.c @@ -2,6 +2,7 @@ /* { dg-require-profiling "-p" } */ /* { dg-options "-O2 -p" } */ /* { dg-options "-O2 -p -static" { target hppa*-*-hpux* } } */ +/* { dg-additional-options "-mfentry -fno-pic" { target i?86-*-gnu* x86_64-*-gnu* } } */ /* { dg-error "profiler" "No profiler support" { target xstormy16-*-* } 0 } */ /* { dg-message "" "consider using `-pg' instead of `-p' with gprof(1)" { target *-*-freebsd* } 0 } */ diff --git a/gcc/testsuite/gcc.dg/Warray-parameter-11.c b/gcc/testsuite/gcc.dg/Warray-parameter-11.c index 8ca1b55..e05835c 100644 --- a/gcc/testsuite/gcc.dg/Warray-parameter-11.c +++ b/gcc/testsuite/gcc.dg/Warray-parameter-11.c @@ -9,7 +9,7 @@ typedef __INTPTR_TYPE__ intptr_t; void f0 (double[!copysign (~2, 3)]); void f1 (double[!copysign (~2, 3)]); -void f1 (double[1]); // { dg-warning "-Warray-parameter" } +void f1 (double[1]); // { dg-warning "-Wvla-parameter" } void f2 (int[(int)+1.0]); void f2 (int[(int)+1.1]); @@ -21,4 +21,4 @@ extern struct S *sp; void f3 (int[(intptr_t)((char*)sp->a - (char*)sp)]); void f3 (int[(intptr_t)((char*)&sp->a[0] - (char*)sp)]); -void f3 (int[(intptr_t)((char*)&sp->a[1] - (char*)sp)]); // { dg-warning "-Warray-parameter" } +void f3 (int[(intptr_t)((char*)&sp->a[1] - (char*)sp)]); // { dg-warning "-Wvla-parameter" } diff --git a/gcc/testsuite/gcc.dg/Warray-parameter.c b/gcc/testsuite/gcc.dg/Warray-parameter.c index 6c5195a..31879a8 100644 --- a/gcc/testsuite/gcc.dg/Warray-parameter.c +++ b/gcc/testsuite/gcc.dg/Warray-parameter.c @@ -118,8 +118,7 @@ typedef int IA2[2]; typedef int IA3[3]; // The message should differentiate between the [] form and *. -void f1IAx_A1 (IAx); // { dg-message "previously declared as 'int\\\[]'" "pr?????" { xfail *-*-* } } - // { dg-message "previously declared as 'int *\\\*'" "note" { target *-*-* } .-1 } +void f1IAx_A1 (IAx); // { dg-message "previously declared as 'int\\\[]'" } void f1IAx_A1 (IA1); // { dg-message "argument 1 of type 'int\\\[1]' with mismatched bound" } void f1IA1_A2 (IA1); // { dg-message "previously declared as 'int\\\[1]'" } diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-1-sarif.py b/gcc/testsuite/gcc.dg/analyzer/state-diagram-1-sarif.py index d2967d4..d92af83 100644 --- a/gcc/testsuite/gcc.dg/analyzer/state-diagram-1-sarif.py +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-1-sarif.py @@ -6,7 +6,7 @@ import pytest def sarif(): return sarif_from_env() -def test_xml_state(sarif): +def test_state_graph(sarif): result = get_result_by_index(sarif, 0) assert result['level'] == 'warning' @@ -17,16 +17,49 @@ def test_xml_state(sarif): # Event "(1)": "entry to 'test'" (index == 0) assert events[0]['location']['message']['text'] == "entry to 'test'" - state0 = get_xml_state(events, 0) - memory_regions = state0.find('memory-regions') - assert memory_regions is not None - stack = memory_regions.find('stack') - assert stack is not None - frame = stack.find('stack-frame') - assert frame.get('function') == 'test' + state0 = get_state_graph(events, 0) + + stack = state0['nodes'][0] + assert stack['id'] == 'stack' + assert get_state_node_kind(stack) == 'stack' + + frame = stack['children'][0] + assert frame['id'].startswith('frame-region-') + assert get_state_node_kind(frame) == 'stack-frame' + assert get_state_node_attr(frame, 'function') == 'test' + assert frame['location']['logicalLocations'][0]['fullyQualifiedName'] == 'test' # Final event: assert events[-1]['location']['message']['text'].startswith("use after 'free' of ") - state = get_xml_state(events, -1) - # TODO + state = get_state_graph(events, -1) + + stack = state['nodes'][0] + assert stack['id'] == 'stack' + assert get_state_node_kind(stack) == 'stack' + + frame = stack['children'][0] + assert frame['id'].startswith('frame-region-') + assert get_state_node_kind(frame) == 'stack-frame' + assert get_state_node_attr(frame, 'function') == 'test' + assert frame['location']['logicalLocations'][0]['fullyQualifiedName'] == 'test' + + heap = state['nodes'][1] + assert heap['id'] == 'heap' + assert get_state_node_kind(heap) == 'heap' + + assert len(heap['children']) == 3 + heap_buffer0 = heap['children'][0] + assert heap_buffer0['id'].startswith('heap-allocated-region-') + assert get_state_node_kind(heap_buffer0) == 'dynalloc-buffer' + + globals_ = state['nodes'][2] + assert globals_['id'] == 'globals' + assert get_state_node_kind(globals_) == 'globals' + first = globals_['children'][0] + assert first['id'].startswith('decl-region-') + assert get_state_node_kind(first) == 'variable' + assert get_state_node_name(first) == 'first' + assert get_state_node_type(first) == 'struct node *' + + assert len(state['edges']) == 3 diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-1.c b/gcc/testsuite/gcc.dg/analyzer/state-diagram-1.c index 3d853d2..3b35cfa 100644 --- a/gcc/testsuite/gcc.dg/analyzer/state-diagram-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-1.c @@ -1,4 +1,4 @@ -/* { dg-additional-options "-fdiagnostics-add-output=sarif:xml-state=yes" } */ +/* { dg-additional-options "-fdiagnostics-add-output=sarif:state-graphs=yes" } */ #include "analyzer-decls.h" diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c index 28cf580..b981cf9 100644 --- a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.c @@ -1,4 +1,4 @@ -/* { dg-additional-options "-fdiagnostics-add-output=sarif:xml-state=yes" } */ +/* { dg-additional-options "-fdiagnostics-add-output=sarif:state-graphs=yes" } */ #include "analyzer-decls.h" diff --git a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.py b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.py index 484da96..3a2c6f8 100644 --- a/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.py +++ b/gcc/testsuite/gcc.dg/analyzer/state-diagram-5-sarif.py @@ -1,5 +1,3 @@ -import xml.etree.ElementTree as ET - from sarif import * import pytest @@ -8,7 +6,7 @@ import pytest def sarif(): return sarif_from_env() -def test_nested_types_in_xml_state(sarif): +def test_nested_types_in_state_graph(sarif): result = get_result_by_index(sarif, 0) assert result['level'] == 'note' @@ -16,16 +14,17 @@ def test_nested_types_in_xml_state(sarif): events = result["codeFlows"][0]["threadFlows"][0]['locations'] assert events[0]['location']['message']['text'] == 'here' - state = get_xml_state(events, 0) - - memory_regions = state.find('memory-regions') - assert memory_regions is not None + state = get_state_graph(events, 0) - stack = memory_regions.find('stack') - assert stack is not None + stack = state['nodes'][0] + assert stack['id'] == 'stack' + assert get_state_node_kind(stack) == 'stack' - frame = stack.find('stack-frame') - assert frame.get('function') == 'test' + frame = stack['children'][0] + assert frame['id'].startswith('frame-region-') + assert get_state_node_kind(frame) == 'stack-frame' + assert get_state_node_attr(frame, 'function') == 'test' + assert frame['location']['logicalLocations'][0]['fullyQualifiedName'] == 'test' # We have: # baz_arr[1].m_bars[1].m_foos[2].m_ints[1] = 42; @@ -34,40 +33,57 @@ def test_nested_types_in_xml_state(sarif): # representation to nested elements and fields. # "baz_arr": - baz_arr = frame.find("variable[@name='baz_arr']") - assert baz_arr.get('type') == 'struct baz[2]' + baz_arr = frame['children'][0] + assert get_state_node_kind(baz_arr) == 'variable' + assert get_state_node_type(baz_arr) == 'struct baz[2]' + + assert len(baz_arr['children']) == 2 + + bindings = baz_arr['children'][0] + assert bindings['id'].startswith('concrete-bindings-') + assert get_state_node_kind(bindings) == 'other' + assert get_state_node_value(bindings['children'][0]) == '(int)42' # "baz_arr[1]": - baz_arr_1 = baz_arr.find("element[@index='1']") - assert baz_arr_1.get('type') == 'struct baz' + baz_arr_1 = baz_arr['children'][1] + assert get_state_node_type(baz_arr_1) == 'struct baz' + assert get_state_node_kind(baz_arr_1) == 'element' + assert get_state_node_attr(baz_arr_1, 'index') == '1' - assert baz_arr.find("element[@index='0']") is None + assert len(baz_arr_1['children']) == 1 # "baz_arr[1].m_bars": - baz_arr_1_m_bars = baz_arr_1.find("field[@name='m_bars']") - assert baz_arr_1_m_bars.get('type') == 'struct bar[2]' + baz_arr_1_m_bars = baz_arr_1['children'][0] + assert get_state_node_name(baz_arr_1_m_bars) == 'm_bars' + assert get_state_node_type(baz_arr_1_m_bars) == 'struct bar[2]' # "baz_arr[1].m_bars[1]" - baz_arr_1_m_bars_1 = baz_arr_1_m_bars.find("element[@index='1']") - assert baz_arr_1_m_bars_1.get('type') == 'struct bar' + baz_arr_1_m_bars_1 = baz_arr_1_m_bars['children'][0] + assert get_state_node_type(baz_arr_1_m_bars_1) == 'struct bar' + assert get_state_node_kind(baz_arr_1_m_bars_1) == 'element' + assert get_state_node_attr(baz_arr_1_m_bars_1, 'index') == '1' # "baz_arr[1].m_bars[1].m_foos" - baz_arr_1_m_bars_1_m_foos = baz_arr_1_m_bars_1.find("field[@name='m_foos']") - assert baz_arr_1_m_bars_1_m_foos.get('type') == 'struct foo[3]' + baz_arr_1_m_bars_1_m_foos = baz_arr_1_m_bars_1['children'][0] + assert get_state_node_kind(baz_arr_1_m_bars_1_m_foos) == 'field' + assert get_state_node_name(baz_arr_1_m_bars_1_m_foos) == 'm_foos' + assert get_state_node_type(baz_arr_1_m_bars_1_m_foos) == 'struct foo[3]' # "baz_arr[1].m_bars[1].m_foos[2]" - baz_arr_1_m_bars_1_m_foos_2 = baz_arr_1_m_bars_1_m_foos.find("element[@index='2']") - assert baz_arr_1_m_bars_1_m_foos_2.get('type') == 'struct foo' - + baz_arr_1_m_bars_1_m_foos_2 = baz_arr_1_m_bars_1_m_foos['children'][0] + assert get_state_node_type(baz_arr_1_m_bars_1_m_foos_2) == 'struct foo' + assert get_state_node_kind(baz_arr_1_m_bars_1_m_foos_2) == 'element' + assert get_state_node_attr(baz_arr_1_m_bars_1_m_foos_2, 'index') == '2' + # "baz_arr[1].m_bars[1].m_foos[2].m_ints" - baz_arr_1_m_bars_1_m_foos_2_m_ints = baz_arr_1_m_bars_1_m_foos_2.find('field[@name="m_ints"]') - assert baz_arr_1_m_bars_1_m_foos_2_m_ints.get('type') == 'int[4]' - - # "baz_arr[1].m_bars[1].m_foos[2].m_ints[1]" - baz_arr_1_m_bars_1_m_foos_2_m_ints_1 = baz_arr_1_m_bars_1_m_foos_2_m_ints.find('element[@index="1"]') - assert baz_arr_1_m_bars_1_m_foos_2_m_ints_1.get('type') == 'int' + baz_arr_1_m_bars_1_m_foos_2_m_ints = baz_arr_1_m_bars_1_m_foos_2['children'][0] + assert get_state_node_kind(baz_arr_1_m_bars_1_m_foos_2_m_ints) == 'field' + assert get_state_node_name(baz_arr_1_m_bars_1_m_foos_2_m_ints) == 'm_ints' + assert get_state_node_type(baz_arr_1_m_bars_1_m_foos_2_m_ints) == 'int[4]' - value = baz_arr_1_m_bars_1_m_foos_2_m_ints_1.find('value-of-region') - constant = value.find('constant') - assert constant.get('value') == '42' - assert constant.get('type') == 'int' + # "baz_arr[1].m_bars[1].m_foos[2].m_ints[1]" + baz_arr_1_m_bars_1_m_foos_2_m_ints_1 = baz_arr_1_m_bars_1_m_foos_2_m_ints['children'][0] + assert get_state_node_type(baz_arr_1_m_bars_1_m_foos_2_m_ints_1) == 'int' + assert get_state_node_kind(baz_arr_1_m_bars_1_m_foos_2_m_ints_1) == 'element' + assert get_state_node_attr(baz_arr_1_m_bars_1_m_foos_2_m_ints_1, 'index') == '1' + assert get_state_node_value(baz_arr_1_m_bars_1_m_foos_2_m_ints_1) == '(int)42' diff --git a/gcc/testsuite/gcc.dg/aru-2.c b/gcc/testsuite/gcc.dg/aru-2.c index 054223c..61898de 100644 --- a/gcc/testsuite/gcc.dg/aru-2.c +++ b/gcc/testsuite/gcc.dg/aru-2.c @@ -1,6 +1,7 @@ /* { dg-do run } */ /* { dg-require-profiling "-pg" } */ /* { dg-options "-O2 -pg" } */ +/* { dg-additional-options "-mfentry -fno-pic" { target i?86-*-gnu* x86_64-*-gnu* } } */ static int __attribute__((noinline)) bar (int x) diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-1.c b/gcc/testsuite/gcc.dg/asm-hard-reg-1.c new file mode 100644 index 0000000..6a5a9ad --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-1.c @@ -0,0 +1,85 @@ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* riscv*-*-* s390*-*-* x86_64-*-* } } */ + +#if defined (__aarch64__) +# define GPR "{x4}" +/* { dg-final { scan-assembler-times "foo\tx4" 8 { target { aarch64*-*-* } } } } */ +#elif defined (__arm__) +# define GPR "{r4}" +/* { dg-final { scan-assembler-times "foo\tr4" 8 { target { arm*-*-* } } } } */ +#elif defined (__i386__) +# define GPR "{ecx}" +/* { dg-final { scan-assembler-times "foo\t%cl" 2 { target { i?86-*-* } } } } */ +/* { dg-final { scan-assembler-times "foo\t%cx" 2 { target { i?86-*-* } } } } */ +/* { dg-final { scan-assembler-times "foo\t%ecx" 4 { target { i?86-*-* } } } } */ +#elif defined (__powerpc__) || defined (__POWERPC__) +# define GPR "{r5}" +/* { dg-final { scan-assembler-times "foo\t5" 8 { target { powerpc*-*-* } } } } */ +#elif defined (__riscv) +# define GPR "{t5}" +/* { dg-final { scan-assembler-times "foo\tt5" 8 { target { riscv*-*-* } } } } */ +#elif defined (__s390__) +# define GPR "{r4}" +/* { dg-final { scan-assembler-times "foo\t%r4" 8 { target { s390*-*-* } } } } */ +#elif defined (__x86_64__) +# define GPR "{rcx}" +/* { dg-final { scan-assembler-times "foo\t%cl" 2 { target { x86_64-*-* } } } } */ +/* { dg-final { scan-assembler-times "foo\t%cx" 2 { target { x86_64-*-* } } } } */ +/* { dg-final { scan-assembler-times "foo\t%ecx" 2 { target { x86_64-*-* } } } } */ +/* { dg-final { scan-assembler-times "foo\t%rcx" 2 { target { x86_64-*-* } } } } */ +#endif + +char +test_char (char x) +{ + __asm__ ("foo\t%0" : "+"GPR (x)); + return x; +} + +char +test_char_from_mem (char *x) +{ + __asm__ ("foo\t%0" : "+"GPR (*x)); + return *x; +} + +short +test_short (short x) +{ + __asm__ ("foo\t%0" : "+"GPR (x)); + return x; +} + +short +test_short_from_mem (short *x) +{ + __asm__ ("foo\t%0" : "+"GPR (*x)); + return *x; +} + +int +test_int (int x) +{ + __asm__ ("foo\t%0" : "+"GPR (x)); + return x; +} + +int +test_int_from_mem (int *x) +{ + __asm__ ("foo\t%0" : "+"GPR (*x)); + return *x; +} + +long +test_long (long x) +{ + __asm__ ("foo\t%0" : "+"GPR (x)); + return x; +} + +long +test_long_from_mem (long *x) +{ + __asm__ ("foo\t%0" : "+"GPR (*x)); + return *x; +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-2.c b/gcc/testsuite/gcc.dg/asm-hard-reg-2.c new file mode 100644 index 0000000..7dabf96 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-2.c @@ -0,0 +1,33 @@ +/* { dg-do compile { target aarch64*-*-* powerpc64*-*-* riscv64-*-* s390*-*-* x86_64-*-* } } */ +/* { dg-options "-std=c99" } we need long long */ + +#if defined (__aarch64__) +# define GPR "{x4}" +/* { dg-final { scan-assembler-times "foo\tx4" 2 { target { aarch64*-*-* } } } } */ +#elif defined (__powerpc__) || defined (__POWERPC__) +# define GPR "{r5}" +/* { dg-final { scan-assembler-times "foo\t5" 2 { target { powerpc64*-*-* } } } } */ +#elif defined (__riscv) +# define GPR "{t5}" +/* { dg-final { scan-assembler-times "foo\tt5" 2 { target { riscv64-*-* } } } } */ +#elif defined (__s390__) +# define GPR "{r4}" +/* { dg-final { scan-assembler-times "foo\t%r4" 2 { target { s390*-*-* } } } } */ +#elif defined (__x86_64__) +# define GPR "{rcx}" +/* { dg-final { scan-assembler-times "foo\t%rcx" 2 { target { x86_64-*-* } } } } */ +#endif + +long long +test_longlong (long long x) +{ + __asm__ ("foo\t%0" : "+"GPR (x)); + return x; +} + +long long +test_longlong_from_mem (long long *x) +{ + __asm__ ("foo\t%0" : "+"GPR (*x)); + return *x; +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-3.c b/gcc/testsuite/gcc.dg/asm-hard-reg-3.c new file mode 100644 index 0000000..fa4472a --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-3.c @@ -0,0 +1,25 @@ +/* { dg-do compile { target { { aarch64*-*-* powerpc64*-*-* riscv64-*-* s390*-*-* x86_64-*-* } && int128 } } } */ +/* { dg-options "-O2" } get rid of -ansi since we use __int128 */ + +#if defined (__aarch64__) +# define REG "{x4}" +/* { dg-final { scan-assembler-times "foo\tx4" 1 { target { aarch64*-*-* } } } } */ +#elif defined (__powerpc__) || defined (__POWERPC__) +# define REG "{r5}" +/* { dg-final { scan-assembler-times "foo\t5" 1 { target { powerpc*-*-* } } } } */ +#elif defined (__riscv) +# define REG "{t5}" +/* { dg-final { scan-assembler-times "foo\tt5" 1 { target { riscv*-*-* } } } } */ +#elif defined (__s390__) +# define REG "{r4}" +/* { dg-final { scan-assembler-times "foo\t%r4" 1 { target { s390*-*-* } } } } */ +#elif defined (__x86_64__) +# define REG "{xmm0}" +/* { dg-final { scan-assembler-times "foo\t%xmm0" 1 { target { x86_64-*-* } } } } */ +#endif + +void +test (void) +{ + __asm__ ("foo\t%0" :: REG ((__int128) 42)); +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-4.c b/gcc/testsuite/gcc.dg/asm-hard-reg-4.c new file mode 100644 index 0000000..0134bf0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-4.c @@ -0,0 +1,50 @@ +/* { dg-do compile { target aarch64*-*-* arm*-*-* powerpc*-*-* riscv*-*-* s390*-*-* x86_64-*-* } } */ + +#if defined (__aarch64__) +# define FPR "{d5}" +/* { dg-final { scan-assembler-times "foo\tv5" 4 { target { aarch64*-*-* } } } } */ +#elif defined (__arm__) +# define FPR "{d5}" +/* { dg-additional-options "-march=armv7-a+fp -mfloat-abi=hard" { target arm*-*-* } } */ +/* { dg-final { scan-assembler-times "foo\ts10" 4 { target { arm*-*-* } } } } */ +#elif defined (__powerpc__) || defined (__POWERPC__) +# define FPR "{5}" +/* { dg-final { scan-assembler-times "foo\t5" 4 { target { powerpc*-*-* } } } } */ +#elif defined (__riscv) +# define FPR "{fa5}" +/* { dg-final { scan-assembler-times "foo\tfa5" 4 { target { rsicv*-*-* } } } } */ +#elif defined (__s390__) +# define FPR "{f5}" +/* { dg-final { scan-assembler-times "foo\t%f5" 4 { target { s390*-*-* } } } } */ +#elif defined (__x86_64__) +# define FPR "{xmm5}" +/* { dg-final { scan-assembler-times "foo\t%xmm5" 4 { target { x86_64-*-* } } } } */ +#endif + +float +test_float (float x) +{ + __asm__ ("foo\t%0" : "+"FPR (x)); + return x; +} + +float +test_float_from_mem (float *x) +{ + __asm__ ("foo\t%0" : "+"FPR (*x)); + return *x; +} + +double +test_double (double x) +{ + __asm__ ("foo\t%0" : "+"FPR (x)); + return x; +} + +double +test_double_from_mem (double *x) +{ + __asm__ ("foo\t%0" : "+"FPR (*x)); + return *x; +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-5.c b/gcc/testsuite/gcc.dg/asm-hard-reg-5.c new file mode 100644 index 0000000..a9e25ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-5.c @@ -0,0 +1,36 @@ +/* { dg-do compile { target aarch64*-*-* powerpc64*-*-* riscv64-*-* s390*-*-* x86_64-*-* } } */ + +typedef int V __attribute__ ((vector_size (4 * sizeof (int)))); + +#if defined (__aarch64__) +# define VR "{v20}" +/* { dg-final { scan-assembler-times "foo\tv20" 2 { target { aarch64*-*-* } } } } */ +#elif defined (__powerpc__) || defined (__POWERPC__) +# define VR "{v5}" +/* { dg-final { scan-assembler-times "foo\t5" 2 { target { powerpc64*-*-* } } } } */ +#elif defined (__riscv) +# define VR "{v5}" +/* { dg-additional-options "-march=rv64imv" { target riscv64-*-* } } */ +/* { dg-final { scan-assembler-times "foo\tv5" 2 { target { riscv*-*-* } } } } */ +#elif defined (__s390__) +# define VR "{v5}" +/* { dg-require-effective-target s390_mvx { target s390*-*-* } } */ +/* { dg-final { scan-assembler-times "foo\t%v5" 2 { target s390*-*-* } } } */ +#elif defined (__x86_64__) +# define VR "{xmm9}" +/* { dg-final { scan-assembler-times "foo\t%xmm9" 2 { target { x86_64-*-* } } } } */ +#endif + +V +test (V x) +{ + __asm__ ("foo\t%0" : "+"VR (x)); + return x; +} + +V +test_from_mem (V *x) +{ + __asm__ ("foo\t%0" : "+"VR (*x)); + return *x; +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-6.c b/gcc/testsuite/gcc.dg/asm-hard-reg-6.c new file mode 100644 index 0000000..d9b7fae --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-6.c @@ -0,0 +1,60 @@ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* riscv*-*-* s390*-*-* x86_64-*-* } } */ +/* { dg-options "-O2" } */ + +/* Test multiple alternatives. */ + +#if defined (__aarch64__) +# define GPR1 "{x1}" +# define GPR2 "{x2}" +# define GPR3 "{x3}" +/* { dg-final { scan-assembler-times "foo\tx1,x3" 1 { target { aarch64*-*-* } } } } */ +/* { dg-final { scan-assembler-times "bar\tx2,\\\[x1\\\]" 1 { target { aarch64*-*-* } } } } */ +#elif defined (__arm__) +# define GPR1 "{r1}" +# define GPR2 "{r2}" +# define GPR3 "{r3}" +/* { dg-final { scan-assembler-times "foo\tr1,r3" 1 { target { arm*-*-* } } } } */ +/* { dg-final { scan-assembler-times "bar\tr2,\\\[r1\\\]" 1 { target { arm*-*-* } } } } */ +#elif defined (__i386__) +# define GPR1 "{eax}" +# define GPR2 "{ebx}" +# define GPR3 "{ecx}" +/* { dg-final { scan-assembler-times "foo\t4\\(%esp\\),%ecx" 1 { target { i?86-*-* } } } } */ +/* { dg-final { scan-assembler-times "bar\t%ebx,\\(%eax\\)" 1 { target { i?86-*-* } } } } */ +#elif defined (__powerpc__) || defined (__POWERPC__) +# define GPR1 "{r4}" +# define GPR2 "{r5}" +# define GPR3 "{r6}" +/* { dg-final { scan-assembler-times "foo\t4,6" 1 { target { powerpc*-*-* } } } } */ +/* { dg-final { scan-assembler-times "bar\t5,0\\(4\\)" 1 { target { powerpc*-*-* } } } } */ +#elif defined (__riscv) +# define GPR1 "{t1}" +# define GPR2 "{t2}" +# define GPR3 "{t3}" +/* { dg-final { scan-assembler-times "foo\tt1,t3" 1 { target { riscv*-*-* } } } } */ +/* { dg-final { scan-assembler-times "bar\tt2,0\\(a1\\)" 1 { target { riscv*-*-* } } } } */ +#elif defined (__s390__) +# define GPR1 "{r0}" +# define GPR2 "{r1}" +# define GPR3 "{r2}" +/* { dg-final { scan-assembler-times "foo\t%r0,%r2" 1 { target { s390*-*-* } } } } */ +/* { dg-final { scan-assembler-times "bar\t%r1,0\\(%r3\\)" 1 { target { s390*-*-* } } } } */ +#elif defined (__x86_64__) +# define GPR1 "{eax}" +# define GPR2 "{ebx}" +# define GPR3 "{rcx}" +/* { dg-final { scan-assembler-times "foo\t%eax,%rcx" 1 { target { x86_64-*-* } } } } */ +/* { dg-final { scan-assembler-times "bar\t%ebx,\\(%rsi\\)" 1 { target { x86_64-*-* } } } } */ +#endif + +void +test_reg_reg (int x, long long *y) +{ + __asm__ ("foo\t%0,%1" :: GPR1"m,"GPR2 (x), GPR3",m" (y)); +} + +void +test_reg_mem (int x, long long *y) +{ + __asm__ ("bar\t%0,%1" :: GPR1"m,"GPR2 (x), GPR3",m" (*y)); +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-7.c b/gcc/testsuite/gcc.dg/asm-hard-reg-7.c new file mode 100644 index 0000000..761a6b7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-7.c @@ -0,0 +1,41 @@ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* riscv*-*-* s390*-*-* x86_64-*-* } } */ +/* { dg-options "-O2" } */ + +/* Test multiple alternatives. */ + +#if defined (__aarch64__) +# define GPR "{x1}" +/* { dg-final { scan-assembler-times "foo\tx1,x1" 2 { target { aarch64*-*-* } } } } */ +#elif defined (__arm__) +# define GPR "{r1}" +/* { dg-final { scan-assembler-times "foo\tr1,r1" 2 { target { arm*-*-* } } } } */ +#elif defined (__i386__) +# define GPR "{eax}" +/* { dg-final { scan-assembler-times "foo\t%eax,%eax" 2 { target { i?86-*-* } } } } */ +#elif defined (__powerpc__) || defined (__POWERPC__) +# define GPR "{r4}" +/* { dg-final { scan-assembler-times "foo\t4,4" 2 { target { powerpc*-*-* } } } } */ +#elif defined (__riscv) +# define GPR "{t1}" +/* { dg-final { scan-assembler-times "foo\tt1,t1" 2 { target { riscv*-*-* } } } } */ +#elif defined (__s390__) +# define GPR "{r0}" +/* { dg-final { scan-assembler-times "foo\t%r0,%r0" 2 { target { s390*-*-* } } } } */ +#elif defined (__x86_64__) +# define GPR "{eax}" +/* { dg-final { scan-assembler-times "foo\t%eax,%eax" 2 { target { x86_64-*-* } } } } */ +#endif + +int +test_1 (int x) +{ + __asm__ ("foo\t%0,%0" : "+"GPR (x)); + return x; +} + +int +test_2 (int x, int y) +{ + __asm__ ("foo\t%0,%1" : "="GPR (x) : GPR (y)); + return x; +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-8.c b/gcc/testsuite/gcc.dg/asm-hard-reg-8.c new file mode 100644 index 0000000..cda5e3e --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-8.c @@ -0,0 +1,49 @@ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* riscv*-*-* s390*-*-* x86_64-*-* } } */ + +/* Due to hard register constraints, X must be copied. */ + +#if defined (__aarch64__) +# define GPR1 "{x1}" +# define GPR2 "{x2}" +#elif defined (__arm__) +# define GPR1 "{r1}" +# define GPR2 "{r2}" +#elif defined (__i386__) +# define GPR1 "{eax}" +# define GPR2 "{ebx}" +#elif defined (__powerpc__) || defined (__POWERPC__) +# define GPR1 "{r4}" +# define GPR2 "{r5}" +#elif defined (__riscv) +# define GPR1 "{t1}" +# define GPR2 "{t2}" +#elif defined (__s390__) +# define GPR1 "{r0}" +# define GPR2 "{r1}" +#elif defined (__x86_64__) +# define GPR1 "{eax}" +# define GPR2 "{ebx}" +#endif + +#define TEST(T) \ +int \ +test_##T (T x) \ +{ \ + int out; \ + __asm__ ("foo" : "=r" (out) : GPR1 (x), GPR2 (x)); \ + return out; \ +} + +TEST(char) +TEST(short) +TEST(int) +TEST(long) + +int +test_subreg (long x) +{ + int out; + short subreg_x = x; + __asm__ ("foo" : "=r" (out) : GPR1 (x), GPR2 (subreg_x)); + return out; +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-error-1.c b/gcc/testsuite/gcc.dg/asm-hard-reg-error-1.c new file mode 100644 index 0000000..0d7c2f2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-error-1.c @@ -0,0 +1,83 @@ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* riscv*-*-* s390*-*-* x86_64-*-* } } */ + +#if defined (__aarch64__) +# define GPR1_RAW "x0" +# define GPR2 "{x1}" +# define GPR3 "{x2}" +# define INVALID_GPR_A "{x31}" +#elif defined (__arm__) +# define GPR1_RAW "r0" +# define GPR2 "{r1}" +# define GPR3 "{r2}" +# define INVALID_GPR_A "{r16}" +#elif defined (__i386__) +# define GPR1_RAW "%eax" +# define GPR2 "{%ebx}" +# define GPR3 "{%edx}" +# define INVALID_GPR_A "{%eex}" +#elif defined (__powerpc__) || defined (__POWERPC__) +# define GPR1_RAW "r4" +# define GPR2 "{r5}" +# define GPR3 "{r6}" +# define INVALID_GPR_A "{r33}" +#elif defined (__riscv) +# define GPR1_RAW "t4" +# define GPR2 "{t5}" +# define GPR3 "{t6}" +# define INVALID_GPR_A "{t7}" +#elif defined (__s390__) +# define GPR1_RAW "r4" +# define GPR2 "{r5}" +# define GPR3 "{r6}" +# define INVALID_GPR_A "{r17}" +#elif defined (__x86_64__) +# define GPR1_RAW "rax" +# define GPR2 "{rbx}" +# define GPR3 "{rcx}" +# define INVALID_GPR_A "{rex}" +#endif + +#define GPR1 "{"GPR1_RAW"}" +#define INVALID_GPR_B "{"GPR1_RAW + +struct { int a[128]; } s = {0}; + +void +test (void) +{ + int x, y; + register int gpr1 __asm__ (GPR1_RAW) = 0; + + __asm__ ("" :: "{}" (42)); /* { dg-error "invalid input constraint: \{\}" } */ + __asm__ ("" :: INVALID_GPR_A (42)); /* { dg-error "invalid input constraint" } */ + __asm__ ("" :: INVALID_GPR_B (42)); /* { dg-error "invalid input constraint" } */ + + __asm__ ("" :: GPR1 (s)); /* { dg-error "data type isn't suitable for register .* of operand 0" } */ + + __asm__ ("" :: "r" (gpr1), GPR1 (42)); /* { dg-error "multiple inputs to hard register" } */ + __asm__ ("" :: GPR1 (42), "r" (gpr1)); /* { dg-error "multiple inputs to hard register" } */ + __asm__ ("" :: GPR1 (42), GPR1 (42)); /* { dg-error "multiple inputs to hard register" } */ + __asm__ ("" :: GPR1","GPR2 (42), GPR2","GPR3 (42)); + __asm__ ("" :: GPR1","GPR2 (42), GPR3","GPR2 (42)); /* { dg-error "multiple inputs to hard register" } */ + __asm__ ("" :: GPR1","GPR2 (42), GPR1","GPR3 (42)); /* { dg-error "multiple inputs to hard register" } */ + __asm__ ("" :: GPR1 GPR2 (42), GPR2 (42)); /* { dg-error "multiple inputs to hard register" } */ + __asm__ ("" : "+"GPR1 (x), "="GPR1 (y)); /* { dg-error "multiple outputs to hard register" } */ + __asm__ ("" : "="GPR1 (y) : GPR1 (42), "0" (42)); /* { dg-error "multiple inputs to hard register" } */ + __asm__ ("" : "+"GPR1 (x) : GPR1 (42)); /* { dg-error "multiple inputs to hard register" } */ + + __asm__ ("" : "="GPR1 (gpr1)); + __asm__ ("" : "="GPR2 (gpr1)); /* { dg-error "constraint and register 'asm' for output operand 0 are unsatisfiable" } */ + __asm__ ("" :: GPR2 (gpr1)); /* { dg-error "constraint and register 'asm' for input operand 0 are unsatisfiable" } */ + __asm__ ("" : "="GPR1 (x) : "0" (gpr1)); + __asm__ ("" : "="GPR1 GPR2 (x) : "0" (gpr1)); /* { dg-error "constraint and register 'asm' for input operand 0 are unsatisfiable" } */ + + __asm__ ("" : "=&"GPR1 (x) : "0" (gpr1)); + __asm__ ("" : "=&"GPR1 (x) : "0" (42)); + __asm__ ("" : "=&"GPR2","GPR1 (x) : "r,"GPR1 (42)); + __asm__ ("" : "="GPR2",&"GPR1 (x) : "r,"GPR1 (42)); /* { dg-error "invalid hard register usage between earlyclobber operand and input operand" } */ + __asm__ ("" : "=&"GPR1 (x) : GPR1 (42)); /* { dg-error "invalid hard register usage between earlyclobber operand and input operand" } */ + __asm__ ("" : "=&"GPR2","GPR1 (x) : "r,r" (gpr1)); + __asm__ ("" : "="GPR2",&"GPR1 (x) : "r,r" (gpr1)); /* { dg-error "invalid hard register usage between earlyclobber operand and input operand" } */ + __asm__ ("" : "=&r" (gpr1) : GPR1 (42)); /* { dg-error "invalid hard register usage between earlyclobber operand and input operand" } */ + __asm__ ("" : "=&"GPR1 (x), "=r" (y) : "1" (gpr1)); /* { dg-error "invalid hard register usage between earlyclobber operand and input operand" } */ +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-error-2.c b/gcc/testsuite/gcc.dg/asm-hard-reg-error-2.c new file mode 100644 index 0000000..d0d5cfe --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-error-2.c @@ -0,0 +1,26 @@ +/* { dg-do compile { target { { aarch64*-*-* s390x-*-* } && int128 } } } */ +/* { dg-options "-O2" } get rid of -ansi since we use __int128 */ + +/* Test register pairs. */ + +#if defined (__aarch64__) +# define GPR1 "{x4}" +# define GPR2_RAW "x5" +#elif defined (__s390__) +# define GPR1 "{r4}" +# define GPR2_RAW "r5" +#endif + +#define GPR2 "{"GPR2_RAW"}" + +void +test (void) +{ + __asm__ ("" :: GPR1 ((__int128) 42)); + __asm__ ("" :: GPR2 ((__int128) 42)); /* { dg-error "register .* for operand 0 isn't suitable for data type" } */ + __asm__ ("" :: GPR1 ((__int128) 42), GPR2 (42)); /* { dg-error "multiple inputs to hard register" } */ + + __int128 x; + __asm__ ("" : "="GPR1 (x) :: GPR2_RAW); /* { dg-error "hard register constraint for output 0 conflicts with 'asm' clobber list" } */ + __asm__ ("" : "=r" (x) : GPR1 (x) : GPR2_RAW); /* { dg-error "hard register constraint for input 0 conflicts with 'asm' clobber list" } */ +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-error-3.c b/gcc/testsuite/gcc.dg/asm-hard-reg-error-3.c new file mode 100644 index 0000000..17b2317 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-error-3.c @@ -0,0 +1,27 @@ +/* { dg-do compile { target arm-*-* s390-*-* } } */ +/* { dg-options "-std=c99" } we need long long */ +/* { dg-additional-options "-march=armv7-a" { target arm-*-* } } */ + +/* Test register pairs. */ + +#if defined (__arm__) +# define GPR1 "{r4}" +# define GPR2_RAW "r5" +#elif defined (__s390__) +# define GPR1 "{r4}" +# define GPR2_RAW "r5" +#endif + +#define GPR2 "{"GPR2_RAW"}" + +void +test (void) +{ + __asm__ ("" :: GPR1 (42ll)); + __asm__ ("" :: GPR2 (42ll)); /* { dg-error "register .* for operand 0 isn't suitable for data type" } */ + __asm__ ("" :: GPR1 (42ll), GPR2 (42)); /* { dg-error "multiple inputs to hard register" } */ + + long long x; + __asm__ ("" : "="GPR1 (x) :: GPR2_RAW); /* { dg-error "hard register constraint for output 0 conflicts with 'asm' clobber list" } */ + __asm__ ("" : "=r" (x) : GPR1 (x) : GPR2_RAW); /* { dg-error "hard register constraint for input 0 conflicts with 'asm' clobber list" } */ +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-error-4.c b/gcc/testsuite/gcc.dg/asm-hard-reg-error-4.c new file mode 100644 index 0000000..465f24b --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-error-4.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +/* Verify output operands. */ + +int +test (void) +{ + int x; + register int y __asm__ ("0"); + + /* Preserve status quo and don't error out. */ + __asm__ ("" : "=r" (x), "=r" (x)); + + /* Be more strict for hard register constraints and error out. */ + __asm__ ("" : "={0}" (x), "={1}" (x)); /* { dg-error "multiple outputs to lvalue 'x'" } */ + + /* Still error out in case of a mixture. */ + __asm__ ("" : "=r" (x), "={1}" (x)); /* { dg-error "multiple outputs to lvalue 'x'" } */ + + return x + y; +} diff --git a/gcc/testsuite/gcc.dg/asm-hard-reg-error-5.c b/gcc/testsuite/gcc.dg/asm-hard-reg-error-5.c new file mode 100644 index 0000000..85398f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-hard-reg-error-5.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +/* Test clobbers. + See asm-hard-reg-error-{2,3}.c for tests involving register pairs. */ + +int +test (void) +{ + int x, y; + __asm__ ("" : "={0}" (x), "={1}" (y) : : "1"); /* { dg-error "hard register constraint for output 1 conflicts with 'asm' clobber list" } */ + __asm__ ("" : "={0}" (x) : "{0}" (y), "{1}" (y) : "1"); /* { dg-error "hard register constraint for input 1 conflicts with 'asm' clobber list" } */ + return x + y; +} diff --git a/gcc/testsuite/gcc.dg/bitint-124.c b/gcc/testsuite/gcc.dg/bitint-124.c new file mode 100644 index 0000000..160a1e3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-124.c @@ -0,0 +1,30 @@ +/* PR tree-optimization/121131 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-O2" } */ + +#if __BITINT_MAXWIDTH__ >= 156 +struct A { _BitInt(156) b : 135; }; + +static inline _BitInt(156) +foo (struct A *x) +{ + return x[1].b; +} + +__attribute__((noipa)) _BitInt(156) +bar (void) +{ + struct A a[] = { 1, 1, -13055525270329736316393717310914023773847wb, + 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + return foo (&a[1]); +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 156 + if (bar () != -13055525270329736316393717310914023773847wb) + __builtin_abort (); +#endif +} diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-link.c b/gcc/testsuite/gcc.dg/darwin-minversion-link.c index af712a1b..55f7c7e 100644 --- a/gcc/testsuite/gcc.dg/darwin-minversion-link.c +++ b/gcc/testsuite/gcc.dg/darwin-minversion-link.c @@ -20,6 +20,7 @@ /* { dg-additional-options "-mmacosx-version-min=013.000.00 -DCHECK=130000" { target *-*-darwin22* } } */ /* { dg-additional-options "-mmacosx-version-min=014.000.00 -DCHECK=140000" { target *-*-darwin23* } } */ /* { dg-additional-options "-mmacosx-version-min=015.000.00 -DCHECK=150000" { target *-*-darwin24* } } */ +/* { dg-additional-options "-mmacosx-version-min=026.000.00 -DCHECK=260000" { target *-*-darwin25* } } */ int main () diff --git a/gcc/testsuite/gcc.dg/memchr-3.c b/gcc/testsuite/gcc.dg/memchr-3.c index 9a35735..9caa2ac 100644 --- a/gcc/testsuite/gcc.dg/memchr-3.c +++ b/gcc/testsuite/gcc.dg/memchr-3.c @@ -17,9 +17,10 @@ struct SX const struct SX sx = { 0x1221 }; const char sx_rep[] = { }; -void test_find (void) +int test_find (void) { int n = 0, nb = (const char*)&sx.a - (const char*)&sx; const char *p = (const char*)&sx, *q = sx_rep; n += p + 1 == memchr (p, q[1], nb); + return n; } diff --git a/gcc/testsuite/gcc.dg/nest.c b/gcc/testsuite/gcc.dg/nest.c index 5734c11..2dce65e 100644 --- a/gcc/testsuite/gcc.dg/nest.c +++ b/gcc/testsuite/gcc.dg/nest.c @@ -3,6 +3,7 @@ /* { dg-require-profiling "-pg" } */ /* { dg-options "-O2 -pg" } */ /* { dg-options "-O2 -pg -static" { target hppa*-*-hpux* } } */ +/* { dg-additional-options "-mfentry -fno-pic" { target i?86-*-gnu* x86_64-*-gnu* } } */ /* { dg-error "profiler" "No profiler support" { target xstormy16-*-* } 0 } */ extern void abort (void); diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc b/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc index 1fe5b5c..01ab766 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc @@ -23,8 +23,8 @@ #include "target.h" #include "fold-const.h" #include "tree-pretty-print.h" -#include "diagnostic-color.h" -#include "diagnostic-metadata.h" +#include "diagnostics/color.h" +#include "diagnostics/metadata.h" #include "tristate.h" #include "bitmap.h" #include "selftest.h" diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.cc b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.cc index fa2f2fa..c101c45 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.cc @@ -16,7 +16,7 @@ #include "gimple.h" #include "gimple-iterator.h" #include "gimple-walk.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "analyzer/common.h" #include "analyzer/analyzer-logging.h" #include "json.h" @@ -120,20 +120,22 @@ public: return false; } - diagnostic_event::meaning + diagnostics::paths::event::meaning get_meaning_for_state_change (const evdesc::state_change &change) const final override { + using event = diagnostics::paths::event; + if (change.is_global_p ()) { if (change.m_new_state == m_sm.m_released_gil) - return diagnostic_event::meaning (diagnostic_event::verb::release, - diagnostic_event::noun::lock); + return event::meaning (event::verb::release, + event::noun::lock); else if (change.m_new_state == m_sm.get_start_state ()) - return diagnostic_event::meaning (diagnostic_event::verb::acquire, - diagnostic_event::noun::lock); + return event::meaning (event::verb::acquire, + event::noun::lock); } - return diagnostic_event::meaning (); + return event::meaning (); } protected: gil_diagnostic (const gil_state_machine &sm) : m_sm (sm) diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.cc b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.cc index 18e054b..fc282a7 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.cc @@ -23,8 +23,8 @@ #include "target.h" #include "fold-const.h" #include "tree-pretty-print.h" -#include "diagnostic-color.h" -#include "diagnostic-metadata.h" +#include "diagnostics/color.h" +#include "diagnostics/metadata.h" #include "tristate.h" #include "bitmap.h" #include "selftest.h" diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.cc b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.cc index 5a6e075..44fcf37 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.cc @@ -23,8 +23,8 @@ #include "target.h" #include "fold-const.h" #include "tree-pretty-print.h" -#include "diagnostic-color.h" -#include "diagnostic-metadata.h" +#include "diagnostics/color.h" +#include "diagnostics/metadata.h" #include "tristate.h" #include "bitmap.h" #include "selftest.h" diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.c new file mode 100644 index 0000000..2256a63 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-fdiagnostics-add-output=experimental-html:javascript=no" } */ + +extern void here (void); + +void test_graphs (void) +{ + here (); /* { dg-error "this is a placeholder error, with graphs" } */ +} + +/* Use a Python script to verify various properties about the generated + HTML file: + { dg-final { run-html-pytest diagnostic-test-graphs-html.c "diagnostic-test-graphs-html.py" } } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.py new file mode 100644 index 0000000..11e5fd1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.py @@ -0,0 +1,48 @@ +# Verify that metadata works in HTML output. + +from htmltest import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def html_tree(): + return html_tree_from_env() + +def test_result_graph(html_tree): + root = html_tree.getroot () + assert root.tag == make_tag('html') + + body = root.find('xhtml:body', ns) + assert body is not None + + diag_list = body.find('xhtml:div', ns) + assert diag_list is not None + assert diag_list.attrib['class'] == 'gcc-diagnostic-list' + + diag = diag_list.find('xhtml:div', ns) + assert diag is not None + + message = diag.find("./xhtml:div[@class='gcc-message']", ns) + assert message.attrib['id'] == 'gcc-diag-0-message' + + assert message[0].tag == make_tag('strong') + assert message[0].tail == ' this is a placeholder error, with graphs ' + + graph = diag.find("./xhtml:div[@class='gcc-directed-graph']", ns) + assert graph is not None + + header = graph.find("./xhtml:h2", ns) + assert header.text == 'foo' + +def test_run_graph(html_tree): + root = html_tree.getroot () + assert root.tag == make_tag('html') + + body = root.find('xhtml:body', ns) + assert body is not None + + graph = body.find("./xhtml:div[@class='gcc-directed-graph']", ns) + assert graph is not None + + header = graph.find("./xhtml:h2", ns) + assert header.text == 'Optimization Passes' diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c new file mode 100644 index 0000000..4170f51 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fdiagnostics-add-output=sarif" } */ + +extern void here (void); + +void test_graphs (void) +{ + here (); /* { dg-error "this is a placeholder error, with graphs" } */ +} + +/* Verify that some JSON was written to a file with the expected name. */ +/* { dg-final { verify-sarif-file } } */ + +/* Use a Python script to verify various properties about the generated + .sarif file: + { dg-final { run-sarif-pytest diagnostic-test-graphs-sarif.c "diagnostic-test-graphs-sarif.py" } } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py new file mode 100644 index 0000000..4bb7535 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py @@ -0,0 +1,55 @@ +from sarif import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def sarif(): + return sarif_from_env() + +def test_basics(sarif): + schema = sarif['$schema'] + assert schema == "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" + + version = sarif['version'] + assert version == "2.1.0" + +def test_result_graph(sarif): + runs = sarif['runs'] + run = runs[0] + results = run['results'] + + assert len(results) == 1 + + result = results[0] + assert result['level'] == 'error' + assert result['message']['text'] == "this is a placeholder error, with graphs" + + assert len(result['graphs']) == 2 + + assert result['graphs'][0]['description']['text'] == 'foo' + + assert len(result['graphs'][0]['nodes']) == 2 + assert result['graphs'][0]['nodes'][0]['id'] == 'a' + assert result['graphs'][0]['nodes'][1]['id'] == 'b' + assert result['graphs'][0]['nodes'][1]['properties']['/placeholder-prefix/color'] == 'red' + assert len(result['graphs'][0]['nodes'][1]['children']) == 1 + assert result['graphs'][0]['nodes'][1]['children'][0]['id'] == 'c' + assert result['graphs'][0]['nodes'][1]['children'][0]['label']['text'] == 'I am a node label' + + assert len(result['graphs'][0]['edges']) == 1 + result['graphs'][0]['edges'][0]['id'] == 'my-edge' + assert result['graphs'][0]['edges'][0]['label']['text'] == 'I am an edge label' + assert result['graphs'][0]['edges'][0]['sourceNodeId'] == 'a' + assert result['graphs'][0]['edges'][0]['targetNodeId'] == 'c' + + assert result['graphs'][1]['description']['text'] == 'bar' + +def test_run_graph(sarif): + runs = sarif['runs'] + run = runs[0] + + assert len(run['graphs']) == 1 + + assert run['graphs'][0]['description']['text'] == 'Optimization Passes' + assert run['graphs'][0]['nodes'][0]['id'] == 'all_lowering_passes' + assert run['graphs'][0]['edges'][0]['id'] == 'edge0' diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs.c new file mode 100644 index 0000000..7973954 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ + +extern void here (void); + +void test_graphs (void) +{ + here (); /* { dg-error "this is a placeholder error, with graphs" } */ +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py index aca1b6c..eaca35a 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py @@ -1,4 +1,4 @@ -# Verify that diagnostic-show-locus.cc works with HTML output. +# Verify that diagnostics/source-printing.cc works with HTML output. from htmltest import * diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc index 4ade232..48f8325 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc @@ -27,7 +27,7 @@ #include "plugin-version.h" #include "c-family/c-common.h" #include "diagnostic.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #include "context.h" int plugin_is_GPL_compatible; @@ -165,8 +165,8 @@ pass_test_groups::execute (function *fun) expected output. */ void -test_diagnostic_text_starter (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic) +test_diagnostic_text_starter (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diagnostic) { pp_set_prefix (text_output.get_printer (), xstrdup ("PREFIX: ")); } @@ -175,22 +175,22 @@ test_diagnostic_text_starter (diagnostic_text_output_format &text_output, expected output. */ void -test_diagnostic_start_span_fn (const diagnostic_location_print_policy &, - to_text &sink, +test_diagnostic_start_span_fn (const diagnostics::location_print_policy &, + diagnostics::to_text &sink, expanded_location) { - pretty_printer *pp = get_printer (sink); + pretty_printer *pp = diagnostics::get_printer (sink); pp_string (pp, "START_SPAN_FN: "); pp_newline (pp); } -/* Custom output format subclass. */ +/* Custom text_sink subclass. */ -class test_output_format : public diagnostic_text_output_format +class custom_test_sink : public diagnostics::text_sink { public: - test_output_format (diagnostic_context &context) - : diagnostic_text_output_format (context) + custom_test_sink (diagnostics::context &context) + : diagnostics::text_sink (context) {} void on_begin_group () final override @@ -228,10 +228,9 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - diagnostic_text_starter (global_dc) = test_diagnostic_text_starter; - diagnostic_start_span (global_dc) = test_diagnostic_start_span_fn; - global_dc->set_output_format - (::std::make_unique<test_output_format> (*global_dc)); + diagnostics::text_starter (global_dc) = test_diagnostic_text_starter; + diagnostics::start_span (global_dc) = test_diagnostic_start_span_fn; + global_dc->set_sink (::std::make_unique<custom_test_sink> (*global_dc)); pass_info.pass = new pass_test_groups (g); pass_info.reference_pass_name = "*warn_function_noreturn"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.cc index 44b94da..7e34a42 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.cc @@ -115,7 +115,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 80; + global_dc->get_source_printing_options ().max_width = 80; register_callback (plugin_name, PLUGIN_PRE_GENERICIZE, diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_graphs.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_graphs.cc new file mode 100644 index 0000000..7398a29 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_graphs.cc @@ -0,0 +1,283 @@ +/* This plugin exercises diagnostic graphs. + We emit an error with a pair of digraphs associated with it, + and a global digraph showing the optimization passes. */ + +#define INCLUDE_MAP +#define INCLUDE_STRING +#define INCLUDE_VECTOR +#include "gcc-plugin.h" +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "tree.h" +#include "stringpool.h" +#include "toplev.h" +#include "basic-block.h" +#include "hash-table.h" +#include "vec.h" +#include "ggc.h" +#include "basic-block.h" +#include "tree-ssa-alias.h" +#include "internal-fn.h" +#include "gimple.h" +#include "gimple-iterator.h" +#include "gimple-fold.h" +#include "tree-eh.h" +#include "gimple-expr.h" +#include "is-a.h" +#include "tree.h" +#include "tree-pass.h" +#include "intl.h" +#include "plugin-version.h" +#include "diagnostic.h" +#include "context.h" +#include "gcc-rich-location.h" +#include "diagnostics/metadata.h" +#include "diagnostics/digraphs.h" +#include "pass_manager.h" + + +int plugin_is_GPL_compatible; + +const pass_data pass_data_test_graph_emission = +{ + GIMPLE_PASS, /* type */ + "test_graph_emission", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_NONE, /* tv_id */ + PROP_ssa, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_test_graph_emission : public gimple_opt_pass +{ +public: + pass_test_graph_emission(gcc::context *ctxt) + : gimple_opt_pass(pass_data_test_graph_emission, ctxt) + {} + + /* opt_pass methods: */ + bool gate (function *) { return true; } + virtual unsigned int execute (function *); + +}; // class pass_test_graph_emission + +/* Determine if STMT is a call with NUM_ARGS arguments to a function + named FUNCNAME. + If so, return STMT as a gcall *. Otherwise return NULL. */ + +static gcall * +check_for_named_call (gimple *stmt, + const char *funcname, unsigned int num_args) +{ + gcc_assert (funcname); + + gcall *call = dyn_cast <gcall *> (stmt); + if (!call) + return NULL; + + tree fndecl = gimple_call_fndecl (call); + if (!fndecl) + return NULL; + + if (strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), funcname)) + return NULL; + + if (gimple_call_num_args (call) != num_args) + { + error_at (stmt->location, "expected number of args: %i (got %i)", + num_args, gimple_call_num_args (call)); + return NULL; + } + + return call; +} + +class lazy_passes_graph : public lazily_created<diagnostics::digraphs::digraph> +{ +public: + lazy_passes_graph (const ::gcc::pass_manager &pass_manager_) + : m_pass_manager (pass_manager_) + { + } + +private: + std::unique_ptr<diagnostics::digraphs::digraph> + create_object () const final override + { + auto g = std::make_unique<diagnostics::digraphs::digraph> (); + g->set_description ("Optimization Passes"); + +#define DEF_PASS_LIST(NAME) \ + add_top_level_pass_list (*g, #NAME, m_pass_manager.NAME); + + GCC_PASS_LISTS + +#undef DEF_PASS_LIST + + return g; + } + + void + add_top_level_pass_list (diagnostics::digraphs::digraph &g, + const char *pass_list_name, + const opt_pass *p) const + { + gcc_assert (p); + auto n = std::make_unique<diagnostics::digraphs::node> (g, pass_list_name); + n->set_label (pass_list_name); + add_child_pass (g, *n, *p); + g.add_node (std::move (n)); + } + + diagnostics::digraphs::node & + add_child_pass (diagnostics::digraphs::digraph &g, + diagnostics::digraphs::node &parent_node, + const opt_pass &p) const + { + std::string node_label; + std::string node_id; + if (p.static_pass_number > 0 ) + { + node_label = std::to_string (p.static_pass_number) + "_" + p.name; + node_id = node_label; + } + else + { + node_label = std::string (p.name); + pretty_printer pp; + pp_printf (&pp, "%s_%p", p.name, &p); + node_id = pp_formatted_text (&pp); + } + auto n + = std::make_unique<diagnostics::digraphs::node> (g, + std::move (node_id)); + n->set_label (node_label.c_str ()); + diagnostics::digraphs::node &result = *n; + parent_node.add_child (std::move (n)); + + // TODO: add attrs for things like type, properties_*, etc + + if (p.sub) + { + auto &other_node = add_child_pass (g, parent_node, *p.sub); + g.add_edge (nullptr, result, other_node, "sub"); + } + + if (p.next) + { + auto &other_node = add_child_pass (g, parent_node, *p.next); + g.add_edge (nullptr, result, other_node, "next"); + } + + return result; + } + + const ::gcc::pass_manager &m_pass_manager; +}; + +static void +report_diag_with_graphs (location_t loc) +{ + class my_lazy_digraphs : public diagnostics::metadata::lazy_digraphs + { + public: + using diagnostic_graph = diagnostics::digraphs::digraph; + using diagnostic_node = diagnostics::digraphs::node; + using diagnostic_edge = diagnostics::digraphs::edge; + + std::unique_ptr<std::vector<std::unique_ptr<diagnostic_graph>>> + create_object () const final override + { + auto graphs + = std::make_unique<std::vector<std::unique_ptr<diagnostic_graph>>> (); + + graphs->push_back (make_test_graph ("foo")); + graphs->push_back (make_test_graph ("bar")); + + return graphs; + } + + private: + std::unique_ptr<diagnostic_graph> + make_test_graph (const char *desc) const + { + auto g = std::make_unique<diagnostic_graph> (); + g->set_description (desc); + auto a = std::make_unique<diagnostic_node> (*g, "a"); + auto b = std::make_unique<diagnostic_node> (*g, "b"); +#define KEY_PREFIX "/placeholder-prefix/" + b->set_attr (KEY_PREFIX, "color", "red"); +#undef KEY_PREFIX + auto c = std::make_unique<diagnostic_node> (*g, "c"); + c->set_label ("I am a node label"); + + auto e = std::make_unique<diagnostic_edge> (*g, "my-edge", *a, *c); + e->set_label ("I am an edge label"); + g->add_edge (std::move (e)); + + g->add_node (std::move (a)); + + b->add_child (std::move (c)); + g->add_node (std::move (b)); + + return g; + } + }; + + gcc_rich_location rich_loc (loc); + diagnostics::metadata meta; + my_lazy_digraphs ldg; + meta.set_lazy_digraphs (&ldg); + error_meta (&rich_loc, meta, + "this is a placeholder error, with graphs"); +} + +/* Exercise diagnostic graph emission. */ + +unsigned int +pass_test_graph_emission::execute (function *fun) +{ + gimple_stmt_iterator gsi; + basic_block bb; + + FOR_EACH_BB_FN (bb, fun) + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + + if (gcall *call = check_for_named_call (stmt, "here", 0)) + report_diag_with_graphs (gimple_location (call)); + } + + return 0; +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + struct register_pass_info pass_info; + const char *plugin_name = plugin_info->base_name; + int argc = plugin_info->argc; + struct plugin_argument *argv = plugin_info->argv; + + if (!plugin_default_version_check (version, &gcc_version)) + return 1; + + pass_info.pass = new pass_test_graph_emission (g); + pass_info.reference_pass_name = "ssa"; + pass_info.ref_pass_instance_number = 1; + pass_info.pos_op = PASS_POS_INSERT_AFTER; + register_callback (plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, + &pass_info); + + gcc_assert (::g->get_passes ()); + global_dc->report_global_digraph (lazy_passes_graph (*::g->get_passes ())); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.cc index 7edce1f..d38538d 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.cc @@ -169,7 +169,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 80; + global_dc->get_source_printing_options ().max_width = 80; pass_info.pass = new pass_test_inlining (g); pass_info.reference_pass_name = "*warn_function_noreturn"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_metadata.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_metadata.cc index b86a8b3..f172258 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_metadata.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_metadata.cc @@ -1,5 +1,6 @@ -/* This plugin exercises diagnostic_metadata. */ +/* This plugin exercises diagnostics::metadata. */ +#define INCLUDE_VECTOR #include "gcc-plugin.h" #include "config.h" #include "system.h" @@ -28,7 +29,7 @@ #include "diagnostic.h" #include "context.h" #include "gcc-rich-location.h" -#include "diagnostic-metadata.h" +#include "diagnostics/metadata.h" int plugin_is_GPL_compatible; @@ -89,7 +90,7 @@ check_for_named_call (gimple *stmt, return call; } -/* Exercise diagnostic_metadata. */ +/* Exercise diagnostics::metadata. */ unsigned int pass_test_metadata::execute (function *fun) @@ -106,13 +107,13 @@ pass_test_metadata::execute (function *fun) if (gcall *call = check_for_named_call (stmt, "gets", 1)) { gcc_rich_location richloc (gimple_location (call)); - diagnostic_metadata m; + diagnostics::metadata m; /* CWE-242: Use of Inherently Dangerous Function. */ m.add_cwe (242); - /* Example of a diagnostic_metadata::rule. */ - diagnostic_metadata::precanned_rule + /* Example of a diagnostics::metadata::rule. */ + diagnostics::metadata::precanned_rule test_rule ("STR34-C", "https://example.com/"); m.add_rule (test_rule); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc index a7963fa..875f4a8 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc @@ -6,6 +6,7 @@ specific tests within the compiler's IR. We can't use any real diagnostics for this, so we have to fake it, hence this plugin. */ +#define INCLUDE_VECTOR #include "gcc-plugin.h" #include "config.h" #include "system.h" @@ -32,8 +33,7 @@ #include "intl.h" #include "plugin-version.h" #include "diagnostic.h" -#include "diagnostic-path.h" -#include "diagnostic-metadata.h" +#include "diagnostics/metadata.h" #include "context.h" #include "print-tree.h" #include "gcc-rich-location.h" @@ -223,7 +223,7 @@ class test_diagnostic_path : public simple_diagnostic_path diagnostic_event_id_t add_event_2 (event_location_t evloc, int stack_depth, const char *desc, - diagnostic_thread_id_t thread_id = 0) + diagnostics::paths::thread_id_t thread_id = 0) { gcc_assert (evloc.m_fun); return add_thread_event (thread_id, evloc.m_loc, evloc.m_fun->decl, @@ -232,7 +232,7 @@ class test_diagnostic_path : public simple_diagnostic_path diagnostic_event_id_t add_event_2_with_event_id (event_location_t evloc, int stack_depth, const char *fmt, - diagnostic_thread_id_t thread_id, + diagnostics::paths::thread_id_t thread_id, diagnostic_event_id_t event_id) { gcc_assert (evloc.m_fun); @@ -242,7 +242,7 @@ class test_diagnostic_path : public simple_diagnostic_path } void add_entry (event_location_t evloc, int stack_depth, const char *funcname, - diagnostic_thread_id_t thread_id = 0) + diagnostics::paths::thread_id_t thread_id = 0) { gcc_assert (evloc.m_fun); add_thread_event (thread_id, evloc.m_loc, evloc.m_fun->decl, stack_depth, @@ -363,7 +363,7 @@ example_2 () richloc.set_path (&path); - diagnostic_metadata m; + diagnostics::metadata m; m.add_cwe (415); /* CWE-415: Double Free. */ warning_meta (&richloc, m, 0, @@ -441,7 +441,7 @@ example_3 () richloc.set_path (&path); - diagnostic_metadata m; + diagnostics::metadata m; /* CWE-479: Signal Handler Use of a Non-reentrant Function. */ m.add_cwe (479); @@ -502,8 +502,8 @@ example_4 () gcc_rich_location richloc (call_to_acquire_lock_a_in_bar.m_loc); test_diagnostic_path path (global_dc->get_reference_printer ()); - diagnostic_thread_id_t thread_1 = path.add_thread ("Thread 1"); - diagnostic_thread_id_t thread_2 = path.add_thread ("Thread 2"); + diagnostics::paths::thread_id_t thread_1 = path.add_thread ("Thread 1"); + diagnostics::paths::thread_id_t thread_2 = path.add_thread ("Thread 2"); path.add_entry (entry_to_foo, 0, "foo", thread_1); diagnostic_event_id_t event_a_acquired = path.add_event_2 (call_to_acquire_lock_a_in_foo, 1, @@ -524,7 +524,7 @@ example_4 () thread_2, event_a_acquired); richloc.set_path (&path); - diagnostic_metadata m; + diagnostics::metadata m; warning_meta (&richloc, m, 0, "deadlock due to inconsistent lock acquisition order"); } @@ -559,7 +559,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 80; + global_dc->get_source_printing_options ().max_width = 80; pass_info.pass = make_pass_test_show_path (g); pass_info.reference_pass_name = "whole-program"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc index cd3834b..92839cd 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc @@ -62,7 +62,8 @@ #include "print-tree.h" #include "gcc-rich-location.h" #include "text-range-label.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" +#include "diagnostics/file-cache.h" int plugin_is_GPL_compatible; @@ -125,14 +126,14 @@ static bool force_show_locus_color = false; /* We want to verify the colorized output of diagnostic_show_locus, but turning on colorization for everything confuses "dg-warning" etc. Hence we special-case it within this plugin by using this modified - version of default_diagnostic_text_finalizer, which, if "color" is + version of diagnostics::default_text_finalizer, which, if "color" is passed in as a plugin argument turns on colorization, but just for diagnostic_show_locus. */ static void -custom_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic, - diagnostic_t) +custom_diagnostic_text_finalizer (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diag, + enum diagnostics::kind) { pretty_printer *const pp = text_output.get_printer (); bool old_show_color = pp_show_color (pp); @@ -143,7 +144,7 @@ custom_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, pp_newline (pp); diagnostic_show_locus (&text_output.get_context (), text_output.get_source_printing_options (), - diagnostic->richloc, diagnostic->kind, pp); + diag->m_richloc, diag->m_kind, pp); pp_show_color (pp) = old_show_color; pp_set_prefix (pp, saved_prefix); pp_flush (pp); @@ -176,11 +177,11 @@ test_show_locus (function *fun) location_t fnstart = fun->function_start_locus; int fnstart_line = LOCATION_LINE (fnstart); - diagnostic_text_finalizer (global_dc) = custom_diagnostic_text_finalizer; + diagnostics::text_finalizer (global_dc) = custom_diagnostic_text_finalizer; /* Hardcode the "terminal width", to verify the behavior of very wide lines. */ - global_dc->m_source_printing.max_width = 71; + global_dc->get_source_printing_options ().max_width = 71; if (0 == strcmp (fnname, "test_simple")) { @@ -251,7 +252,7 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_very_wide_line")) { const int line = fnstart_line + 2; - global_dc->m_source_printing.show_ruler_p = true; + global_dc->get_source_printing_options ().show_ruler_p = true; text_range_label label0 ("label 0"); text_range_label label1 ("label 1"); rich_location richloc (line_table, @@ -263,7 +264,7 @@ test_show_locus (function *fun) &label1); richloc.add_fixit_replace ("bar * foo"); warning_at (&richloc, 0, "test"); - global_dc->m_source_printing.show_ruler_p = false; + global_dc->get_source_printing_options ().show_ruler_p = false; } /* Likewise, but with a secondary location that's immediately before @@ -271,7 +272,7 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_very_wide_line_2")) { const int line = fnstart_line + 2; - global_dc->m_source_printing.show_ruler_p = true; + global_dc->get_source_printing_options ().show_ruler_p = true; text_range_label label0 ("label 0"); text_range_label label1 ("label 1"); rich_location richloc (line_table, @@ -283,7 +284,7 @@ test_show_locus (function *fun) richloc.add_range (get_loc (line, 34), SHOW_RANGE_WITHOUT_CARET, &label1); warning_at (&richloc, 0, "test"); - global_dc->m_source_printing.show_ruler_p = false; + global_dc->get_source_printing_options ().show_ruler_p = false; } /* Example of multiple carets. */ @@ -294,11 +295,11 @@ test_show_locus (function *fun) location_t caret_b = get_loc (line, 11); rich_location richloc (line_table, caret_a); add_range (&richloc, caret_b, caret_b, SHOW_RANGE_WITH_CARET); - global_dc->m_source_printing.caret_chars[0] = 'A'; - global_dc->m_source_printing.caret_chars[1] = 'B'; + global_dc->get_source_printing_options ().caret_chars[0] = 'A'; + global_dc->get_source_printing_options ().caret_chars[1] = 'B'; warning_at (&richloc, 0, "test"); - global_dc->m_source_printing.caret_chars[0] = '^'; - global_dc->m_source_printing.caret_chars[1] = '^'; + global_dc->get_source_printing_options ().caret_chars[0] = '^'; + global_dc->get_source_printing_options ().caret_chars[1] = '^'; } /* Tests of rendering fixit hints. */ @@ -412,11 +413,11 @@ test_show_locus (function *fun) location_t caret_b = get_loc (line - 1, 19); rich_location richloc (line_table, caret_a); richloc.add_range (caret_b, SHOW_RANGE_WITH_CARET); - global_dc->m_source_printing.caret_chars[0] = '1'; - global_dc->m_source_printing.caret_chars[1] = '2'; + global_dc->get_source_printing_options ().caret_chars[0] = '1'; + global_dc->get_source_printing_options ().caret_chars[1] = '2'; warning_at (&richloc, 0, "test"); - global_dc->m_source_printing.caret_chars[0] = '^'; - global_dc->m_source_printing.caret_chars[1] = '^'; + global_dc->get_source_printing_options ().caret_chars[0] = '^'; + global_dc->get_source_printing_options ().caret_chars[1] = '^'; } /* Example of using the "%q+D" format code, which as well as printing @@ -443,8 +444,8 @@ test_show_locus (function *fun) rich_location richloc (line_table, loc); for (int line = start_line; line <= finish_line; line++) { - file_cache &fc = global_dc->get_file_cache (); - char_span content = fc.get_source_line (file, line); + diagnostics::file_cache &fc = global_dc->get_file_cache (); + diagnostics::char_span content = fc.get_source_line (file, line); gcc_assert (content); /* Split line up into words. */ for (int idx = 0; idx < content.length (); idx++) @@ -464,7 +465,8 @@ test_show_locus (function *fun) richloc.add_range (word, SHOW_RANGE_WITH_CARET, &label); /* Add a fixit, converting to upper case. */ - char_span word_span = content.subspan (start_idx, idx - start_idx); + diagnostics::char_span word_span + = content.subspan (start_idx, idx - start_idx); char *copy = word_span.xstrdup (); for (char *ch = copy; *ch; ch++) *ch = TOUPPER (*ch); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc index 1b5fad2..b64d60f 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc @@ -208,7 +208,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 80; + global_dc->get_source_printing_options ().max_width = 80; pass_info.pass = new pass_test_string_literals (g); pass_info.reference_pass_name = "ssa"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.cc index e28d697..ce2f1d3 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.cc @@ -9,7 +9,7 @@ #include "coretypes.h" #include "plugin-version.h" #include "diagnostic.h" -#include "diagnostic-diagram.h" +#include "diagnostics/diagram.h" #include "text-art/canvas.h" #include "text-art/table.h" @@ -22,7 +22,7 @@ using namespace text_art; static void emit_canvas (const canvas &c, const char *alt_text) { - diagnostic_diagram diagram (c, alt_text); + diagnostics::diagram diagram (c, alt_text); global_dc->emit_diagram (diagram); } diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc index fbdb2f8..bbd0faa 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc @@ -89,7 +89,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 130; + global_dc->get_source_printing_options ().max_width = 130; register_callback (plugin_name, PLUGIN_PRE_GENERICIZE, diff --git a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc index 7b9b8d4..67722d4 100644 --- a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc @@ -6,9 +6,9 @@ #include "system.h" #include "coretypes.h" #include "diagnostic.h" -#include "edit-context.h" +#include "diagnostics/changes.h" #include "selftest.h" -#include "selftest-diagnostic.h" +#include "diagnostics/selftest-context.h" int plugin_is_GPL_compatible; @@ -47,14 +47,15 @@ static void test_richloc (rich_location *richloc) { /* Run the diagnostic and fix-it printing code. */ - test_diagnostic_context dc; - diagnostic_show_locus (&dc, dc.m_source_printing, - richloc, DK_ERROR, dc.get_reference_printer ()); + diagnostics::selftest::test_context dc; + diagnostic_show_locus (&dc, dc.get_source_printing_options (), + richloc, diagnostics::kind::error, + dc.get_reference_printer ()); /* Generate a diff. */ - edit_context ec (global_dc->get_file_cache ()); - ec.add_fixits (richloc); - char *diff = ec.generate_diff (true); + diagnostics::changes::change_set edit (global_dc->get_file_cache ()); + edit.add_fixits (richloc); + char *diff = edit.generate_diff (true); free (diff); } diff --git a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc index f770d35..00ad870 100644 --- a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc @@ -7,7 +7,7 @@ #include "coretypes.h" #include "spellcheck.h" #include "diagnostic.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" int plugin_is_GPL_compatible; @@ -39,12 +39,12 @@ on_pragma_registration (void */*gcc_data*/, void */*user_data*/) /* We add some extra testing during diagnostics by chaining up to the text finalizer. */ -static diagnostic_text_finalizer_fn original_text_finalizer = NULL; +static diagnostics::text_finalizer_fn original_text_finalizer = NULL; static void -verify_unpacked_ranges (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic, - diagnostic_t orig_diag_kind) +verify_unpacked_ranges (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diagnostic, + enum diagnostics::kind orig_diag_kind) { /* Verify that the locations are ad-hoc, not packed. */ location_t loc = diagnostic_location (diagnostic); @@ -56,9 +56,9 @@ verify_unpacked_ranges (diagnostic_text_output_format &text_output, } static void -verify_no_columns (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic, - diagnostic_t orig_diag_kind) +verify_no_columns (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diagnostic, + enum diagnostics::kind orig_diag_kind) { /* Verify that the locations have no columns. */ location_t loc = diagnostic_location (diagnostic); @@ -104,15 +104,15 @@ plugin_init (struct plugin_name_args *plugin_info, NULL); /* void *user_data */ /* Hack in additional testing, based on the exact value supplied. */ - original_text_finalizer = diagnostic_text_finalizer (global_dc); + original_text_finalizer = diagnostics::text_finalizer (global_dc); switch (base_location) { case LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES + 1: - diagnostic_text_finalizer (global_dc) = verify_unpacked_ranges; + diagnostics::text_finalizer (global_dc) = verify_unpacked_ranges; break; case LINE_MAP_MAX_LOCATION_WITH_COLS + 1: - diagnostic_text_finalizer (global_dc) = verify_no_columns; + diagnostics::text_finalizer (global_dc) = verify_no_columns; break; default: diff --git a/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c b/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c index d51d15c..6f65f4a 100644 --- a/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c +++ b/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c @@ -55,5 +55,5 @@ volatile fn_ptr_t fn_ptr; void test_5 (void) { - fn_ptr (); /* { dg-error "cannot tail-call: " } */ + fn_ptr (); } diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index d1d7f5d..ce25c0a 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -107,6 +107,10 @@ set plugin_test_list [list \ diagnostic-test-metadata.c \ diagnostic-test-metadata-html.c \ diagnostic-test-metadata-sarif.c } \ + { diagnostic_plugin_test_graphs.cc + diagnostic-test-graphs.c \ + diagnostic-test-graphs-html.c \ + diagnostic-test-graphs-sarif.c } \ { diagnostic_plugin_test_nesting.cc \ diagnostic-test-nesting-text-plain.c \ diagnostic-test-nesting-text-indented.c \ diff --git a/gcc/testsuite/gcc.dg/pr109267-1.c b/gcc/testsuite/gcc.dg/pr109267-1.c new file mode 100644 index 0000000..e762e59 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109267-1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* PR middle-end/109267 */ + +int f(void) +{ + __builtin_unreachable(); +} + +/* This unreachable should be changed to be a trap. */ + +/* { dg-final { scan-tree-dump-times "__builtin_unreachable trap \\\(" 1 "optimized" { target trap } } } */ +/* { dg-final { scan-tree-dump-times "goto <" 1 "optimized" { target { ! trap } } } } */ +/* { dg-final { scan-tree-dump-not "__builtin_unreachable \\\(" "optimized"} } */ diff --git a/gcc/testsuite/gcc.dg/pr109267-2.c b/gcc/testsuite/gcc.dg/pr109267-2.c new file mode 100644 index 0000000..6cd1419 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109267-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* PR middle-end/109267 */ +void g(void); +int f(int *t) +{ + g(); + __builtin_unreachable(); +} + +/* The unreachable should stay a unreachable. */ +/* { dg-final { scan-tree-dump-not "__builtin_unreachable trap \\\(" "optimized"} } */ +/* { dg-final { scan-tree-dump-times "__builtin_unreachable \\\(" 1 "optimized"} } */ diff --git a/gcc/testsuite/gcc.dg/pr116906-1.c b/gcc/testsuite/gcc.dg/pr116906-1.c index 7187507..ee60ad6 100644 --- a/gcc/testsuite/gcc.dg/pr116906-1.c +++ b/gcc/testsuite/gcc.dg/pr116906-1.c @@ -1,3 +1,4 @@ +/* { dg-do run } */ /* { dg-require-effective-target alarm } */ /* { dg-require-effective-target signal } */ /* { dg-options "-O2" } */ diff --git a/gcc/testsuite/gcc.dg/pr116906-2.c b/gcc/testsuite/gcc.dg/pr116906-2.c index 41a352b..4172ec3 100644 --- a/gcc/testsuite/gcc.dg/pr116906-2.c +++ b/gcc/testsuite/gcc.dg/pr116906-2.c @@ -1,3 +1,4 @@ +/* { dg-do run } */ /* { dg-require-effective-target alarm } */ /* { dg-require-effective-target signal } */ /* { dg-options "-O2 -fno-tree-ch" } */ diff --git a/gcc/testsuite/gcc.dg/pr120660.c b/gcc/testsuite/gcc.dg/pr120660.c new file mode 100644 index 0000000..6e8c5e8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr120660.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ +/* { dg-options "-O -favoid-store-forwarding" } */ + +int c; + +short +foo (short s) +{ + __builtin_memset (&s, c, 1); + return s; +} + +int +main () +{ + short x = foo (0x1111); + if (x != 0x1100 && x != 0x0011) + __builtin_abort(); +} diff --git a/gcc/testsuite/gcc.dg/pr121035.c b/gcc/testsuite/gcc.dg/pr121035.c new file mode 100644 index 0000000..fc0edce --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr121035.c @@ -0,0 +1,94 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple" } */ + +int printf(const char *, ...); +int a, b, d; +unsigned c; +int __GIMPLE (ssa,startwith("pre")) +main () +{ + unsigned int g; + int f; + unsigned int _1; + unsigned int _2; + int _3; + int _4; + int _5; + unsigned int _6; + unsigned int _7; + int _10; + unsigned int _11; + _Bool _19; + _Bool _20; + _Bool _22; + int _25; + + __BB(2): + _25 = a; + if (_25 != 0) + goto __BB11; + else + goto __BB10; + + __BB(11): + goto __BB3; + + __BB(3): + f_26 = __PHI (__BB12: f_18, __BB11: 0); + g_15 = c; + if (f_26 != 0) + goto __BB4; + else + goto __BB5; + + __BB(4): + __builtin_putchar (48); + goto __BB5; + + __BB(5): + _1 = c; + _2 = _1 << 1; + _3 = a; + _4 = d; + _5 = _3 * _4; + if (_5 != 0) + goto __BB7; + else + goto __BB6; + + __BB(6): + goto __BB7; + + __BB(7): + _11 = __PHI (__BB5: 0u, __BB6: 4294967295u); + _6 = g_15 * 4294967294u; + _7 = _6 | _11; + _20 = _3 != 0; + _19 = _7 != 0u; + _22 = _19 & _20; + if (_22 != _Literal (_Bool) 0) + goto __BB9; + else + goto __BB8; + + __BB(8): + goto __BB9; + + __BB(9): + _10 = __PHI (__BB7: 1, __BB8: 0); + b = _10; + f_18 = (int) _1; + if (_3 != 0) + goto __BB12; + else + goto __BB10; + + __BB(12): + goto __BB3; + + __BB(10): + return 0; + +} + + diff --git a/gcc/testsuite/gcc.dg/pr121202.c b/gcc/testsuite/gcc.dg/pr121202.c new file mode 100644 index 0000000..30ecf4a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr121202.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fno-tree-copy-prop" } */ + +int a, b, c; +int e(int f, int g) { return f >> g; } +int h(int f) { return a > 1 ? 0 : f << a; } +int main() { + while (c--) + b = e(h(1), a); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr121216.c b/gcc/testsuite/gcc.dg/pr121216.c new file mode 100644 index 0000000..a695b40 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr121216.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int foo (void) +{ + const char *key = "obscurelevelofabstraction"; + const char reverse_key[__builtin_strlen(key)] = {'\0'}; /* { dg-error "variable-sized object may not be initialized except with an empty initializer" } */ + return __builtin_strlen(reverse_key); +} diff --git a/gcc/testsuite/gcc.dg/pr121322.c b/gcc/testsuite/gcc.dg/pr121322.c new file mode 100644 index 0000000..2fad5b5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr121322.c @@ -0,0 +1,14 @@ +/* PR middle-end/121322 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +unsigned long long +foo (unsigned long long *p) +{ + unsigned long long a = *p; + unsigned long long b = __builtin_bswap64 (a); + return ((b << 32) + | ((b >> 8) & 0xff000000ULL) + | ((b >> 24) & 0xff0000ULL) + | ((b >> 40) & 0xff00ULL)); +} diff --git a/gcc/testsuite/gcc.dg/pr32450.c b/gcc/testsuite/gcc.dg/pr32450.c index 9606e30..0af262f 100644 --- a/gcc/testsuite/gcc.dg/pr32450.c +++ b/gcc/testsuite/gcc.dg/pr32450.c @@ -4,6 +4,7 @@ /* { dg-require-profiling "-pg" } */ /* { dg-options "-O2 -pg" } */ /* { dg-options "-O2 -pg -mtune=core2" { target { i?86-*-* x86_64-*-* } } } */ +/* { dg-additional-options "-mfentry -fno-pic" { target i?86-*-gnu* x86_64-*-gnu* } } */ /* { dg-options "-O2 -pg -static" { target hppa*-*-hpux* } } */ extern void abort (void); diff --git a/gcc/testsuite/gcc.dg/pr43643.c b/gcc/testsuite/gcc.dg/pr43643.c index 43896ab..41c00c8 100644 --- a/gcc/testsuite/gcc.dg/pr43643.c +++ b/gcc/testsuite/gcc.dg/pr43643.c @@ -4,6 +4,7 @@ /* { dg-require-profiling "-pg" } */ /* { dg-options "-O2 -pg" } */ /* { dg-options "-O2 -pg -static" { target hppa*-*-hpux* } } */ +/* { dg-additional-options "-mfentry -fno-pic" { target i?86-*-gnu* x86_64-*-gnu* } } */ extern char *strdup (const char *); diff --git a/gcc/testsuite/gcc.dg/pr78185.c b/gcc/testsuite/gcc.dg/pr78185.c index ada8b1b..4c3af4f 100644 --- a/gcc/testsuite/gcc.dg/pr78185.c +++ b/gcc/testsuite/gcc.dg/pr78185.c @@ -1,3 +1,4 @@ +/* { dg-do run } */ /* { dg-require-effective-target alarm } */ /* { dg-require-effective-target signal } */ /* { dg-options "-O" } */ diff --git a/gcc/testsuite/gcc.dg/pr87600-1.c b/gcc/testsuite/gcc.dg/pr87600-1.c index 3517957..9d74cad 100644 --- a/gcc/testsuite/gcc.dg/pr87600-1.c +++ b/gcc/testsuite/gcc.dg/pr87600-1.c @@ -1,5 +1,5 @@ /* PR rtl-optimization/87600 */ -/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* loongarch*-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ /* { dg-options "-O2" } */ #include "pr87600.h" diff --git a/gcc/testsuite/gcc.dg/pr87600-2.c b/gcc/testsuite/gcc.dg/pr87600-2.c index e8a9f19..822afe0 100644 --- a/gcc/testsuite/gcc.dg/pr87600-2.c +++ b/gcc/testsuite/gcc.dg/pr87600-2.c @@ -1,5 +1,5 @@ /* PR rtl-optimization/87600 */ -/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* loongarch*-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ /* { dg-options "-O2" } */ #include "pr87600.h" @@ -23,22 +23,3 @@ test1 (void) asm ("blah %0 %1" : "=r" (var1) : "0" (var2)); /* { dg-error "invalid hard register usage between output operand and matching constraint operand" } */ return var1; } - -long -test2 (void) -{ - register long var1 asm (REG1); - register long var2 asm (REG1); - asm ("blah %0 %1" : "=&r" (var1) : "r" (var2)); /* { dg-error "invalid hard register usage between earlyclobber operand and input operand" } */ - return var1; -} - -long -test3 (void) -{ - register long var1 asm (REG1); - register long var2 asm (REG1); - long var3; - asm ("blah %0 %1" : "=&r" (var1), "=r" (var3) : "1" (var2)); /* { dg-error "invalid hard register usage between earlyclobber operand and input operand" } */ - return var1 + var3; -} diff --git a/gcc/testsuite/gcc.dg/pr87600-3.c b/gcc/testsuite/gcc.dg/pr87600-3.c new file mode 100644 index 0000000..4f43a5f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr87600-3.c @@ -0,0 +1,26 @@ +/* PR rtl-optimization/87600 */ +/* { dg-do compile { target aarch64*-*-* arm*-*-* i?86-*-* powerpc*-*-* s390*-*-* x86_64-*-* } } */ +/* { dg-options "-O2" } */ + +#include "pr87600.h" + +/* The following are all invalid uses of local register variables. */ + +long +test2 (void) +{ + register long var1 asm (REG1); + register long var2 asm (REG1); + asm ("blah %0 %1" : "=&r" (var1) : "r" (var2)); /* { dg-error "invalid hard register usage between earlyclobber operand and input operand" } */ + return var1; +} + +long +test3 (void) +{ + register long var1 asm (REG1); + register long var2 asm (REG1); + long var3; + asm ("blah %0 %1" : "=&r" (var1), "=r" (var3) : "1" (var2)); /* { dg-error "invalid hard register usage between earlyclobber operand and input operand" } */ + return var1 + var3; +} diff --git a/gcc/testsuite/gcc.dg/pr87600.h b/gcc/testsuite/gcc.dg/pr87600.h index c89071eb..29f065e 100644 --- a/gcc/testsuite/gcc.dg/pr87600.h +++ b/gcc/testsuite/gcc.dg/pr87600.h @@ -7,6 +7,9 @@ #elif defined (__i386__) # define REG1 "%eax" # define REG2 "%edx" +#elif defined (__loongarch__) +# define REG1 "$t0" +# define REG2 "$t1" #elif defined (__powerpc__) || defined (__POWERPC__) || defined (__PPC__) # define REG1 "r3" # define REG2 "r4" diff --git a/gcc/testsuite/gcc.dg/sarif-output/include-chain-2.h b/gcc/testsuite/gcc.dg/sarif-output/include-chain-2.h index 382ac02..f60fb33 100644 --- a/gcc/testsuite/gcc.dg/sarif-output/include-chain-2.h +++ b/gcc/testsuite/gcc.dg/sarif-output/include-chain-2.h @@ -1,4 +1,4 @@ -/* Generate a warning with a diagnostic_path within a header. */ +/* Generate a warning with a diagnostic path within a header. */ void test (void *ptr) { diff --git a/gcc/testsuite/gcc.dg/torture/pr121116.c b/gcc/testsuite/gcc.dg/torture/pr121116.c new file mode 100644 index 0000000..637324f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr121116.c @@ -0,0 +1,21 @@ +/* { dg-do run { target bitint } } */ + +#include <stdlib.h> +#include <stdckdint.h> +#include <string.h> +typedef _BitInt(16) bit16; +[[nodiscard]] static bit16 process_data(bit16 input) { + _Static_assert(sizeof(bit16) == 2, "Unexpected size of bit16"); + return (input << 5) | (input >> 9); +} +int main(void) { + const bit16 data = 0b101'0101'0000'0000; + bit16 result = 0; + for (bit16 i = 0; i < 0b1000; ++i) { + result ^= process_data(data ^ i); + } + if (ckd_add(&result, result, 0x1234)) { + return EXIT_FAILURE; + } + return (result & 0xFF00) ? 0 : 1; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr121194.c b/gcc/testsuite/gcc.dg/torture/pr121194.c new file mode 100644 index 0000000..20f5ff7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr121194.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ + +int a, b, c, d; +void e() { + int *f = &b; + for (a = 0; a < 8; a++) { + *f = 0; + for (c = 0; c < 2; c++) + *f = *f == 0; + } +} +int main() { + e(); + int *g = &b; + *g = *g == (d == 0); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr121236-1.c b/gcc/testsuite/gcc.dg/torture/pr121236-1.c new file mode 100644 index 0000000..2b397e3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr121236-1.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* PR tree-optimization/121236 */ + + +unsigned func_26(short *p_27, int gg, int p) { + unsigned l_184 = 0; + unsigned m = 0; + for (int g_59 = 0; g_59 < 10; g_59++) + { + if (gg) + l_184--; + else + { + m |= l_184 |= p; + (l_184)--; + } + } + return m; +} + diff --git a/gcc/testsuite/gcc.dg/torture/pr121295-1.c b/gcc/testsuite/gcc.dg/torture/pr121295-1.c new file mode 100644 index 0000000..7825c6e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr121295-1.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-additional-options " -fno-tree-copy-prop -fno-tree-pre -fno-code-hoisting" */ + +/* PR tree-optimization/121295 */ + + +int a, b, c; +int main() { + int *d = &a; + while (b) + b = (*d &= 10) <= 0 || (*d = c); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/tree-prof/afdo-crossmodule-1b.c b/gcc/testsuite/gcc.dg/tree-prof/afdo-crossmodule-1b.c index dd53295..79ba529 100644 --- a/gcc/testsuite/gcc.dg/tree-prof/afdo-crossmodule-1b.c +++ b/gcc/testsuite/gcc.dg/tree-prof/afdo-crossmodule-1b.c @@ -1,3 +1,8 @@ +/* { dg-require-effective-target lto } */ +/* { dg-additional-sources "afdo-crossmodule-1.c" } */ +/* { dg-options "-O3 -flto -fdump-ipa-afdo_offline -fdump-tree-einline-details" } */ +/* { dg-require-profiling "-fauto-profile" } */ + extern int foo2 (); int bar (int (*fooptr) (int (*)())) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmp-2.c b/gcc/testsuite/gcc.dg/tree-ssa/cmp-2.c new file mode 100644 index 0000000..9b02901 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/cmp-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop" } */ + +/* PR tree-optimization/110949 */ +/* Transform `(cmp) - 1` into `-icmp`. */ + +int f1(int a) +{ + int t = a == 115; + return t - 1; +} + +/* { dg-final { scan-tree-dump " != 115" "forwprop1" } } */ +/* { dg-final { scan-tree-dump-not " == 115" "forwprop1" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cswtch-7.c b/gcc/testsuite/gcc.dg/tree-ssa/cswtch-7.c new file mode 100644 index 0000000..7b797807 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/cswtch-7.c @@ -0,0 +1,48 @@ +/* PR tree-optimization/120523 */ +/* PR tree-optimization/120451 */ +/* { dg-do compile { target elf } } */ +/* { dg-options "-O2" } */ + +void foo (int, int); + +__attribute__((noinline, noclone)) void +f1 (int v, int w) +{ + int i, j; + if (w) + { + i = 129; + j = i - 1; + goto lab; + } + switch (v) + { + case 170: + j = 7; + i = 27; + break; + case 171: + i = 8; + j = 122; + break; + case 172: + i = 21; + j = -19; + break; + case 173: + i = 18; + j = 17; + break; + case 174: + i = 33; + j = 55; + break; + default: + __builtin_abort (); + } + + lab: + foo (i, j); +} + +/* { dg-final { scan-assembler ".rodata.cst32" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/max-bitcmp-1.c b/gcc/testsuite/gcc.dg/tree-ssa/max-bitcmp-1.c new file mode 100644 index 0000000..81b5a27 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/max-bitcmp-1.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop -fdump-tree-optimized" } */ + +/* PR tree-optimization/95906 */ +/* this should become MAX_EXPR<a,b> */ + +int f2(int a, int b) +{ + int cmp = -(a > b); + return (cmp & a) | (~cmp & b); +} + +/* we should not end up with -_2 */ +/* we should not end up and & nor a `+ -1` */ +/* In optimized we should have a max. */ +/* { dg-final { scan-tree-dump-not " -\[a-zA-Z_\]" "forwprop1" } } */ +/* { dg-final { scan-tree-dump-not " & " "forwprop1" } } */ +/* { dg-final { scan-tree-dump-not " . -1" "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR " 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr117423.c b/gcc/testsuite/gcc.dg/tree-ssa/pr117423.c new file mode 100644 index 0000000..a5d3b29 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr117423.c @@ -0,0 +1,49 @@ +/* { dg-do run } */ +/* { dg-options "-O1" } */ + +struct s4 { + int _0; +}; +struct s1 { + unsigned char _4; + long _1; +}; +struct s2 { + union { + struct s3 { + unsigned char _1; + struct s4 _0; + } var_0; + struct s1 var_1; + } DATA; +}; +int f1(int arg0) { return arg0 > 12345; } +__attribute__((noinline)) +struct s4 f2(int arg0) { + struct s4 rv = {arg0}; + return rv; +} +struct s2 f3(int arg0) { + struct s2 rv; + struct s1 var6 = {0}; + struct s4 var7; + if (f1(arg0)) { + rv.DATA.var_1 = var6; + return rv; + } else { + rv.DATA.var_0._1 = 2; + var7 = f2(arg0); + rv.DATA.var_0._0 = var7; + return rv; + } +} +int main() { + if (f3(12345).DATA.var_0._0._0 == 12345) + ; + else + __builtin_abort(); + if (f3(12344).DATA.var_0._0._0 == 12344) + ; + else + __builtin_abort(); +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr119085.c b/gcc/testsuite/gcc.dg/tree-ssa/pr119085.c new file mode 100644 index 0000000..e9811ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr119085.c @@ -0,0 +1,37 @@ +/* { dg-do run } */ +/* { dg-options "-O1" } */ + +struct with_hole { + int x; + long y; +}; +struct without_hole { + int x; + int y; +}; +union u { + struct with_hole with_hole; + struct without_hole without_hole; +}; + +void __attribute__((noinline)) +test (union u *up, union u u) +{ + union u u2; + volatile int f = 0; + u2 = u; + if (f) + u2.with_hole = u.with_hole; + *up = u2; +} + +int main(void) +{ + union u u; + union u u2; + u2.without_hole.y = -1; + test (&u, u2); + if (u.without_hole.y != -1) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr121264.c b/gcc/testsuite/gcc.dg/tree-ssa/pr121264.c new file mode 100644 index 0000000..bd5acc0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr121264.c @@ -0,0 +1,12 @@ +/* PR tree-optimization/121264 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump " \\\| " "optimized" } } */ + +struct A { char b; char c[0x20000010]; } a; + +int +foo () +{ + return a.c[0x20000000] || a.c[1]; +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr81627.c b/gcc/testsuite/gcc.dg/tree-ssa/pr81627.c index 9ba43be..ef35b29 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr81627.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr81627.c @@ -4,6 +4,7 @@ int a, b, c, d[6], e = 3, f; void abort (void); +void fn1 () __attribute__((noinline)); void fn1 () { for (b = 1; b < 5; b++) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-23.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-23.c new file mode 100644 index 0000000..f632dc8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-23.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-sink1-details" } */ + +struct S { + int* x; + int* y; +}; + +void __attribute__((noreturn)) bar(const struct S* s); + +void foo(int a, int b) { + struct S s; + s.x = &a; + s.y = &b; + if (a < b) { + bar(&s); + } +} + +/* { dg-final { scan-tree-dump "Sinking.*s.y" "sink1" } } */ +/* { dg-final { scan-tree-dump "Sinking.*s.x" "sink1" } } */ diff --git a/gcc/testsuite/gcc.dg/uninit-pr120924.c b/gcc/testsuite/gcc.dg/uninit-pr120924.c new file mode 100644 index 0000000..bfc8ae9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr120924.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wmaybe-uninitialized" } */ + +int foo(int); +enum { + BPF_TRACE_RAW_TP, + BPF_MODIFY_RETURN, + BPF_LSM_MAC, + BPF_TRACE_ITER, + BPF_LSM_CGROUP +}; +int btf_get_kernel_prefix_kind_prefix, obj_1, attach_name___trans_tmp_1; +char attach_name_fn_name; +void attach_name(int attach_type) +{ + int mod_len; + char mod_name = attach_name_fn_name; + if (attach_name_fn_name) + mod_len = mod_name; + for (; obj_1;) { + if (mod_name && foo(mod_len)) + continue; + switch (attach_type) { + case BPF_TRACE_RAW_TP: + case BPF_LSM_MAC: + case BPF_LSM_CGROUP: + btf_get_kernel_prefix_kind_prefix = 1; + case BPF_TRACE_ITER: + attach_name_fn_name = 2; + } + if (attach_name___trans_tmp_1) + return; + } +} diff --git a/gcc/testsuite/gcc.dg/unused-9.c b/gcc/testsuite/gcc.dg/unused-9.c index bdf36e1..ad1ad0e 100644 --- a/gcc/testsuite/gcc.dg/unused-9.c +++ b/gcc/testsuite/gcc.dg/unused-9.c @@ -2,12 +2,9 @@ /* { dg-do compile } */ /* { dg-options "-Wunused" } */ - void g(void) { - int i = 0; - volatile int x; - (x, i++); /* { dg-bogus "set but not used" } */ + int i = 0; /* { dg-warning "variable 'i' set but not used" } */ + volatile int x; /* { dg-bogus "variable 'x' set but not used" } */ + (x, i++); } - - diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-39.c b/gcc/testsuite/gcc.dg/vect/bb-slp-39.c index f05ce8f..255bb10 100644 --- a/gcc/testsuite/gcc.dg/vect/bb-slp-39.c +++ b/gcc/testsuite/gcc.dg/vect/bb-slp-39.c @@ -16,5 +16,4 @@ void foo (double *p) } /* See that we vectorize three SLP instances. */ -/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 3 "slp2" { target { ! { s390*-*-* riscv*-*-* } } } } } */ -/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 5 "slp2" { target { s390*-*-* riscv*-*-* } } } } */ +/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 3 "slp2" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/pr112325.c b/gcc/testsuite/gcc.dg/vect/pr112325.c index 8689fbf..d380595 100644 --- a/gcc/testsuite/gcc.dg/vect/pr112325.c +++ b/gcc/testsuite/gcc.dg/vect/pr112325.c @@ -5,6 +5,7 @@ /* { dg-additional-options "-mavx2" { target x86_64-*-* i?86-*-* } } */ /* { dg-additional-options "--param max-completely-peeled-insns=200" { target powerpc64*-*-* } } */ /* { dg-additional-options "-mlsx" { target loongarch64-*-* } } */ +/* { dg-additional-options "--param max-completely-peeled-insns=200 --param min-vect-loop-bound=0" { target s390*-*-* } } */ typedef unsigned short ggml_fp16_t; static float table_f32_f16[1 << 16]; diff --git a/gcc/testsuite/gcc.dg/vect/pr116125.c b/gcc/testsuite/gcc.dg/vect/pr116125.c index eab9efd..1b882ec 100644 --- a/gcc/testsuite/gcc.dg/vect/pr116125.c +++ b/gcc/testsuite/gcc.dg/vect/pr116125.c @@ -17,12 +17,12 @@ main (void) { check_vect (); - struct st a[9] = {}; + struct st a[10] = {}; - // input a = 0, 0, 0, 0, 0, 0, 0, 0, 0 + // input a = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 mem_overlap (&a[1], a); - // output a = 0, 1, 2, 3, 4, 5, 6, 7, 8 + // output a = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 if (a[2].num == 2) return 0; else diff --git a/gcc/testsuite/gcc.dg/vect/pr117888-1.c b/gcc/testsuite/gcc.dg/vect/pr117888-1.c index 0b31fcd..884aed2 100644 --- a/gcc/testsuite/gcc.dg/vect/pr117888-1.c +++ b/gcc/testsuite/gcc.dg/vect/pr117888-1.c @@ -5,6 +5,7 @@ /* { dg-additional-options "-mavx2" { target x86_64-*-* i?86-*-* } } */ /* { dg-additional-options "--param max-completely-peeled-insns=200" { target powerpc64*-*-* } } */ /* { dg-additional-options "-mlsx" { target loongarch64-*-* } } */ +/* { dg-additional-options "--param max-completely-peeled-insns=200 --param min-vect-loop-bound=0" { target s390*-*-* } } */ typedef unsigned short ggml_fp16_t; static float table_f32_f16[1 << 16]; diff --git a/gcc/testsuite/gcc.dg/vect/pr120687-1.c b/gcc/testsuite/gcc.dg/vect/pr120687-1.c new file mode 100644 index 0000000..ce9cf63 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr120687-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_int } */ + +unsigned +frd (unsigned *p, unsigned *lastone) +{ + unsigned sum = 0; + for (; p <= lastone; p += 16) + sum += p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7] + + p[8] + p[9] + p[10] + p[11] + p[12] + p[13] + p[14] + p[15]; + return sum; +} + +/* { dg-final { scan-tree-dump "reduction: detected reduction chain" "vect" } } */ +/* { dg-final { scan-tree-dump-not "SLP discovery of reduction chain failed" "vect" } } */ +/* { dg-final { scan-tree-dump "optimized: loop vectorized" "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/pr120687-2.c b/gcc/testsuite/gcc.dg/vect/pr120687-2.c new file mode 100644 index 0000000..dfc6dc7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr120687-2.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_float } */ +/* { dg-additional-options "-ffast-math" } */ + +float +frd (float *p, float *lastone) +{ + float sum = 0; + for (; p <= lastone; p += 16) + sum += p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7] + + p[8] + p[9] + p[10] + p[11] + p[12] + p[13] + p[14] + p[15]; + return sum; +} + +/* { dg-final { scan-tree-dump "reduction: detected reduction chain" "vect" } } */ +/* { dg-final { scan-tree-dump-not "SLP discovery of reduction chain failed" "vect" } } */ +/* { dg-final { scan-tree-dump "optimized: loop vectorized" "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/pr120687-3.c b/gcc/testsuite/gcc.dg/vect/pr120687-3.c new file mode 100644 index 0000000..f20a66a --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr120687-3.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_double } */ +/* { dg-additional-options "-ffast-math" } */ + +float +frd (float *p, float *lastone) +{ + float sum = 0; + for (; p <= lastone; p += 2) + sum += p[0] + p[1]; + return sum; +} + +/* { dg-final { scan-tree-dump "reduction: detected reduction chain" "vect" } } */ +/* { dg-final { scan-tree-dump-not "SLP discovery of reduction chain failed" "vect" } } */ +/* { dg-final { scan-tree-dump "optimized: loop vectorized" "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/pr121034.c b/gcc/testsuite/gcc.dg/vect/pr121034.c new file mode 100644 index 0000000..de20781 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr121034.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O3" } */ + +int b, e; +char c, d; +unsigned g; +int abs(int); +void f() { + char *a = &d; + int h; + for (; e; e++) { + h = 0; + for (; h < 16; h++) + g += __builtin_abs(a[h] - c); + a += b; + } +} diff --git a/gcc/testsuite/gcc.dg/vect/pr121049.c b/gcc/testsuite/gcc.dg/vect/pr121049.c new file mode 100644 index 0000000..558c92a --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr121049.c @@ -0,0 +1,25 @@ +/* { dg-additional-options "--param vect-partial-vector-usage=1" } */ +/* { dg-additional-options "-march=x86-64-v4" { target avx512f_runtime } } */ + +#include "tree-vect.h" + +int mon_lengths[12] = { 1, 10, 100 }; + +__attribute__ ((noipa)) long +transtime (int mon) +{ + long value = 0; + for (int i = 0; i < mon; ++i) + value += mon_lengths[i] * 2l; + return value; +} + +int +main () +{ + check_vect (); + if (transtime (3) != 222) + __builtin_abort (); + return 0; +} + diff --git a/gcc/testsuite/gcc.dg/vect/pr121059.c b/gcc/testsuite/gcc.dg/vect/pr121059.c new file mode 100644 index 0000000..2bbfcea --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr121059.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O3 --param vect-partial-vector-usage=1" } */ +/* { dg-additional-options "-march=x86-64-v4" { target avx512f } } */ + +typedef struct { + long left, right, top, bottom; +} MngBox; +typedef struct { + MngBox object_clip[6]; + char exists[256], frozen[]; +} MngReadInfo; +MngReadInfo mng_info; + +long ReadMNGImage_i; + +void ReadMNGImage(int ReadMNGImage_i) +{ + for (; ReadMNGImage_i < 256; ReadMNGImage_i++) + if (mng_info.exists[ReadMNGImage_i] && mng_info.frozen[ReadMNGImage_i]) + mng_info.object_clip[ReadMNGImage_i].left = + mng_info.object_clip[ReadMNGImage_i].right = + mng_info.object_clip[ReadMNGImage_i].top = + mng_info.object_clip[ReadMNGImage_i].bottom = 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr121126.c b/gcc/testsuite/gcc.dg/vect/pr121126.c new file mode 100644 index 0000000..ae6603b --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr121126.c @@ -0,0 +1,30 @@ +/* { dg-additional-options "--param vect-partial-vector-usage=2" } */ + +#include "tree-vect.h" + +unsigned char a; +unsigned b; +int r[11]; +static void __attribute__((noipa)) +c(int e, unsigned s[][11][11]) +{ + for (int u = -(e ? 2000424973 : 0) - 2294542319; u < 7; u += 4) + for (int x = 0; x < 300000011; x += 4) + for (int y = 0; y < (0 < s[u][4][1]) + 11; y += 3) { + a = a ?: 1; + b = r[2]; + } +} +long long ab; +int e = 1; +unsigned s[11][11][11]; +int main() +{ + check_vect (); + for (int t = 0; t < 11; ++t) + r[t] = 308100; + c(e,s); + ab = b; + if (ab != 308100) + __builtin_abort (); +} diff --git a/gcc/testsuite/gcc.dg/vect/slp-28.c b/gcc/testsuite/gcc.dg/vect/slp-28.c index 67b7be2..1f98787 100644 --- a/gcc/testsuite/gcc.dg/vect/slp-28.c +++ b/gcc/testsuite/gcc.dg/vect/slp-28.c @@ -59,8 +59,8 @@ main1 () abort (); } - /* Not vectorizable because of data dependencies: distance 3 is greater than - the actual VF with SLP (2), but the analysis fail to detect that for now. */ + /* Dependence distance 3 is greater than the actual VF with SLP (2), + thus vectorizable. */ for (i = 3; i < N/4; i++) { in3[i*4] = in3[(i-3)*4] + 5; @@ -91,7 +91,6 @@ int main (void) return 0; } -/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { target { ! vect32 } } } } */ -/* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect" { target vect32 } } } */ -/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 1 "vect" { target { ! vect32 } } } } */ +/* { dg-final { scan-tree-dump-times "vectorized 2 loops" 1 "vect" } } */ +/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 2 "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-127.c b/gcc/testsuite/gcc.dg/vect/vect-127.c new file mode 100644 index 0000000..8b913dc --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-127.c @@ -0,0 +1,15 @@ +// { dg-do compile } +// { dg-require-effective-target vect_int } + +void foo (int *p) +{ + for (int i = 0; i < 1024; ++i) + { + int a0 = p[2*i + 0]; + int a1 = p[2*i + 1]; + p[2*i + 4] = a0; + p[2*i + 5] = a1; + } +} + +/* { dg-final { scan-tree-dump "loop vectorized using 16 byte vectors" "vect" { target { vect128 && vect_hw_misalign } } } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_137-pr121190.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_137-pr121190.c new file mode 100644 index 0000000..e6b071c --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_137-pr121190.c @@ -0,0 +1,62 @@ +/* PR tree-optimization/121190 */ +/* { dg-options "-O3" } */ +/* { dg-additional-options "-march=znver2" { target x86_64-*-* i?86-*-* } } */ +/* { dg-require-effective-target mmap } */ +/* { dg-require-effective-target vect_early_break } */ + +#include <stdint.h> +#include <string.h> +#include <stdio.h> +#include <sys/mman.h> +#include <unistd.h> +#include "tree-vect.h" + +#define MAX_COMPARE 5000 + +__attribute__((noipa)) +int diff (uint64_t *restrict p, uint64_t *restrict q) +{ + int i = 0; + while (i < MAX_COMPARE) { + if (*(p + i) != *(q + i)) + return i; + i++; + } + return -1; +} + +int main () +{ + check_vect (); + + long pgsz = sysconf (_SC_PAGESIZE); + if (pgsz == -1) { + fprintf (stderr, "sysconf failed\n"); + return 0; + } + + /* Allocate 2 consecutive pages of memory and let p1 and p2 point to the + beginning of each. */ + void *mem = mmap (NULL, pgsz * 2, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (mem == MAP_FAILED) { + fprintf (stderr, "mmap failed\n"); + return 0; + } + uint64_t *p1 = (uint64_t *) mem; + uint64_t *p2 = (uint64_t *) mem + pgsz / sizeof (uint64_t); + + /* Fill the first page with zeros, except for its last 64 bits. */ + memset (p1, 0, pgsz); + *(p2 - 1) = -1; + + /* Make the 2nd page not accessable. */ + mprotect (p2, pgsz, PROT_NONE); + + /* Calls to diff should not read the 2nd page. */ + for (int i = 1; i <= 20; i++) { + if (diff (p2 - i, p1) != i - 1) + __builtin_abort (); + } +} + diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_138-pr121020.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_138-pr121020.c new file mode 100644 index 0000000..8cb62bf --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_138-pr121020.c @@ -0,0 +1,54 @@ +/* PR tree-optimization/121020 */ +/* { dg-options "-O3 --vect-cost-model=unlimited" } */ +/* { dg-additional-options "-march=znver2" { target x86_64-*-* i?86-*-* } } */ +/* { dg-require-effective-target mmap } */ +/* { dg-require-effective-target vect_early_break } */ + +#include <stdint.h> +#include <stdio.h> +#include <sys/mman.h> +#include <unistd.h> +#include "tree-vect.h" + +__attribute__((noipa)) +bool equal (uint64_t *restrict p, uint64_t *restrict q, int length) +{ + for (int i = 0; i < length; i++) { + if (*(p + i) != *(q + i)) + return false; + } + return true; +} + +int main () +{ + check_vect (); + + long pgsz = sysconf (_SC_PAGESIZE); + if (pgsz == -1) { + fprintf (stderr, "sysconf failed\n"); + return 0; + } + + /* Allocate a whole page of memory. */ + void *mem = mmap (NULL, pgsz, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (mem == MAP_FAILED) { + fprintf (stderr, "mmap failed\n"); + return 0; + } + uint64_t *p1 = (uint64_t *) mem; + uint64_t *p2 = (uint64_t *) mem + 32; + + /* The first 16 elements pointed to by p1 and p2 are the same. */ + for (int i = 0; i < 32; i++) { + *(p1 + i) = 0; + *(p2 + i) = (i < 16 ? 0 : -1); + } + + /* All calls to equal should return true. */ + for (int len = 0; len < 16; len++) { + if (!equal (p1 + 1, p2 + 1, len)) + __builtin_abort(); + } +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_52.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_52.c index 86a632f..6abfcd6 100644 --- a/gcc/testsuite/gcc.dg/vect/vect-early-break_52.c +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_52.c @@ -18,4 +18,4 @@ int main1 (short X) } } -/* { dg-final { scan-tree-dump "vectorized 1 loops in function" "vect" { target { ! "x86_64-*-* i?86-*-*" } } } } */ +/* { dg-final { scan-tree-dump "vectorized 1 loops in function" "vect" { target { ! "x86_64-*-* i?86-*-* arm*-*-*" } } } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-recurr-pr121256-2.c b/gcc/testsuite/gcc.dg/vect/vect-recurr-pr121256-2.c new file mode 100644 index 0000000..7350fd9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-recurr-pr121256-2.c @@ -0,0 +1,49 @@ +/* { dg-additional-options "-mavx2" { target avx2_runtime } } */ + +#include "tree-vect.h" + +#define B 0 +#define G 1 +#define R 2 + +int red = 153; +int green = 66; +int blue = 187; + +static void __attribute__((noipa)) +sub_left_prediction_bgr32(int *restrict dst, int *restrict src) +{ + for (int i = 0; i < 8; i++) { + int rt = src[i * 3 + R]; + int gt = src[i * 3 + G]; + int bt = src[i * 3 + B]; + + dst[i * 3 + R] = rt - red; + dst[i * 3 + G] = gt - green; + dst[i * 3 + B] = bt - blue; + + red = rt; + green = gt; + blue = bt; + } +} + +int main() +{ + int dst[8*3]; + int src[8*3] = { 160, 73, 194, 17, 33, 99, 0, 12, 283, 87, 73, 11, + 9, 7, 1, 23, 19, 13, 77, 233, 97, 78, 2, 5 }; + int dst2[8*3] = {-27, 7, 41, -143, -40, -95, -17, -21, 184, 87, 61, + -272, -78, -66, -10, 14, 12, 12, 54, 214, 84, 1, -231, -92}; + + check_vect (); + + sub_left_prediction_bgr32(dst, src); + +#pragma GCC novector + for (int i = 0; i < 8*3; ++i) + if (dst[i] != dst2[i]) + __builtin_abort(); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-recurr-pr121256.c b/gcc/testsuite/gcc.dg/vect/vect-recurr-pr121256.c new file mode 100644 index 0000000..c895e94 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-recurr-pr121256.c @@ -0,0 +1,54 @@ +/* { dg-additional-options "-mavx2" { target avx2_runtime } } */ + +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include "tree-vect.h" + +#define B 0 +#define G 1 +#define R 2 +#define A 3 + +int red = 153; +int green = 66; +int blue = 187; +int alpha = 255; + +static void __attribute__((noipa)) +sub_left_prediction_bgr32(uint8_t *restrict dst, uint8_t *restrict src, int w) +{ + for (int i = 0; i < 8; i++) { + int rt = src[i * 4 + R]; + int gt = src[i * 4 + G]; + int bt = src[i * 4 + B]; + int at = src[i * 4 + A]; + + dst[i * 4 + R] = rt - red; + dst[i * 4 + G] = gt - green; + dst[i * 4 + B] = bt - blue; + dst[i * 4 + A] = at - alpha; + + red = rt; + green = gt; + blue = bt; + alpha = at; + } +} + +int main() +{ + check_vect (); + + uint8_t *dst = calloc(36, sizeof(uint8_t)); + uint8_t *src = calloc(36, sizeof(uint8_t)); + + src[R] = 160; + src[G] = 73; + src[B] = 194; + src[A] = 255; + + sub_left_prediction_bgr32(dst, src, 33); + if (dst[R] != 7 || dst[B] != 7 || dst[A] != 0) + __builtin_abort(); +} diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-cond-1.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-cond-1.c new file mode 100644 index 0000000..258f17e --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-cond-1.c @@ -0,0 +1,60 @@ +/* { dg-require-effective-target vect_int } */ +/* { dg-require-effective-target vect_condition } */ + +#include <stdarg.h> +#include "tree-vect.h" + +/* PR tree-optimization/119920 */ + +#define N 32 + +unsigned int ub[N]; + +/* Test vectorization of reduction of unsigned-int. */ + +__attribute__ ((noinline, noipa)) +void init(void) +{ + #pragma GCC novector + for(int i = 0;i < N; i++) + ub[i] = i; +} + + +__attribute__ ((noinline, noipa)) +void main1 (unsigned int b, unsigned int c) +{ + int i; + unsigned int usum = 0; + + init(); + + /* Summation. */ + for (i = 0; i < N; i++) { + if ( ub[i] < N/2 ) + { + usum += b; + } + else + { + usum += c; + } + } + + /* check results: */ + /* __builtin_printf("%d : %d\n", usum, (N/2*b + N/2*c)); */ + if (usum != N/2*b + N/2*c) + abort (); +} + +int main (void) +{ + check_vect (); + + main1 (0, 0); + main1 (1, 1); + main1 (10, 1); + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { xfail { vect_no_int_add } } } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-cond-2.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-cond-2.c new file mode 100644 index 0000000..126a50f --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-cond-2.c @@ -0,0 +1,62 @@ +/* { dg-require-effective-target vect_int } */ +/* { dg-require-effective-target vect_condition } */ +/* { dg-additional-options "-fdump-tree-ifcvt-details" } */ + +#include <stdarg.h> +#include "tree-vect.h" + +/* PR tree-optimization/119920 */ + +#define N 32 + +unsigned int ub[N]; +unsigned int ua[N]; + +/* Test vectorization of reduction of unsigned-int. */ + +__attribute__ ((noinline, noipa)) +void init(void) +{ + #pragma GCC novector + for(int i = 0;i < N; i++) { + ub[i] = i; + ua[i] = 1; + } +} + + +__attribute__ ((noinline, noipa)) +void main1 (unsigned int b, unsigned int c) +{ + int i; + unsigned int usum = 0; + + init(); + + /* Summation. */ + for (i = 0; i < N; i++) { + unsigned t = ua[i]; + if ( ub[i] < N/2 ) + usum += b * t; + else + usum += c * t; + } + + /* check results: */ + /* __builtin_printf("%d : %d\n", usum, (N/2*b*1 + N/2*c*1)); */ + if (usum != N/2*b + N/2*c) + abort (); +} + +int main (void) +{ + check_vect (); + + main1 (0, 0); + main1 (1, 1); + main1 (10, 1); + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { xfail { vect_no_int_add } } } } */ +/* { dg-final { scan-tree-dump-times "changed to factor operation out from COND_EXPR" 2 "ifcvt" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-cond-3.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-cond-3.c new file mode 100644 index 0000000..e425869 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-cond-3.c @@ -0,0 +1,56 @@ +/* { dg-require-effective-target vect_int } */ + +#include <stdarg.h> +#include "tree-vect.h" + +/* PR tree-optimization/112324 */ +/* PR tree-optimization/110015 */ + +#define N 32 + +int ub[N]; + +/* Test vectorization of reduction of int max with some extra code involed. */ + +__attribute__ ((noinline, noipa)) +void init(void) +{ + #pragma GCC novector + for(int i = 0;i < N; i++) + ub[i] = (i&4) && (i&1) ? -i : i; +} + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + +__attribute__ ((noinline, noipa)) +void main1 (void) +{ + int i; + int max = 0; + + init(); + + /* Summation. */ + for (i = 0; i < N; i++) { + int tmp = ub[i]; + if (tmp < 0) + max = MAX (-tmp, max); + else + max = MAX (tmp, max); + } + + /* check results: */ + /* __builtin_printf("%d : %d\n", max, N); */ + if (max != N - 1) + abort (); +} + +int main (void) +{ + check_vect (); + + main1 (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { xfail { vect_no_int_min_max } } } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-pr121130.c b/gcc/testsuite/gcc.dg/vect/vect-simd-pr121130.c new file mode 100644 index 0000000..c882ded --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-simd-pr121130.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ + +int n2; + +__attribute__((simd)) char +w7(void) +{ + short int xb = n2; + xb = w7() < 1; + return xb; +} |