Summary: When C and C++ code handle a common struct typed value, the struct type is handled as a `CStruct` in the C code, but as a `CppClass` in the C++ code. On the other hand, `Fieldname.t` contains a string of field and **the struct type**. As a result, even if a same field is accessed in C and C++ code, the accessed fieldnames are different. ``` void callee_in_c(struct s* x) { x->a = 3; } void caller_in_cpp() { struct s x; x.a = 5; callee_in_c(&x); // HERE } ``` For example, in the above code, `caller_in_cpp` sets the field `a` as 5, then calls `callee_in_c`, which sets the field `a` as 3. However, at `HERE`, the value of `x` in Pulse is `{a -> 5, a -> 3}`, because the two fieldnames are addressed as different ones. To avoid the issue, this diff loosens the fieldname comparison in Pulse. Reviewed By: jvillard Differential Revision: D26000812 fbshipit-source-id: 77142ebdamaster
parent
caa8bd0e39
commit
eeb34231fa
@ -0,0 +1,24 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
SOURCES = $(SOURCES_C) $(SOURCES_CPP)
|
||||
|
||||
ROOT_DIR = $(TESTS_DIR)/../..
|
||||
|
||||
CLEAN_EXTRA += duplicates.txt
|
||||
|
||||
OBJECTS = $(foreach source,$(filter %.c %.cpp %.m %.mm,$(SOURCES)),$(basename $(source)).o)
|
||||
|
||||
include $(TESTS_DIR)/infer.make
|
||||
include $(TESTS_DIR)/clang-base.make
|
||||
|
||||
infer-out$(TEST_SUFFIX)/report.json: $(CLANG_DEPS) $(SOURCES) $(HEADERS) $(TESTS_DIR)/.inferconfig $(MAKEFILE_LIST)
|
||||
$(QUIET)$(call silent_on_success,Testing infer/clang in $(TEST_REL_DIR),\
|
||||
echo $(SOURCES) && \
|
||||
$(INFER_BIN) capture --results-dir $(@D) --dump-duplicate-symbols \
|
||||
$(INFER_OPTIONS) -- clang $(CLANG_OPTIONS_C) $(SOURCES_C) && \
|
||||
$(INFER_BIN) capture --continue --results-dir $(@D) --dump-duplicate-symbols \
|
||||
$(INFER_OPTIONS) -- clang $(CLANG_OPTIONS_CPP) $(SOURCES_CPP) && \
|
||||
$(INFER_BIN) analyze --results-dir $(@D) --dump-duplicate-symbols $(INFER_OPTIONS))
|
@ -0,0 +1,19 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
TESTS_DIR = ../../..
|
||||
|
||||
CLANG_OPTIONS_C = -c
|
||||
CLANG_OPTIONS_CPP = -x c++ -std=c++17 -nostdinc++ -isystem$(CLANG_INCLUDES)/c++/v1/ -c
|
||||
|
||||
INFER_OPTIONS = --pulse-only --debug-exceptions --project-root $(TESTS_DIR) \
|
||||
--pulse-report-latent-issues
|
||||
|
||||
INFERPRINT_OPTIONS = --issues-tests
|
||||
|
||||
SOURCES_C = $(wildcard *.c)
|
||||
SOURCES_CPP = $(wildcard *.cpp)
|
||||
|
||||
include $(TESTS_DIR)/clang-c-cpp.make
|
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "callee_in_c.h"
|
||||
|
||||
void set_field_three(struct s* x) { x->a = 3; }
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
struct s {
|
||||
int a;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void set_field_three(struct s* x);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "callee_in_c.h"
|
||||
|
||||
void call_set_field_three_Ok(int* p) {
|
||||
struct s x;
|
||||
x.a = 5;
|
||||
set_field_three(&x);
|
||||
if (x.a == 5) {
|
||||
free(p);
|
||||
*p = 3;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue