LCOV - code coverage report
Current view: top level - gcc/go/gofrontend - unsafe.cc (source / functions) Hit Total Coverage
Test: gcc.info Lines: 47 49 95.9 %
Date: 2020-03-28 11:57:23 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // unsafe.cc -- Go frontend builtin unsafe package.
       2                 :            : 
       3                 :            : // Copyright 2009 The Go Authors. All rights reserved.
       4                 :            : // Use of this source code is governed by a BSD-style
       5                 :            : // license that can be found in the LICENSE file.
       6                 :            : 
       7                 :            : #include "go-system.h"
       8                 :            : 
       9                 :            : #include "go-c.h"
      10                 :            : #include "types.h"
      11                 :            : #include "gogo.h"
      12                 :            : 
      13                 :            : // Set up the builtin unsafe package.  This should probably be driven
      14                 :            : // by a table.
      15                 :            : 
      16                 :            : void
      17                 :       1192 : Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported,
      18                 :            :                     Location location)
      19                 :            : {
      20                 :       1192 :   Location bloc = Linemap::predeclared_location();
      21                 :            : 
      22                 :       1192 :   bool add_to_globals;
      23                 :       2384 :   Package* package = this->add_imported_package("unsafe", local_name,
      24                 :            :                                                 is_local_name_exported,
      25                 :            :                                                 "unsafe", "unsafe", location,
      26                 :       1192 :                                                 &add_to_globals);
      27                 :            : 
      28                 :       1192 :   if (package == NULL)
      29                 :            :     {
      30                 :          0 :       go_assert(saw_errors());
      31                 :          0 :       return;
      32                 :            :     }
      33                 :            : 
      34                 :       1192 :   package->set_location(location);
      35                 :       1192 :   this->imports_.insert(std::make_pair("unsafe", package));
      36                 :            : 
      37                 :       1192 :   Bindings* bindings = package->bindings();
      38                 :            : 
      39                 :            :   // The type may have already been created by an import.
      40                 :       1192 :   Named_object* no = package->bindings()->lookup("Pointer");
      41                 :       1192 :   if (no == NULL)
      42                 :            :     {
      43                 :        147 :       Type* type = Type::make_pointer_type(Type::make_void_type());
      44                 :        294 :       no = bindings->add_type("Pointer", package, type,
      45                 :            :                               Linemap::unknown_location());
      46                 :            :     }
      47                 :            :   else
      48                 :            :     {
      49                 :       1045 :       go_assert(no->package() == package);
      50                 :       1045 :       go_assert(no->is_type());
      51                 :       1045 :       go_assert(no->type_value()->is_unsafe_pointer_type());
      52                 :       1045 :       no->type_value()->set_is_visible();
      53                 :            :     }
      54                 :       1192 :   Named_type* pointer_type = no->type_value();
      55                 :       1192 :   if (add_to_globals)
      56                 :          2 :     this->add_named_type(pointer_type);
      57                 :            : 
      58                 :       1192 :   Type* uintptr_type = Type::lookup_integer_type("uintptr");
      59                 :            : 
      60                 :            :   // Sizeof.
      61                 :       1192 :   Typed_identifier_list* results = new Typed_identifier_list;
      62                 :       1192 :   results->push_back(Typed_identifier("", uintptr_type, bloc));
      63                 :       1192 :   Function_type* fntype = Type::make_function_type(NULL, NULL, results, bloc);
      64                 :       1192 :   fntype->set_is_builtin();
      65                 :       1192 :   no = bindings->add_function_declaration("Sizeof", package, fntype, bloc);
      66                 :       1192 :   if (add_to_globals)
      67                 :          2 :     this->add_dot_import_object(no);
      68                 :            : 
      69                 :            :   // Offsetof.
      70                 :       1192 :   results = new Typed_identifier_list;
      71                 :       1192 :   results->push_back(Typed_identifier("", uintptr_type, bloc));
      72                 :       1192 :   fntype = Type::make_function_type(NULL, NULL, results, bloc);
      73                 :       1192 :   fntype->set_is_varargs();
      74                 :       1192 :   fntype->set_is_builtin();
      75                 :       1192 :   no = bindings->add_function_declaration("Offsetof", package, fntype, bloc);
      76                 :       1192 :   if (add_to_globals)
      77                 :          2 :     this->add_dot_import_object(no);
      78                 :            : 
      79                 :            :   // Alignof.
      80                 :       1192 :   results = new Typed_identifier_list;
      81                 :       1192 :   results->push_back(Typed_identifier("", uintptr_type, bloc));
      82                 :       1192 :   fntype = Type::make_function_type(NULL, NULL, results, bloc);
      83                 :       1192 :   fntype->set_is_varargs();
      84                 :       1192 :   fntype->set_is_builtin();
      85                 :       1192 :   no = bindings->add_function_declaration("Alignof", package, fntype, bloc);
      86                 :       1192 :   if (add_to_globals)
      87                 :          2 :     this->add_dot_import_object(no);
      88                 :            : 
      89                 :       1192 :   if (!this->imported_unsafe_)
      90                 :            :     {
      91                 :        243 :       go_imported_unsafe();
      92                 :        243 :       this->imported_unsafe_ = true;
      93                 :            :     }
      94                 :            : }

Generated by: LCOV version 1.0

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto --enable-host-shared. GCC test suite is run with the built compiler.