]> sourceware.org Git - libabigail.git/commitdiff
Fix redundant const qualifier stripping
authorDodji Seketeli <dodji@redhat.com>
Mon, 7 Sep 2015 20:37:53 +0000 (22:37 +0200)
committerDodji Seketeli <dodji@redhat.com>
Mon, 7 Sep 2015 21:35:08 +0000 (23:35 +0200)
In the DWARF reader, we strip the const qualifier when it applies to
reference types because a reference is always const.  Those redundant
const qualifiers can later introduce spurious changes in type
comparison.

But then we were forgetting to add the stripped type to the IR, in
some cases.  This patch fixes that.

* include/abg-ir.h (operator&, operator~): Add overloaded bitwise
operators for qualified_type_def::CV.
* src/abg-ir.cc (operator&, operator~): Define them.
* src/abg-dwarf-reader.cc (maybe_strip_qualification): Fix
comment.  If there are multiple qualifiers, only strip the const
one.
(build_ir_node_from_die): Once we've built a qualified type, if
the 'const' qualifier is stripped, then add the new (stripped)
type to the set of new types.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
include/abg-ir.h
src/abg-dwarf-reader.cc
src/abg-ir.cc

index 6957f3f22a626dc395a937513ed86b18d9fa7f32..f193eba5aadd8ceac9a3762547d54153802e34f3 100644 (file)
@@ -1349,6 +1349,12 @@ public:
 qualified_type_def::CV
 operator|(qualified_type_def::CV, qualified_type_def::CV);
 
+qualified_type_def::CV
+operator&(qualified_type_def::CV, qualified_type_def::CV);
+
+qualified_type_def::CV
+operator~(qualified_type_def::CV);
+
 std::ostream&
 operator<<(std::ostream&, qualified_type_def::CV);
 
index d5218e4057dd0c7c5745f9d5bb739c54bc8678b0..0d59f7d050960c5ae71b69a477cbfcbf02b42bb6 100644 (file)
@@ -6759,10 +6759,11 @@ build_qualified_type(read_context&      ctxt,
 /// reference is always const.  The issue is these redundant type then
 /// leaks into the IR and makes for bad diagnostics.
 ///
-/// This function thus strips qualified type in that case.  It might
-/// contain code to strip other cases like this in the future.
+/// This function thus strips the const qualifier from the type in
+/// that case.  It might contain code to strip other cases like this
+/// in the future.
 ///
-/// @param t the type to strip qualification from.
+/// @param t the type to strip const qualification from.
 ///
 /// @return the stripped type or just return @p t.
 static decl_base_sptr
@@ -6771,10 +6772,21 @@ maybe_strip_qualification(const qualified_type_def_sptr t)
   if (!t)
     return t;
 
-  if (dynamic_pointer_cast<reference_type_def>(t->get_underlying_type()))
-    return get_type_declaration(t->get_underlying_type());
+  decl_base_sptr result = t;
+  type_base_sptr u = t->get_underlying_type();
+  if (t->get_cv_quals() & qualified_type_def::CV_CONST
+      && is_reference_type(t->get_underlying_type()))
+    {
+      // Let's strip only the const qualifier.
+      if (qualified_type_def::CV q =
+         (t->get_cv_quals() & ~(qualified_type_def::CV_CONST)))
+       result.reset(new qualified_type_def(u, t->get_cv_quals() | q,
+                                           t->get_location()));
+      else
+       result = get_type_declaration(u);
+    }
 
-  return t;
+  return result;
 }
 
 /// Build a pointer type from a DW_TAG_pointer_type DIE.
@@ -7664,8 +7676,17 @@ build_ir_node_from_die(read_context&     ctxt,
                               where_offset);
        if (q)
          {
-           result = add_decl_to_scope(maybe_strip_qualification(q),
-                                      ctxt.cur_tu()->get_global_scope());
+           // Strip some potentially redundant type qualifiers from
+           // the qualified type we just built.
+           decl_base_sptr d = maybe_strip_qualification(q);
+           type_base_sptr ty = is_type(d);
+           // Associate the die to type ty again because 'ty'might be
+           // different from 'q', because 'ty' is 'q' possibly
+           // stripped from some redundant type qualifier.
+           ctxt.associate_die_to_type(dwarf_dieoffset(die),
+                                      die_is_from_alt_di,
+                                      ty);
+           result = add_decl_to_scope(d, ctxt.cur_tu()->get_global_scope());
            maybe_canonicalize_type(dwarf_dieoffset(die),
                                    die_is_from_alt_di,
                                    ctxt);
index f769d59eec84c0d6570377e2c2717ef02c1cd6d3..81a49a9858af337bdb7c5447b70a84386025659b 100644 (file)
@@ -6295,6 +6295,19 @@ operator| (qualified_type_def::CV lhs,
     (static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs));
 }
 
+/// Overloaded bitwise AND operator for CV qualifiers.
+qualified_type_def::CV
+operator&(qualified_type_def::CV lhs, qualified_type_def::CV rhs)
+{
+    return static_cast<qualified_type_def::CV>
+    (static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs));
+}
+
+/// Overloaded bitwise inverting operator for CV qualifiers.
+qualified_type_def::CV
+operator~(qualified_type_def::CV q)
+{return static_cast<qualified_type_def::CV>(~static_cast<unsigned>(q));}
+
 /// Streaming operator for qualified_type_decl::CV
 ///
 /// @param o the output stream to serialize the cv qualifier to.
This page took 0.10565 seconds and 5 git commands to generate.