1#!/usr/bin/env python3
2
3# Copyright (C) 2020 Free Software Foundation, Inc.
4#
5# This file is part of GCC.
6#
7# GCC is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3, or (at your option)
10# any later version.
11#
12# GCC is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with GCC; see the file COPYING.  If not, write to
19# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20# Boston, MA 02110-1301, USA.
21
22# This script parses a .diff file generated with 'diff -up' or 'diff -cp'
23# and adds a skeleton ChangeLog file to the file. It does not try to be
24# too smart when parsing function names, but it produces a reasonable
25# approximation.
26#
27# Author: Martin Liska <mliska@suse.cz>
28
29import unittest
30
31from mklog import generate_changelog
32
33import unidiff
34
35unidiff_supports_renaming = hasattr(unidiff.PatchedFile(), 'is_rename')
36
37
38PATCH1 = '''\
39diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h
40index 567c23380fe..e6209ede9d6 100644
41--- a/gcc/config/riscv/riscv.h
42+++ b/gcc/config/riscv/riscv.h
43@@ -920,6 +920,7 @@ extern unsigned riscv_stack_boundary;
44 #define SHIFT_RS1 15
45 #define SHIFT_IMM 20
46 #define IMM_BITS 12
47+#define C_S_BITS 5
48 #define C_SxSP_BITS 6
49
50 #define IMM_REACH (1LL << IMM_BITS)
51@@ -929,6 +930,10 @@ extern unsigned riscv_stack_boundary;
52 #define SWSP_REACH (4LL << C_SxSP_BITS)
53 #define SDSP_REACH (8LL << C_SxSP_BITS)
54
55+/* This is the maximum value that can be represented in a compressed load/store
56+   offset (an unsigned 5-bit value scaled by 4).  */
57+#define CSW_MAX_OFFSET ((4LL << C_S_BITS) - 1) & ~3
58+
59 /* Called from RISCV_REORG, this is defined in riscv-sr.c.  */
60
61 extern void riscv_remove_unneeded_save_restore_calls (void);
62
63'''
64
65EXPECTED1 = '''\
66gcc/ChangeLog:
67
68	* config/riscv/riscv.h (C_S_BITS):
69	(CSW_MAX_OFFSET):
70
71'''
72
73PATCH2 = '''\
74diff --git a/gcc/targhooks.h b/gcc/targhooks.h
75index 9704d23f1db..b572a36e8cf 100644
76--- a/gcc/targhooks.h
77+++ b/gcc/targhooks.h
78@@ -120,7 +120,7 @@ extern bool default_empty_mask_is_expensive (unsigned);
79 extern void *default_init_cost (class loop *);
80 extern unsigned default_add_stmt_cost (class vec_info *, void *, int,
81 				       enum vect_cost_for_stmt,
82-				       class _stmt_vec_info *, int,
83+				       class _stmt_vec_info *, tree, int,
84 				       enum vect_cost_model_location);
85 extern void default_finish_cost (void *, unsigned *, unsigned *, unsigned *);
86 extern void default_destroy_cost_data (void *);
87@@ -186,6 +186,7 @@ extern tree default_emutls_var_init (tree, tree, tree);
88 extern unsigned int default_hard_regno_nregs (unsigned int, machine_mode);
89 extern bool default_hard_regno_scratch_ok (unsigned int);
90 extern bool default_mode_dependent_address_p (const_rtx, addr_space_t);
91+extern bool default_new_address_profitable_p (rtx, rtx_insn *, rtx);
92 extern bool default_target_option_valid_attribute_p (tree, tree, tree, int);
93 extern bool default_target_option_pragma_parse (tree, tree);
94 extern bool default_target_can_inline_p (tree, tree);
95
96'''
97
98EXPECTED2 = '''\
99gcc/ChangeLog:
100
101	* targhooks.h (default_add_stmt_cost):
102	(default_new_address_profitable_p):
103
104'''
105
106PATCH3 = '''\
107diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
108index 2b1e33f94ae..7f47402f9b9 100644
109--- a/libcpp/include/cpplib.h
110+++ b/libcpp/include/cpplib.h
111@@ -173,7 +173,7 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X,
112 	     CLK_STDC2X,
113 	     CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
114 	     CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
115-	     CLK_GNUCXX2A, CLK_CXX2A, CLK_ASM};
116+	     CLK_GNUCXX20, CLK_CXX20, CLK_ASM};
117
118 /* Payload of a NUMBER, STRING, CHAR or COMMENT token.  */
119 struct GTY(()) cpp_string {
120@@ -484,7 +484,7 @@ struct cpp_options
121   /* Nonzero for C2X decimal floating-point constants.  */
122   unsigned char dfp_constants;
123
124-  /* Nonzero for C++2a __VA_OPT__ feature.  */
125+  /* Nonzero for C++20 __VA_OPT__ feature.  */
126   unsigned char va_opt;
127
128   /* Nonzero for the '::' token.  */
129
130'''
131
132EXPECTED3 = '''\
133libcpp/ChangeLog:
134
135	* include/cpplib.h (enum c_lang):
136	(struct cpp_options):
137
138'''
139
140EXPECTED3B = '''\
141libcpp/ChangeLog:
142
143	* include/cpplib.h:
144
145'''
146
147PATCH4 = '''\
148diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
149index aab79492357..f0df1002488 100644
150--- a/gcc/ipa-icf.c
151+++ b/gcc/ipa-icf.c
152@@ -1,5 +1,7 @@
153
154
155+
156+
157 /* Interprocedural Identical Code Folding pass
158    Copyright (C) 2014-2020 Free Software Foundation, Inc.
159
160diff --git a/gcc/testsuite/gcc.dg/pr32374.c b/gcc/testsuite/gcc.dg/pr32374.c
161deleted file mode 100644
162index de15d559f5b..00000000000
163--- a/gcc/testsuite/gcc.dg/pr32374.c
164+++ /dev/null
165@@ -1,20 +0,0 @@
166-/* { dg-do compile } */
167-/* { dg-options "-O2" } */
168-
169-extern int *stderr;
170-
171-void f (int *, const char *, ...);
172-
173-void g (const char *conf_name)
174-{
175-  typedef struct
176-  {
177-    const char *label;
178-    const int value;
179-  } Section;
180-
181-  const Section sections[2] = { {"", 0}, {"", 1} };
182-
183-  f (stderr, "", "", conf_name, 0, sections[0]);
184-  f (stderr, "", "", conf_name, 0, sections[0]);
185-}
186diff --git a/gcc/testsuite/gcc.dg/pr40209.c b/gcc/testsuite/gcc.dg/pr40209.c
187index 4e77df5c2e6..c23d69d1f1b 100644
188--- a/gcc/testsuite/gcc.dg/pr40209.c
189+++ b/gcc/testsuite/gcc.dg/pr40209.c
190@@ -1,6 +1,8 @@
191 /* { dg-do compile } */
192 /* { dg-options "-O2 -fprofile-use -fopt-info -Wno-missing-profile" } */
193
194+
195+
196 void process(const char *s);
197
198 struct BaseHolder {
199diff --git a/gcc/testsuite/gcc.dg/pr50209.c b/gcc/testsuite/gcc.dg/pr50209.c
200new file mode 100644
201index 00000000000..b28b04f6431
202--- /dev/null
203+++ b/gcc/testsuite/gcc.dg/pr50209.c
204@@ -0,0 +1,3 @@
205+
206+
207+
208diff --git a/gcc/testsuite/gcc.dg/pr63567-1.c b/gcc/testsuite/gcc.dg/pr63567-1.c
209index 97da171563e..00c5ecc11fa 100644
210--- a/gcc/testsuite/gcc.dg/pr63567-1.c
211+++ b/gcc/testsuite/gcc.dg/pr63567-1.c
212@@ -1,3 +1,4 @@
213+
214 /* PR c/63567 */
215 /* { dg-do compile } */
216 /* { dg-options "" } */
217diff --git a/gcc/varasm.c b/gcc/varasm.c
218index f062e48071f..fd3c7ca8cf3 100644
219--- a/gcc/varasm.c
220+++ b/gcc/varasm.c
221@@ -1,3 +1,5 @@
222+
223+
224 /* Output variables, constants and external declarations, for GNU compiler.
225    Copyright (C) 1987-2020 Free Software Foundation, Inc.
226
227diff --git a/libssp/gets-chk.c b/libssp/gets-chk.c
228index 4ad78c1f77b..6687b368038 100644
229--- a/libssp/gets-chk.c
230+++ b/libssp/gets-chk.c
231@@ -32,6 +32,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
232 <http://www.gnu.org/licenses/>.  */
233
234
235+
236+
237 #include "config.h"
238 #include <ssp/ssp.h>
239 #include <stdarg.h>
240'''
241
242EXPECTED4 = '''\
243
244	PR 50209
245
246gcc/ChangeLog:
247
248	* ipa-icf.c:
249	* varasm.c:
250
251libssp/ChangeLog:
252
253	* gets-chk.c:
254
255gcc/testsuite/ChangeLog:
256
257	* gcc.dg/pr40209.c:
258	* gcc.dg/pr63567-1.c:
259	* gcc.dg/pr32374.c: Removed.
260	* gcc.dg/pr50209.c: New test.
261
262'''
263
264PATCH5 = '''\
265diff --git a/gcc/testsuite/gcc.target/i386/pr95046-6.c b/gcc/testsuite/gcc.target/i386/pr95046-6.c
266new file mode 100644
267index 00000000000..dcc8999c446
268--- /dev/null
269+++ b/gcc/testsuite/gcc.target/i386/pr95046-6.c
270@@ -0,0 +1,44 @@
271+/* PR target/95046 */
272+/* { dg-do compile { target { ! ia32 } } } */
273+/* { dg-options "-O3 -mavx512vl" } */
274+
275+
276+double r[2];
277+int s[2];
278+unsigned int u[2];
279+
280+void
281+test_float (void)
282+{
283+  for (int i = 0; i < 2; i++)
284+    r[i] = s[i];
285+}
286+
287+/* { dg-final { scan-assembler "\tvcvtdq2pd" } } */
288+
289+void
290+test_ufloat (void)
291+{
292+  for (int i = 0; i < 2; i++)
293+    r[i] = u[i];
294+}
295+
296+/* { dg-final { scan-assembler "\tvcvtudq2pd" } } */
297+
298+void
299+test_fix (void)
300+{
301+  for (int i = 0; i < 2; i++)
302+    s[i] = r[i];
303+}
304+
305+/* { dg-final { scan-assembler "\tvcvttpd2dqx" } } */
306+
307+void
308+test_ufix (void)
309+{
310+  for (int i = 0; i < 2; i++)
311+    u[i] = r[i];
312+}
313+
314+/* { dg-final { scan-assembler "\tvcvttpd2udqx" } } */
315--
3162.26.2
317
318'''
319
320EXPECTED5 = '''\
321PR target/95046 - Vectorize V2SFmode operations
322
323	PR target/95046
324
325gcc/testsuite/ChangeLog:
326
327	* gcc.target/i386/pr95046-6.c: New test.
328
329'''
330
331PATCH6 = '''\
332diff --git a/gcc/cgraph.h b/gcc/cgraph.h
333index 5ddeb65269b..cfae6e91da9 100644
334--- a/gcc/cgraph.h
335+++ b/gcc/cgraph.h
336@@ -937,7 +937,8 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node
337       split_part (false), indirect_call_target (false), local (false),
338       versionable (false), can_change_signature (false),
339       redefined_extern_inline (false), tm_may_enter_irr (false),
340-      ipcp_clone (false), m_uid (uid), m_summary_id (-1)
341+      ipcp_clone (false), declare_variant_alt (false),
342+      calls_declare_variant_alt (false), m_uid (uid), m_summary_id (-1)
343   {}
344
345   /* Remove the node from cgraph and all inline clones inlined into it.
346
347'''
348
349EXPECTED6 = '''\
350gcc/ChangeLog:
351
352	* cgraph.h (struct cgraph_node):
353
354'''
355
356PATCH7 = '''\
357diff --git a/gcc/testsuite/g++.dg/DRs/dr2237.C b/gcc/testsuite/g++.dg/DRs/dr2237.C
358new file mode 100644
359index 00000000000..f3d6d11e61e
360--- /dev/null
361+++ b/gcc/testsuite/g++.dg/DRs/dr2237.C
362@@ -0,0 +1,18 @@
363+// DR 2237 - Can a template-id name a constructor?
364+
365+template<class T>
366+struct X {
367+  X<T>(); // { dg-error "expected" "" { target c++20 } }
368+  X(int); // OK, injected-class-name used
369+  ~X<T>(); // { dg-error "template-id not allowed for destructor" "" { target c++20 } }
370+};
371+
372+// ill-formed since DR1435
373+template<typename T> X<T>::X<T>() {} // { dg-error "names the constructor|as no template constructors" }
374+template<typename T> X<T>::~X<T>() {} // { dg-error "template-id not allowed for destructor" "" { target c++20 } }
375+
376+struct Q {
377+  // ill-formed since DR1435
378+  template<typename T> friend X<T>::X<T>(); // { dg-error "names the constructor|as no template constructors" }
379+  template<typename T> friend X<T>::~X<T>(); // { dg-error "template-id not allowed for destructor" "" { target c++20 } }
380+};
381'''
382
383EXPECTED7 = '''\
384
385	DR 2237
386
387gcc/testsuite/ChangeLog:
388
389	* g++.dg/DRs/dr2237.C: New test.
390
391'''
392
393PATCH8 = '''\
394diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf2.c
395similarity index 100%
396rename from gcc/ipa-icf.c
397rename to gcc/ipa-icf2.c
398'''
399
400EXPECTED8 = '''\
401gcc/ChangeLog:
402
403	* ipa-icf.c: Moved to...
404	* ipa-icf2.c: ...here.
405
406'''
407
408PATCH9 = '''\
409diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
410index 2a260c1cfbd..7f03fc491c3 100644
411--- a/gcc/config/i386/sse.md
412+++ b/gcc/config/i386/sse.md
413@@ -17611,6 +17611,23 @@ (define_insn "avx2_<code>v16qiv16hi2<mask_name>"
414    (set_attr "prefix" "maybe_evex")
415    (set_attr "mode" "OI")])
416
417+(define_insn_and_split "*avx2_zero_extendv16qiv16hi2_1"
418+  [(set (match_operand:V32QI 0 "register_operand" "=v")
419+	(vec_select:V32QI
420+	  (vec_concat:V64QI
421+	    (match_operand:V32QI 1 "nonimmediate_operand" "vm")
422+	    (match_operand:V32QI 2 "const0_operand" "C"))
423+	  (match_parallel 3 "pmovzx_parallel"
424+	    [(match_operand 4 "const_int_operand" "n")])))]
425+  "TARGET_AVX2"
426+  "#"
427+  "&& reload_completed"
428+  [(set (match_dup 0) (zero_extend:V16HI (match_dup 1)))]
429+{
430+  operands[0] = lowpart_subreg (V16HImode, operands[0], V32QImode);
431+  operands[1] = lowpart_subreg (V16QImode, operands[1], V32QImode);
432+})
433+
434 (define_expand "<insn>v16qiv16hi2"
435   [(set (match_operand:V16HI 0 "register_operand")
436 	(any_extend:V16HI
437'''
438
439EXPECTED9 = '''\
440gcc/ChangeLog:
441
442	* config/i386/sse.md (*avx2_zero_extendv16qiv16hi2_1):
443
444'''
445
446class TestMklog(unittest.TestCase):
447    def test_macro_definition(self):
448        changelog = generate_changelog(PATCH1)
449        assert changelog == EXPECTED1
450
451    def test_changed_argument(self):
452        changelog = generate_changelog(PATCH2)
453        assert changelog == EXPECTED2
454
455    def test_enum_and_struct(self):
456        changelog = generate_changelog(PATCH3)
457        assert changelog == EXPECTED3
458
459    def test_no_function(self):
460        changelog = generate_changelog(PATCH3, True)
461        assert changelog == EXPECTED3B
462
463    def test_sorting(self):
464        changelog = generate_changelog(PATCH4)
465        assert changelog == EXPECTED4
466
467    def test_pr_bugzilla_download(self):
468        changelog = generate_changelog(PATCH5, fill_pr_titles=True)
469        assert changelog == EXPECTED5
470
471    def test_gty_in_struct(self):
472        changelog = generate_changelog(PATCH6, fill_pr_titles=True)
473        assert changelog == EXPECTED6
474
475    def test_dr_detection_in_test_case(self):
476        changelog = generate_changelog(PATCH7)
477        assert changelog == EXPECTED7
478
479    @unittest.skipIf(not unidiff_supports_renaming,
480                     'Newer version of unidiff is needed (0.6.0+)')
481    def test_renaming(self):
482        changelog = generate_changelog(PATCH8)
483        assert changelog == EXPECTED8
484
485    def test_define_macro_parsing(self):
486        changelog = generate_changelog(PATCH9)
487        assert changelog == EXPECTED9
488