Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

src: fix warnings in aliased_buffer #503

Closed
wants to merge 1 commit into from

Conversation

kfarnung
Copy link
Contributor

@kfarnung kfarnung commented Mar 24, 2018

  • Unary minus usages on unsigned type
  • Implicit casts to/from input parameters

Just looking for feedback from this group first, then I'll open a PR upstream. I saw these warnings while working on another issue and I believe these fixes to be equivalent to the implicit conversions that were happening before.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@kfarnung kfarnung self-assigned this Mar 24, 2018
@kfarnung kfarnung requested a review from mike-kaufman March 24, 2018 00:33
@kfarnung
Copy link
Contributor Author

@@ -129,7 +129,7 @@ class AliasedBuffer {

template <typename T>
inline Reference& operator=(const T& val) {
aliased_buffer_->SetValue(index_, val);
aliased_buffer_->SetValue(index_, static_cast<NativeT>(val));
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this does the same as the original code, but I'd prefer a solution where these operators aren't templates and the caller has to think about whether casting is valid. Otherwise we hide all of the danger inside this function instead of getting useful compiler warnings elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

you'd still get compiler warnings w/ static_cast right? I don't remember why these functions were templated instead of taking a NativeT as a param.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the explicit cast tells the compiler that you've carefully thought about what happens here and are okay with a possibly lossy conversion.


In reply to: 177183603 [](ancestors = 177183603)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. So, it would be interesting to see if we could remove the templated functions here & push casts onto the caller. I don't recall why I did it this way previously.

@@ -144,7 +144,7 @@ class AliasedBuffer {

template <typename T>
inline Reference& operator+=(const T& val) {
const T current = aliased_buffer_->GetValue(index_);
const NativeT current = aliased_buffer_->GetValue(index_);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is exactly equivalent to the existing code; it's actually a little better. If NativeT is wider than T, then it used to cast the existing value to T, perform the addition in T-space, and then cast back to NativeT. Now it should perform the addition as whichever is wider of T and NativeT since you're adding one of each, which could plausibly extend beyond the bounds of T.

@mike-kaufman
Copy link
Contributor

lgtm

inline Reference& operator=(const T& val) {
aliased_buffer_->SetValue(index_, val);
inline Reference& operator=(const NativeT& val) {
aliased_buffer_->SetValue(index_, static_cast<NativeT>(val));
Copy link
Contributor

Choose a reason for hiding this comment

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

static_cast [](start = 40, length = 11)

static_cast from NativeT to NativeT is no longer needed

@sethbrenith
Copy link
Contributor

// This is not caught by the template operator= above.

Comment is no longer relevant


Refers to: src/aliased_buffer.h:135 in 7fd4285. [](commit_id = 7fd4285, deletion_comment = False)

Copy link
Contributor

@sethbrenith sethbrenith left a comment

Choose a reason for hiding this comment

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

:shipit:

@kfarnung
Copy link
Contributor Author

@kfarnung
Copy link
Contributor Author

Looks like there's a CI failure on macOS:

not ok 1886 abort/test-abort-backtrace
  ---
  duration_ms: 0.585
  severity: fail
  stack: |-
    assert.js:82
      throw new AssertionError(obj);
      ^
    
    AssertionError [ERR_ASSERTION]: Each frame should start with a frame number:
     1: node::Abort() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
     2: node::Chdir(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
     3: v8::FunctionCallbackData::FunctionInvoked(void*, void**, unsigned short, JsNativeFunctionInfo*, void*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
     4: Js::JavascriptExternalFunction::StdCallExternalFunctionThunk(Js::RecyclableObject*, Js::CallInfo, ...) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
     5: amd64_CallFunction [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
     6: void* Js::JavascriptFunction::CallFunction<true>(Js::RecyclableObject*, void* (*)(Js::RecyclableObject*, Js::CallInfo, ...), Js::Arguments, bool) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
     7: void Js::InterpreterStackFrame::OP_CallCommon<Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallIWithICIndex<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > >(Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallIWithICIndex<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > const*, Js::RecyclableObject*, unsigned int, Js::AuxArray<unsigned int> const*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
     8: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
     9: Js::InterpreterStackFrame::Process() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    10: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    11: Js::InterpreterStackFrame::InterpreterThunk(Js::JavascriptCallStackLayout*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    12: 0x90594054a
    13: amd64_CallFunction [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    14: Js::JavascriptFunction::EntryCall(Js::RecyclableObject*, Js::CallInfo, ...) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    15: amd64_CallFunction [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    16: void* Js::JavascriptFunction::CallFunction<true>(Js::RecyclableObject*, void* (*)(Js::RecyclableObject*, Js::CallInfo, ...), Js::Arguments, bool) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    17: void Js::InterpreterStackFrame::OP_CallCommon<Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallIWithICIndex<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > >(Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallIWithICIndex<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > const*, Js::RecyclableObject*, unsigned int, Js::AuxArray<unsigned int> const*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    18: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    19: Js::InterpreterStackFrame::Process() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    20: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    21: Js::InterpreterStackFrame::InterpreterThunk(Js::JavascriptCallStackLayout*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    22: 0x90594058a
    23: amd64_CallFunction [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    24: void* Js::JavascriptFunction::CallFunction<true>(Js::RecyclableObject*, void* (*)(Js::RecyclableObject*, Js::CallInfo, ...), Js::Arguments, bool) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    25: void Js::InterpreterStackFrame::OP_CallCommon<Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallIWithICIndex<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > >(Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallIWithICIndex<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > const*, Js::RecyclableObject*, unsigned int, Js::AuxArray<unsigned int> const*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    26: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    27: Js::InterpreterStackFrame::Process() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    28: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    29: Js::InterpreterStackFrame::InterpreterThunk(Js::JavascriptCallStackLayout*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    30: 0x905940652
    31: amd64_CallFunction [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    32: void* Js::JavascriptFunction::CallFunction<true>(Js::RecyclableObject*, void* (*)(Js::RecyclableObject*, Js::CallInfo, ...), Js::Arguments, bool) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    33: void Js::InterpreterStackFrame::OP_CallCommon<Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallI<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > >(Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallI<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > const*, Js::RecyclableObject*, unsigned int, Js::AuxArray<unsigned int> const*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    34: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    35: Js::InterpreterStackFrame::Process() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    36: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    37: Js::InterpreterStackFrame::InterpreterThunk(Js::JavascriptCallStackLayout*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    38: 0x90594067a
    39: amd64_CallFunction [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    40: void* Js::JavascriptFunction::CallFunction<true>(Js::RecyclableObject*, void* (*)(Js::RecyclableObject*, Js::CallInfo, ...), Js::Arguments, bool) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    41: void Js::InterpreterStackFrame::OP_CallCommon<Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallIWithICIndex<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > >(Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallIWithICIndex<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > const*, Js::RecyclableObject*, unsigned int, Js::AuxArray<unsigned int> const*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    42: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    43: Js::InterpreterStackFrame::Process() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    44: Js::InterpreterStackFrame::ProcessTryFinally(unsigned char const*, short, unsigned int, unsigned int, bool) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    45: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    46: Js::InterpreterStackFrame::Process() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    47: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    48: Js::InterpreterStackFrame::InterpreterThunk(Js::JavascriptCallStackLayout*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    49: 0x905940682
    50: amd64_CallFunction [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    51: void* Js::JavascriptFunction::CallFunction<true>(Js::RecyclableObject*, void* (*)(Js::RecyclableObject*, Js::CallInfo, ...), Js::Arguments, bool) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    52: void Js::InterpreterStackFrame::OP_CallCommon<Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallI<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > >(Js::OpLayoutDynamicProfile<Js::OpLayoutT_CallI<Js::LayoutSizePolicy<(Js::LayoutSize)0> > > const*, Js::RecyclableObject*, unsigned int, Js::AuxArray<unsigned int> const*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    53: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    54: Js::InterpreterStackFrame::Process() [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    55: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    56: Js::InterpreterStackFrame::InterpreterThunk(Js::JavascriptCallStackLayout*) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    57: 0x905940732
    58: amd64_CallFunction [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    59: void* Js::JavascriptFunction::CallFunction<true>(Js::RecyclableObject*, void* (*)(Js::RecyclableObject*, Js::CallInfo, ...), Js::Arguments, bool) [/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/out/Release/node]
    60: 
    Js::InterpreterStackFrame::ProcessUnprofiled()
    Js::InterpreterStackFrame::Process()
    
    Js::InterpreterStackFrame::InterpreterThunk(Js::JavascriptCallStackLayout*)
    
    amd64_CallFunction
    
    
    
    
    
    
    
    amd64_CallFunction
    
    
    
    
    
    
    
       at Anonymous function (/Users/iojs/build/workspace/chakracore-test-osx/nodes/osx1010/test/abort/test-abort-backtrace.js:18:7)
       at Module.prototype._compile (internal/modules/cjs/loader.js:677:5)
       at Module._extensions[.js] (internal/modules/cjs/loader.js:688:3)
       at Module.prototype.load (internal/modules/cjs/loader.js:588:3)
       at tryModuleLoad (internal/modules/cjs/loader.js:527:5)
       at Module._load (internal/modules/cjs/loader.js:519:3)
       at Module.runMain (internal/modules/cjs/loader.js:718:3)
  …

I'll have to investigate that before taking this upstream.

* Unary minus usages on unsigned type
* Implicit casts to/from input parameters
@kfarnung
Copy link
Contributor Author

@kfarnung
Copy link
Contributor Author

Opened upstream PR: nodejs/node#19665

@kfarnung
Copy link
Contributor Author

Landed upstream PR nodejs/node#19665

@kfarnung kfarnung closed this Mar 31, 2018
@kfarnung kfarnung deleted the ab_warnings branch March 31, 2018 06:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants