This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libdw: Don't reassign result pointer in dwarf_peel_type.


GCC6 will warn about the reassignement of the nonnull result pointer.
The reassignment is indeed a little questionable. The compiler cannot
see that the pointer will not actually be reassigned since the function
will just return the same pointer value except when the dwarf_formref_die
function fails. In which case we don't use the result anymore. So the
compiler has to pessimistically assume the pointer will need to be
reloaded in the loop every time. Help the compiler generate slightly
better code by just checking whether the function fails directly instead
of reusing the pointer value for this.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdw/ChangeLog         | 4 ++++
 libdw/dwarf_peel_type.c | 5 ++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 13beefc..2e27ff9 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2015-09-15  Mark Wielaard  <mjw@redhat.com>
+
+	* dwarf_peel_type.c (dwarf_peel_type): Don't reassign result pointer.
+
 2015-09-09  Chih-Hung Hsieh  <chh@google.com>
 
 	* dwarf_macro_getsrcfiles.c (dwarf_macro_getsrcfiles): Remove
diff --git a/libdw/dwarf_peel_type.c b/libdw/dwarf_peel_type.c
index 9be838d..7b29d35 100644
--- a/libdw/dwarf_peel_type.c
+++ b/libdw/dwarf_peel_type.c
@@ -1,5 +1,5 @@
 /* Peel type aliases and qualifier tags from a type DIE.
-   Copyright (C) 2014 Red Hat, Inc.
+   Copyright (C) 2014, 2015 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -60,8 +60,7 @@ dwarf_peel_type (die, result)
       if (attr == NULL)
 	return 1;
 
-      result = INTUSE (dwarf_formref_die) (attr, result);
-      if (result == NULL)
+      if (INTUSE (dwarf_formref_die) (attr, result) == NULL)
 	return -1;
 
       tag = INTUSE (dwarf_tag) (result);
-- 
1.8.3.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]