-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
814: Set TREE_ADDRESSABLE when we need to borrow any expression r=philberty a=philberty GCC requires VAR_DECL's and PARAM_DECL's to be marked with TREE_ADDRESSABLE when the declaration will be used in borrow's ('&' getting the address). This takes into account the implicit addresses when we do autoderef in method resolution/operator-overloading. If it is not set we end up in cases like this: ```c i32 main () { i32 a.1; i32 D.86; i32 a; a = 1; a.1 = a; // this is wrong <i32 as AddAssign>::add_assign (&a.1, 2); D.86 = 0; return D.86; } ``` You can see GCC will automatically make a copy of the VAR_DECL resulting bad code-generation. Fixes #804 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
- Loading branch information
Showing
9 changed files
with
344 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (C) 2020-2021 Free Software Foundation, Inc. | ||
|
||
// This file is part of GCC. | ||
|
||
// GCC is free software; you can redistribute it and/or modify it under | ||
// the terms of the GNU General Public License as published by the Free | ||
// Software Foundation; either version 3, or (at your option) any later | ||
// version. | ||
|
||
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY | ||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
// for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with GCC; see the file COPYING3. If not see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
#include "rust-hir-address-taken.h" | ||
#include "rust-hir-full.h" | ||
|
||
namespace Rust { | ||
namespace Resolver { | ||
|
||
AddressTakenContext * | ||
AddressTakenContext::get () | ||
{ | ||
static AddressTakenContext *instance; | ||
if (instance == nullptr) | ||
instance = new AddressTakenContext (); | ||
|
||
return instance; | ||
} | ||
|
||
AddressTakenContext::~AddressTakenContext () {} | ||
|
||
bool | ||
AddressTakenContext::lookup_addess_taken (HirId id, bool *address_taken) const | ||
{ | ||
const auto &it = ctx.find (id); | ||
if (it == ctx.end ()) | ||
return false; | ||
|
||
*address_taken = it->second; | ||
return true; | ||
} | ||
|
||
void | ||
AddressTakenContext::insert_address_taken (HirId id, bool address_taken) | ||
{ | ||
const auto &it = ctx.find (id); | ||
if (it != ctx.end ()) | ||
{ | ||
// assert that we never change a true result to a negative | ||
if (it->second == true) | ||
{ | ||
rust_assert (address_taken != false); | ||
} | ||
} | ||
|
||
ctx[id] = address_taken; | ||
} | ||
|
||
} // namespace Resolver | ||
} // namespace Rust |
Oops, something went wrong.