Skip to content

Commit

Permalink
8307147: [x86] Dangling pointer warning for Assembler::_attributes
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, aph
  • Loading branch information
Kim Barrett committed May 4, 2023
1 parent 64ac9a0 commit 3599448
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/hotspot/cpu/x86/assembler_x86.cpp
Expand Up @@ -217,6 +217,17 @@ void Assembler::init_attributes(void) {
_attributes = nullptr;
}

void Assembler::set_attributes(InstructionAttr* attributes) {
// Record the assembler in the attributes, so the attributes destructor can
// clear the assembler's attributes, cleaning up the otherwise dangling
// pointer. gcc13 has a false positive warning, because it doesn't tie that
// cleanup to the assignment of _attributes here.
attributes->set_current_assembler(this);
PRAGMA_DIAG_PUSH
PRAGMA_DANGLING_POINTER_IGNORED
_attributes = attributes;
PRAGMA_DIAG_POP
}

void Assembler::membar(Membar_mask_bits order_constraint) {
// We only have to handle StoreLoad
Expand Down Expand Up @@ -11442,7 +11453,6 @@ void Assembler::vex_prefix(Address adr, int nds_enc, int xreg_enc, VexSimdPrefix
vex_x = adr.index_needs_rex();
}
set_attributes(attributes);
attributes->set_current_assembler(this);

// For EVEX instruction (which is not marked as pure EVEX instruction) check and see if this instruction
// is allowed in legacy mode and has resources which will fit in it.
Expand Down Expand Up @@ -11489,7 +11499,6 @@ int Assembler::vex_prefix_and_encode(int dst_enc, int nds_enc, int src_enc, VexS
bool vex_b = (src_enc & 8) == 8;
bool vex_x = false;
set_attributes(attributes);
attributes->set_current_assembler(this);

// For EVEX instruction (which is not marked as pure EVEX instruction) check and see if this instruction
// is allowed in legacy mode and has resources which will fit in it.
Expand Down
6 changes: 2 additions & 4 deletions src/hotspot/cpu/x86/assembler_x86.hpp
Expand Up @@ -678,7 +678,8 @@ class Assembler : public AbstractAssembler {
bool _legacy_mode_vlbw;
NOT_LP64(bool _is_managed;)

class InstructionAttr *_attributes;
InstructionAttr *_attributes;
void set_attributes(InstructionAttr* attributes);

// 64bit prefixes
void prefix(Register reg);
Expand Down Expand Up @@ -917,8 +918,6 @@ class Assembler : public AbstractAssembler {
// belong in macro assembler but there is no need for both varieties to exist

void init_attributes(void);

void set_attributes(InstructionAttr *attributes) { _attributes = attributes; }
void clear_attributes(void) { _attributes = nullptr; }

void set_managed(void) { NOT_LP64(_is_managed = true;) }
Expand Down Expand Up @@ -2892,7 +2891,6 @@ class InstructionAttr {
if (_current_assembler != nullptr) {
_current_assembler->clear_attributes();
}
_current_assembler = nullptr;
}

private:
Expand Down
6 changes: 5 additions & 1 deletion src/hotspot/share/utilities/compilerWarnings.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -55,6 +55,10 @@
#define ATTRIBUTE_SCANF(fmt, vargs)
#endif

#ifndef PRAGMA_DANGLING_POINTER_IGNORED
#define PRAGMA_DANGLING_POINTER_IGNORED
#endif

#ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED
#define PRAGMA_FORMAT_NONLITERAL_IGNORED
#endif
Expand Down
7 changes: 6 additions & 1 deletion src/hotspot/share/utilities/compilerWarnings_gcc.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -39,6 +39,11 @@
#define PRAGMA_DIAG_PUSH _Pragma("GCC diagnostic push")
#define PRAGMA_DIAG_POP _Pragma("GCC diagnostic pop")

// Disable -Wdangling-pointer which is introduced in GCC 12.
#if !defined(__clang_major__) && (__GNUC__ >= 12)
#define PRAGMA_DANGLING_POINTER_IGNORED PRAGMA_DISABLE_GCC_WARNING("-Wdangling-pointer")
#endif

#define PRAGMA_FORMAT_NONLITERAL_IGNORED \
PRAGMA_DISABLE_GCC_WARNING("-Wformat-nonliteral") \
PRAGMA_DISABLE_GCC_WARNING("-Wformat-security")
Expand Down

1 comment on commit 3599448

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.