mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Most of these are places where we failed to include a header file and simply never got an error about this. The fix is to include the header file. Most other cases are functions that should have been marked `static` but were not. Finding all of these was a main motivation for me enabling the warning despite how much work it is. One complicating factor was that we weren't including the `handle.h` for all the state-based handler functions. While this isn't a tiny amount of code, it is just declarations and doesn't add any extra dependencies. It also lets us have the checking for which functions need to be `static` and which don't. For the `parse` library I had to add the `handle.h` header as well, I tried to match the design of it in `check`. I have also had to work around a bug in the warning, but given the value it seems to be providing, that seems reasonable. I've filed the bug upstream: https://github.com/llvm/llvm-project/issues/94138 I also had to use some hacks to work around limitations of Bazel rules that wrap `cc_library` rules and don't expose `copts`. I filed a bug for `cc_proto_library` specifically: ~https://github.com/bazelbuild/bazel/issues/22610~ https://github.com/bazelbuild/bazel/issues/4446
40 lines
1.4 KiB
C++
40 lines
1.4 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "toolchain/check/pointer_dereference.h"
|
|
|
|
#include "llvm/ADT/STLFunctionalExtras.h"
|
|
#include "toolchain/check/context.h"
|
|
#include "toolchain/check/convert.h"
|
|
#include "toolchain/parse/node_ids.h"
|
|
#include "toolchain/sem_ir/ids.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
auto PerformPointerDereference(
|
|
Context& context, Parse::AnyPointerDeferenceExprId node_id,
|
|
SemIR::InstId base_id,
|
|
llvm::function_ref<auto(SemIR::TypeId not_pointer_type_id)->void>
|
|
diagnose_not_pointer) -> SemIR::InstId {
|
|
// TODO: Once we have a finalized design for a pointer interface, use
|
|
//
|
|
// HandleUnaryOperator(context, node_id, {"Pointer", "Dereference"});
|
|
//
|
|
// to convert to a pointer value.
|
|
base_id = ConvertToValueExpr(context, base_id);
|
|
auto type_id =
|
|
context.GetUnqualifiedType(context.insts().Get(base_id).type_id());
|
|
auto result_type_id = SemIR::TypeId::Error;
|
|
if (auto pointer_type =
|
|
context.types().TryGetAs<SemIR::PointerType>(type_id)) {
|
|
result_type_id = pointer_type->pointee_id;
|
|
} else if (type_id != SemIR::TypeId::Error) {
|
|
diagnose_not_pointer(type_id);
|
|
}
|
|
return context.AddInst<SemIR::Deref>(
|
|
node_id, {.type_id = result_type_id, .pointer_id = base_id});
|
|
}
|
|
|
|
} // namespace Carbon::Check
|