{'fraction_non_alphanumeric': 0.032624849614304924, 'fraction_numerical': 0.011700596824797717, 'mean_word_length': 4.914887679642807, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Ranking Warnings of Static Analysis Tools Using Representation Learning

Static analysis tools are frequently used to detect potential vulnerabilities in software systems. However, an inevitable problem of these tools is their large number of warnings with a high false positive rate, which consumes time and effort for investigating. In this paper, we present DeFP, a novel method for ranking static analysis warnings. Based on the intuition that warnings which have similar contexts tend to have similar labels (true positive or false positive), DeFP is built with two BiLSTM models to capture the patterns associated with the contexts of labeled warnings. After that, for a set of new warnings, DeFP can calculate and rank them according to their likelihoods to be true positives (i.e., actual vulnerabilities). Our experimental results on a dataset of 10 real-world projects show that using DeFP, by investigating only 60% of the warnings, developers can find +90% of actual vulnerabilities. Moreover, DeFP improves the state-of-the-art approach 30% in both Precision and Recall.


I. INTRODUCTION
In order to guarantee the quality of software, many techniques such as code review, automatic static analysis, and testing, etc. have been applied during the software development life cycle. Especially, static analysis [1], [2] plays an important role in detecting vulnerabilities at the early phases. Without executing programs, static analysis (SA) tools analyze the source code to identify the violations of the pre-defined rules and recommendations. These rules and recommendations are often defined by coding standards such as SEI CERT Coding Rule [3] or MISRA [4].
However, SA tools often report a large number of warnings (a.k.a. alarms) [5]. In particular, a warning indicates the statement containing the potential vulnerability, the vulnerability type, and often the additional meta-information [6]. In practice, developers have to manually inspect all the reported warnings and address them if necessary. However, due to the conservative over-approximation of program behaviors/properties of SA, many warnings are incorrectly reported by tools (i.e., false positive warnings). Among the reported warnings, true positive warnings or true positives (TPs) are actual vulnerabilities, while false positive warnings or false positives (FPs) are the positions which indeed do not violate the checking rules. Investigating FPs consumes time and effort but does not bring any benefit, therefore, the high FP rate reduces the productivity of developers [7], [8] and is bad for the usability of SA tools [7], [9]. In consequence, it is necessary to reduce the number of FPs that developers need to verify.
In previous studies, sophisticated techniques such as model checking and symbolic execution have been applied to eliminate FPs [10]- [12]. Although these approaches obtain high precision in identifying FPs, they generally face nonscalability and time consuming issues because of their state space problems [13].
With the growth in size and complexity of the source code, recently machine learning (ML) techniques are leveraged to build models for discovering patterns associated with TPs/FPs. In general, detecting TPs/FPs among SA warnings can be considered as a standard binary classification problem. To build a SA waning classification model, there are two main methods for extracting features from the warnings, one uses a pre-defined set of features and the other encodes the features by ML models. Then, from the extracted features, the ML models need to predict whether the SA warning is a TP or FP.
In several existing studies [6], [14], [15], the fixed sets of the hand-engineered features based on static code metrics and warning information have been derived from the source code and then fed to classifiers. The effectiveness of these approaches depends on the quality of the selected set of features. Moreover, the features in these approaches are manually defined by experts for certain kinds of warnings, therefore it is difficult to extend for handling different ones.
Meanwhile, instead of using a fixed pre-defined set of features, Lee et al. [16] proposed a model to learn the lexical patterns of the statements around the warnings at the source code token level. They used Word2vec [17] to embed code tokens into the vector form and then trained a Convolutional Neural Networks (CNN) classifier. Specially, by investigating their projects, they define the number of surrounding statements that need to be extracted to reflect the contexts of the warnings. These numbers of extracted statements are different for their six proposed checkers. However, it is challenging to apply this approach for different projects and/or different kinds of warnings since it requires expert knowledge and carefully manual investigation to decide how many statements in each function are enough to capture the contexts of the checking warnings. Moreover, not every statement surrounding a warning is all related to its violation and equally important for TP/FP detection. Also, warning unrelated statements would negatively affect the performance of the ML models.
In this paper, we propose DEFP, a novel method to prioritize SA warnings. Instead of classifying SA warnings, DEFP predicts their likelihoods to be TPs and then ranks them with the top entries are more likely to be TPs (actual vulnerabilities), and the last entries are more likely to be FPs. Indeed, ranking SA warnings rather than classifying them gives us three following benefits.
First, for developers, DEFP helps shorten the cycle of developing and releasing products, especially for critical systems. The reason is that critical systems are highly required to be safe, secure, and reliable. Therefore, any potential vulnerabilities (warnings) are all needed to be addressed. In other words, if a warning is eliminated due to being falsely classified as an FP, it would cause the system to be dangerously explored in the future. Instead of directly eliminating any warnings classified as FP, DEFP ranks SA warnings according to their vulnerable likelihoods. With the pressure to release the highquality software on time, focusing on the top-ranked warnings first helps developers to find more actual vulnerabilities in a fixed duration. Then, they can spend time and effort on the low-ranked warnings later.
Second, for SA tool builders, DEFP suggests case studies that they can examine to improve the quality of their tools. Indeed, to better serve the market, SA tool builders need to frequently improve their tools by not only increasing the TP rate, but also decreasing the FP rate. Among a huge number of reported warnings in various projects, DEFP suggests an effective order for investigation. Specially, SA tool builders can directly concentrate on addressing warnings which are more likely to be FPs, i.e., warnings at the last of the resulting lists, to find the patterns which tends to be incorrectly reported.
Third, for researchers, to build the datasets of real-world warnings, DEFP helps the data collection process be more efficient. In practice, in this field, it still lacks public datasets for evaluating approaches and researchers often have to manually investigate to label warnings. This process is extremely timeconsuming. From the ranked lists of DEFP, researchers can effectively collect warnings by selectively labeling top-ranked and last-ranked warnings.
Our key idea is based on the intuition that warnings which have similar contexts tend to have similar labels (TP or FP). For each warning, DEFP exploits both syntax and semantics from the context of the warning and then determines its likelihood to be TP. In order to capture the context of a warning, DEFP extracts all of the statements in the program which impact and are impacted by the statement containing the warning (the reported statement). After that, to better represent the general patterns of warnings, identifiers and literals, which are specific for functions/files/projects and could make the ML models be biased by the training source code, are replaced by abstract names. Next, the reported statements and their contexts are vectorized and used to train neural network models. One of the models represents the information specifically included in the reported statements, while the other extracts critical information in the warning contexts. Then, the high-level features encoded from these models are utilized to estimate the likelihoods to be TPs of the corresponding warnings. Lastly, SA warnings are ranked according to their predicted scores.  To the best of our knowledge, it still lacks a public realworld dataset for widely evaluating approaches post-handling SA warnings. In existing studies [6], [14], [15], ML models are often trained and tested on synthetic datasets, such as Juliet [18] and SARD [19]. However, Chakraborty et al. [20] has demonstrated that these datasets are quite simple for estimating the performance of ML models on real-world data. Thus, to address the limitation of data shortage, we propose a dataset containing 6,620 warnings of 10 real-world projects.
Our experiments show that about 60% of actual vulnerabilities are ranked by DEFP in Top-20% of warnings. Moreover, +90% of actual vulnerabilities can be found by investigating only 60% of the total warnings. Meanwhile, by using the stateof-the-art approach [16], with the same number of examined warnings, developers can find only 46% and 82% TPs.
In summary, our contributions in this paper are: • A novel approach to rank SA warnings, which does not require feature engineering and could be flexible to extend for different kinds of warnings. • A public dataset of 6,620 warnings collected from 10 real-world projects, which can be used as a benchmark for evaluating related work. • An extensive experimental evaluation showing the performance of DEFP over the state-of-the-art approach [16]. Fig. 1 shows a simplified version of function aoc_s_event in project Asterisk 1 , the complete version can be found on our website [21]. In this example, a warning related to Buffer Overflow (BO) is reported at line 24 by Flawfinder [22], a static analysis tool. The reason is that strcat appends the string pointed by rate_str to the end of prefix. This could cause the size of the resulting string stored in prefix to be greater than 32 which is the prefix's size of allocated memory (line 15).

II. MOTIVATING EXAMPLE AND GUIDING PRINCIPLES A. Motivating Example
However, via inter-procedure analysis, we can conclude that this warning is an FP. Specially, at line 19 in Fig. 1, prefix is set to be R(i) where i is the index of the loop, and the maximum size of prefix after this statement is 13, in the case of i = IN T M AX (i.e., 2,147,483,647). At line 23, prefix is appended a character (i.e., "/"), and then at line 24 it is appended a string pointed by rate_str, which has length 8 (rate_str = "Duration", line 20 and line 6). As a result, after line 24, the maximum length of prefix is 22, which is still much smaller than 32. Therefore, in order to determine whether a warning is a TP or FP, it need to conduct not only intra-procedure analysis but also interprocedure analysis. In other words, simply approximating the context of a warning by its surrounding statements or by its containing function could be ineffective.

B. Guiding Principles
In order to determine whether a SA warning is a TP or FP, analyzing only the reported statement is not enough. It requires investigating the context of the warning as well. For example, to conclude the warning at line 24 in Fig. 1 is an FP, not only that statement but also the related statements such as lines 18, 19, 20, etc. need to be examined. Therefore, to build an ML model which can effectively predict the likelihoods to be TP/FP of the warnings, for each warning, we need to extract its appropriate context in the program. From the extracted contexts, the model can capture patterns associated with the warnings. Also, statements unrelated to the warning, which might cause noises and negatively affect the performance of the model, should be excluded from the warning context. In this paper, we propose the following principles for the problem of ranking SA warnings by representation learning.
P1. The warning contexts can be semantically captured by the statements in the program which can impact and be impacted by the reported statements. In practice, to determine whether a warning indicates an actual violation of a specific vulnerability type or not, it is necessary to investigate all of the feasible execution paths containing the reported statement. In other words, we need to examine the control flows and data flows of the program which contain the reported statement. Besides, functions in a program do not work independently, they often execute with the invocations of the others. Thus, inter-procedural analysis is essential to effectively capture the contexts of the warnings. Simply, all the statements in the functions/programs can be considered as the warning contexts, however, this method can cause unnecessarily large contexts and negatively affect the ML model's predictive performance. Also, not all of the statements in the functions/programs are actually relevant to the warnings. For example, the statement at line 17 in Fig. 1 does not affect the decision about TP or FP of the warning at line 24. Including such irrelevant statements may cause the ML model to falsely learn the actual patterns associated with TPs/FPs. Therefore, inter-procedural slicing techniques [23] can be applied to effectively extract the warning contexts by statements semantically related to the reported statements and eliminate the irrelevant statements.
P2. The reported statements should be highlighted compared to the other statements in the warning contexts. Intuitively, not all the statements in the program slices are equally important regarding the considering warnings. The reported statements are where the vulnerabilities are potentially explored, thus, they should be highlighted compared to the other statements in their contexts. For example in Fig. 1, the statements at lines 19, 23, and 24, which all modify the value of prefix, are all necessary for investigating the warning. However, according to the report of Flawfinder, the BO vulnerability is potentially explored at line 24, which appends prefix by an unknown size string, i.e., a string is returned by another function. Intuitively, the statement at line 24 should be emphasized compared to statements at lines 19 and 23. Moreover, in practice, a program slice could contain several warnings, therefore to distinguish warnings, not only the program slices (i.e. context of the warnings) but also the reported statements need to be featurized.
P3. Identifiers should be abstracted. The reason is that identifiers such as variables, function names, constants are projectspecific (or even file-specific/function-specific) and considerably vary regarding developers' coding style. By learning such specific information, the ML model could not capture general patterns of the warnings. Also, this could make the models simply learn the connections between specific identifiers and warning labels (TP/FP). Consequently, the models accurately predict the warnings of several training programs but their performance might decrease dramatically on the different programs. Therefore, to build a general ML model which can work well and stably across programs, the identifiers should be abstracted into symbolic names, for example, VAR1, FUNC1, etc. Moreover, without abstraction, the number of identifiers could be virtually infinite, so ML model could have to deal with the vocabulary explosion problem. Fig. 2 illustrates our SA warning ranking approach. Particularly, from the source code and the set of warnings of the analyzed program, we extract the reported statements and their program slices associated with warnings. For each warning, the reported statement and the corresponding program slice are converted into vectors and then fed to the BiLSTM models to predict its likelihood to be TP. After that, all of the warnings of the program are ranked according to their predicted scores.

A. Program Slice Extraction
In this work, to capture the context of each warning, we extract all the statements in the program which impact and are impacted by the corresponding reported statement. Specially, starting from the reported statement, we employ Joern [24] to conduct both backward and forward inter-procedural slicing in the program. For instance, the context of the warning at line 24 in Fig. 1 is captured by the program slice shown in Fig. 3. Therefore, by this approach, not only a large number of irrelevant statements in the program are removed, but also the warning contexts are precisely captured via control/data dependencies relationship throughout the program.

B. Input Vectorization
Program slices and reported statements are lexical source code tokens. Meanwhile, neural network models require their inputs to be formalized as numeric vectors. Therefore, we need to represent the model input data by a suitable data structure. In this section, we show three steps to represent the program slice and the reported statement of each warning: identifier abstraction, tokenization, and vectorization.
1) Identifier Abstraction: In general, programs often contain a huge number of identifiers, also their naming conventions and styles are diverse. It could cause difficulties for the ML models to capture the general patterns of the warnings [20]. Besides, ML models would simply learn characteristics of identifiers in certain projects, as well as simply map specific identifiers with corresponding warning labels. In order to avoid this problem, DEFP abstracts all the identifiers before feeding them to the models. In particular, variables, function names, and constants in the extracted program slices are replaced by common symbolic names. For example, function name aoc_s_event is replaced by FUNC1, the array prefix is replaced by VAR5, and its allocated size 32 is replaced by NUMBER_LIT. The details of our rules for abstracting identifiers can be found on our website [21].
2) Tokenization: To represent in numeric vectors for feeding to the neural network models, both the extracted program slices and the reported statements are tokenized into sequences of tokens. In this work, we use lexical analysis to break down each code statement into code tokens, which including identifiers, keywords, punctuation marks, and operators. For instance, the statement at line 24 in Fig. 1, strcat(prefix, rate_str);, is abstracted  as strcat(VAR8, VAR11); and then it is tokenized into seven separated tokens: "strcat", "(", "VAR8", ",", "VAR11", ")" and ";".
3) Padding and Truncation: In practice, the number of sequence tokens in different slices could be significantly different. For example, in our experiment, the sequence lengths can vary from 5 to 9,566 code tokens. Therefore, to ensure that all the sequences have the same length, L, before inputting to the neural network, we use padding and truncation techniques. To achieve the best performance, the fixed length L is carefully selected via multiple experiments.
Particularly, for sequences having lengths smaller than L, we add one or more special tokens (<pad>) at the end of these sequences. For the sequences whose lengths are greater than L, we truncate them to fit the fixed length.
In practice, the positions of the reported statements in their corresponding slices significantly vary. They can appear at the beginning of the slices or at the end of the slices. Thus, truncating from either the beginning or the end of the sequences could lead to the cases that the statements containing warnings are missed in the truncated sequences. Therefore, in order to guarantee that the truncated sequences always contain the reported statements, we take these statements as the center for truncating. Specially, from the reported statements, we extend to both sides of the sequences. until reach the fixed length L. Importantly, to capture the correct semantics of each code statement, we ensure that a statement will be fully included in the truncated sequences. It means that when only some tokens of a statement are included in the truncated sequences and the remaining is left due to the length limitation, we will replace all of the tokens of that statement in the truncated sequence by (<pad>) token. 4) Vectorization: In this step, the token sequences are embedded into numeric fixed-length vectors. In practice, besides the structural information of the sequences which need to be The reason is that code tokens have to appear together in a certain order to make the program grammatically and syntactically correct [25]. For this purpose, in the vectorization step, we use Word2vec model [17] with Continuous Bag-of-Words (CBOW) architecture.

C. Representation Learning and Warning Ranking
The DEFP's model architecture is shown in Fig. 4. Especially, to effectively learn contextual information that is crucial for revealing TP/FP code patterns, two Bidirectional Long Short-Term Memory networks (BiLSTM) [26] are employed to train on the embedding vectors of the program slices and the reported statements. Afterwards, DEFP extracts the meaningful characteristics of related warnings by concatenating the outputs from these BiLSTM models and feed into Fully Connected layers. In particular, we consider the final layer's output of the model as the likelihood to be TP/FP of each input warning. All these scores are finally gathered by DEFP and ranked accordingly.
1) Representation Learning: In this work, the warning contexts (i.e. program slices) and the reported statements are encoded by two BiLSTM networks. In the case of program slices containing multiple statements distributed across functions, LSTM architecture might essentially apprehend the relationships between code tokens. Additionally, by utilizing a gated mechanism, LSTM can handle long-term dependencies and also focus on the most significant parts of the sequences.
However, the information in LSTM is expressed one way through continuous time steps in sequential order. Meanwhile, the occurrence of a code token is usually related to either the previous or the subsequent tokens, or even both. Thus, additionally applying the bidirectional implementation of LSTM can assist the model to build dependencies in both forward and backward directions, which efficiently captures the general pattern of warnings.
DEFP also employs the Global Max Pooling (GMP) layer to accumulate the output of each BiLSTM network. Especially, GMP layer computes maximum values over LSTM's time steps, which help to reduce output dimension and only keep the most important elements from LSTM cells. As a result, DEFP has two GMP layers following each BiLSTM network, and then they are concatenated into a unified one to represent a whole feature map (Fig. 4).
2) Warning Ranking: After obtaining the learned representations of the warnings, DEFP distinguishes their patterns by feeding them into three Fully Connected (Dense) layers behind. Particularly, the final layer has only two hidden units activated by the Softmax function, which produces two scores whose total is 1.0. These two values correspond to the likelihoods of each warning to be TP and FP, respectively.
In the training phase, DEFP's neural network enhances its predictions by finding the best hidden weights through estimating its errors. In other words, an objective function, crossentropy, is applied to calculate the model's loss and update the weights towards minimizing this error value. Consequently, in the case of a TP warning, the model tends to converge its TP score towards 1.0 and its FP score closes to 0.0, and vice versa for an FP warning. In the ranking phase, by inputting a list of warnings, DEFP directly calculates their TP scores and sorts them in descending order.

IV. EMPIRICAL METHODOLOGY
In order to evaluate DEFP, we seek to answer the following research questions:
they only contain simple examples which are artificially created from known vulnerable patterns. Thus, the patterns which the ML models capture from these datasets could not reflect the real-world scenarios [20]. To evaluate our solution and the others on real-world data, we construct a dataset containing 6,620 warnings in 10 open-source projects [27], [28]. Table I shows the overview of our dataset. In these 10 real-world projects, functions are previously manually labeled as vulnerable and non-vulnerable [27], [28]. Then, our dataset is constructed by the following steps: 1) Since, these functions are already marked as clean regarding BO and/or NPD, thus all the corresponding warnings in these functions are annotated as FPs. 3) Labeling warnings in the vulnerable functions: Although these functions are marked containing BO and/or NPD vulnerabilities, we do not know exactly how many vulnerabilities each function contains and the positions of the vulnerabilities in the source code. Therefore, for each of the warnings in these functions, we manually investigate to label whether it is a TP or FP.
B. Evaluation Setup, Procedure, and Metrics 1) Experimental Setup: We implemented neural network models using Keras together with TensorFlow backend (version 2.5.0). The tokenizer was built upon NLTK library (version 3.6.2) and Word2vec embedding model was provided by the gensim package (version 3.6.0). All experiments were computed by a server running Ubuntu 18.04 with an NVIDIA Tesla P100 GPU.
We adopt cross-validation to train several neural networks and select the best parameter values corresponding to the effectiveness of predicting likelihoods to be TP warnings in the proposed dataset. Specially, for DEFP, embedding size are set to 96, the maximum length of each slice and reported statement is fixed to 600 and 40, respectively, and they are learned by two BiLSTM networks which each has 256 hidden nodes. During the training phase, the dropout, batch size, and number of epochs is set to 0.1, 64 and 60, respectively. Also, the minibatch stochastic gradient descent ADAMAX optimizer is selected with the learning rate of 0.002.
Besides, the data is sampled into stratified 5 folds, while 4 folds are picked for training and 1 remaining fold for testing (ratio of 8:2). We then run 5 different experiments on 5 pairs of training and testing data and aggregate average results for the final assessment of the corresponding experiment.
2) Empirical Procedure: RQ1. We compare the performance of DEFP and the CNN model proposed by Lee et al. [16] for ranking warnings in the proposed dataset.
RQ2. We study the impact of the warning contexts on the performance of DEFP. Specially, we compare the performance of DEFP in four scenarios of the warning contexts: (1) the raw code of the program, (2) the program slices on control dependencies, (3) the program slices on data dependencies, and (4) the program slices on both control and data dependencies.
RQ3. We study the impact of highlighting the reported statements on DEFP's performance. We compare the ranking results of DEFP in two scenarios when the reported statements are and are not encoded for training the BiLSTM model.
RQ4. We study the impact of the identifier abstraction component by comparing the performance of DEFP when the inputs are embedded with and without this component.
For evaluation, we have two experimental settings as widely adopted in related studies [27], [28], [31]: within-project setting and combined-project setting. First, in within-project setting, warnings from the same project are split into training and testing sets. Second, in combined-project setting, we collect the warnings from all 10 projects and then split them into training and testing sets. In practice, in several projects, the number of warnings is quite small for training and testing an ML model, and it could cause overfitting or underfitting problems. Thus, we only select three projects which have the largest number of BO warnings for evaluating RQ1 in the corresponding vulnerability type in the within-project setting. RQ1 in the NPD vulnerability and the other research questions are only evaluated in the combined-project setting.
3) Evaluation Metrics: In order to evaluate DEFP and compare its performance with the state-of-the-art approach, we applied Top-k% Precision (P@K) and Top-k% Recall (R@K). These two metrics are widely used in related studies [28], [32], especially when the dataset is severely imbalanced. In this paper, P@K denotes the proportion of actual TP warnings in the Top-k% of warnings ranked by the model, and R@K refers to the proportion of correctly predicted TP warnings in Top-k% among the total actual TPs warnings. In particular,  Table II shows the performance of DEFP and the CNN model proposed by Lee et al. [16] in Top-5%-Top-60% warnings of the ranked lists. Overall, DEFP improves their model by nearly 30% in Precision and Recall for both BO and NPD warnings. For example, in FFmpeg, Qemu, and Asterisk with the Top-20% of warnings returned by DEFP, developers can find 23/79, 24/77, and 9/13 actual vulnerabilities. Meanwhile, by using the CNN model [16], the corresponding figures are only 16/79, 15/77, and 6/13, respectively. When the warnings of all the projects are combined, by investing 20% of the warnings in the top of the ranked list, 105/202 actual BO vulnerabilities and 12/18 actual NPD vulnerabilities can be found by DEFP, while these figures for the CNN model are only 82/202 and 10/18, respectively. Interestingly, with the results of DEFP, developers can find +90% of actual vulnerabilities by investigating only 60% of the total warnings, which is 8% better than the CNN model.

A. Performance Comparison (RQ1)
Indeed, DEFP obtains better results because it concentrates on statements which semantically describe the contexts of the warnings and DEFP is not negatively affected by the statements which are unrelated to the warnings. For example, the warning in Fig. 1, DEFP captures its context by the statements which impact and are impacted by the reported statement at line 24 as shown in Fig 3. These statements are essential for semantically capturing the context of the warning because they show when and how the value of prefix, which is reported to potentially overflow, is changed. Additionally, unlike the CNN model [16], DEFP ignores statements at lines 17 and 26, which do not play any role in reflecting the violation of the reported statement, although they are near it. Therefore, they could cause noises if they are encoded as the context of the warning.
In addition, by inter-procedural analysis, DEFP does not miss important information to validate the violation of the reported statements. Specially, there are statements, which are essential for validating the warnings, could be in multiple functions. For example in Fig 1, the statement at line 6 specifying the concatenated string to prefix is extremely important to determine whether the BO vulnerability could occur at line 24 or not. However, this statement is not in the same function with the reported statement, yet in another function aoc_rate_type_str. This statement is captured by DEFP, but it will be missed if only intra-procedural analysis is considered.
Interestingly, among the studied projects, DEFP achieved the highest results in Qemu and the lowest results in Asterisk. Specially, for Top-20% warnings of Qemu, DEFP obtained 65.14% in Precision, whereas this figure of Asterisk is only 10.73%. The reason is that the models are impacted by the imbalance of the dataset. For instance, the numbers of TPs and FPs in Qemu are quite balanced, while they are greatly imbalanced in Asterisk. Moreover, Asterisk only contains 63 TPs, which is extremely small compared to its 1986 FPs.
B. Impact of the Warning Context (RQ2) Fig. 5 shows the performance of DEFP when the contexts of the warnings are captured by different kinds of dependencies. DEFP obtains the best performance when the warning contexts are captured by both control and data dependencies on the PDG. The reason is that, by using slicing techniques on both of these dependencies, unrelated statements are removed from the warnings' contexts and only related statements are encoded and fed to the BiLSTM models. Therefore, the models can better capture the patterns of warnings without being affected by noises caused by the statements which are semantically unrelated to the warnings. In particular, when program slices are conducted on both control and data dependencies, the performance of DEFP in two studied vulnerability types is 16% and 19% better than when the warning contexts captured Importantly, for both BO and NPD vulnerabilities, program slices on only data dependencies capture the warning contexts better than the raw code of functions, however, the program slices on only control dependencies do worse. The reason is that for these two kinds of vulnerabilities, the information about data dependencies, which illustrates how the values of the variables are propagated, is more informative for reasoning the warnings. For example in Fig. 1, to determine whether the warning (line 24) is an FP, it is essential to analyze the statements which have data-dependent on, such as lines 6, 15, 19, etc. Although the raw code may contain noises and unrelated statements, it still contains all of this information. However, this important information is missed in the program slices on control dependencies only. Therefore, the performance of DEFP with raw code is worse than the program slices on data dependencies, yet better than the program slices on control dependencies. Specifically for Top-1%-Top-60% of warnings, compared to the raw code, DEFP's results with program slices on the data dependencies is 7% and 29% better for BO and NPD. Also, compared to the program slices on the control dependencies, these figures are 8% and 46%, respectively.
In practice, for different kinds of vulnerabilities, it could require control or data dependencies or both of these two  Fig. 6: Impact of highlighting the reported statements on the performance of DEFP kinds of information for validating the warnings. Therefore, to guarantee the best performance of DEFP, program slices on both control and data dependencies should be leveraged to capture the warning contexts.
C. Impact of the Reported Statements (RQ3) As seen in Fig 6, the performance of DEFP is slightly improved by 4% and 7% for BO and NPD vulnerabilities when the reported statements are highlighted by being encoded as an input of the BiLSTM model. For example, in Top-20% of ranked warnings, by encoding the reported statements, developers can find 7 more actual BO vulnerabilities and 1 more actual NPD vulnerabilities. More details about the performance of DEFP on P@K can be found on our website [21].
Indeed, highlighting the reported statements can help the neural network model not only capture the patterns associated with the warning contexts, but also explicitly emphasize the positions of warnings. Consequently, this would be considerably helpful when several warnings having similar contexts but labeled (TP and FP) differently. However, our dataset is built from the set functions which are already classified as vulnerable or non-vulnerable. Thus, most of the warnings in a vulnerable function tend to have the same TP labels. Also, all of the warnings in a non-vulnerable function are labeled as FPs. That is the reason why the DEFP's performance is just slightly improved when the reported statements are encoded as an input of the representation model.  respectively. More details about the performance of DEFP on P@K can be found on our website [21]. Moreover, identifier abstraction decreases Word2vec vocabulary size on BO and NPD datasets from 37,170 to 512 and 4,094 to 259 tokens, respectively. This helps the model deal with the vocabulary explosion problem, better generalize rare identifiers, and avoid out-of-vocabulary. As well, Word2vec might also beneficially reduce vector dimension to represent each code token, thus improve memory usage and shorten the training/prediction time.

VI. THREATS TO VALIDITY
There are three main threats to validity in this paper, they are external validity, internal validity, and construct validity, respectively, which are illustrated as follows.
1) External validity: Our dataset contains 10 open-source programs and warnings in only two vulnerability types. Therefore, our results may not be general for all software projects and other kinds of vulnerabilities. To reduce the threat, we chose the programs which are widely used in the related work [27], [28] and the top most popular vulnerabilities [33]. Also, we plan to collect more data for the future work.
2) Internal validity: For this paper, the internal validity mainly lies in the data used for learning process. We manually labeled for the warnings based on the labels of the functions, which are assigned by Zhou et al. [27] and Lin et al. [28]. The threat may come from their incorrect labels at function level or our misleading labels at warning level. To minimize this threat, we carefully investigate to label the warnings.
3) Construct validity: In this study, we adopt P@K and R@K for evaluating the performance of the ranking models. However, with the problem of handling SA warnings, evaluation in terms of other metrics may also require in practice. We will conduct experiments using more evaluation measures in our future work.

VII. RELATED WORK
There are various approaches have been applied to detect source code vulnerabilities in the early phases of the software development process. Specially, using SA tools is an automatic and simple way to detect various kinds of vulnerabilities without executing the programs [1], [2]. Baca et al. [34] has demonstrated that SA tools is better than average developers in detecting warnings, especially the security ones. However, the generated warnings of SA tools often contain a high number of FP rate [7], [8]. Therefore, developers still need to waste a lot of time and effort for investing such FP warnings.
In order to improve the precision of SA tools, sophisticated program verification techniques such as model checking, symbolic execution, or deductive verification, etc., have been applied to reduce the number of FPs [10]- [12], [35], [36]. For instance, Muske et al. [35], [36] uses model checking to eliminate FPs. Specially, for each warning, they generate appropriate assertions and then use model checking to verify whether those assertions hold. Nguyen et al. [12] also generate proper annotations to describe the verified properties of the warnings and then prove them by deductive verification. These approaches can precisely discard a number of FPs. However, not all of the generated warnings can be formally proved to be FPs or TPs by these approaches. Additional, model checking approaches also suffer from the enormous states space, which affect their performance and lead them to be non-scalable.
In addition, several studies applied ML models to address SA warnings. Specially, some research [6], [14], [15] propose sets of features about statistic information of the warnings and then build a model which learn these features to classify SA warnings. However, these features are manually defined based on the dataset and the used SA tools. This process is errorprone even for experts. Meanwhile, instead of using a fixed set of features, Lee et al. [16] trained a CNN model classifying warnings based on features which are learned from lexical patterns in source code. However, they manually defined different contexts for different kinds of warnings based on their dataset. This limits the adaptation of their approach for other kinds of vulnerabilities and different dataset. In this paper, we propose an approach which can be fully automated and easily to adapt for handling different warnings in different projects. Specially, our models are trained to capture the patterns associated with the warnings in their corresponding contexts, which are extracted by inter-procedural slicing techniques.
Moreover, ML are also actively adopted in vulnerabilities detection. Particularly, to leverage the syntax and semantics information presented in the Abstract Syntax Tree, Dam et al. [31] proposed a deep learning tree based model to predict whether a source file is clean or defective. Besides, there are multiple studies also propose token-based models [37], [38] or graph-based models [20], [27] to predict whether a function containing vulnerabilities. However, these research focuses on detecting vulnerabilities at the file level or function level, which are quite coarse-grained in granularity. Developers still need to investigate the whole source code in the detected files or functions to localize the vulnerabilities. In this research, our objective is more fine-grained in granularity. We focus on ranking the warnings which are reported by SA tools. With the resulting lists, developers can decide which vulnerabilities should be investigated and fixed in a given a amount of time.

VIII. CONCLUSION
SA tools have demonstrated their usefulness in detecting potential vulnerabilities. However, these tools often report a large number of warnings containing both TPs and FPs, which causes time-consuming for post-handling warnings and affects the productivity of developers. In this paper, we introduce DEFP, a novel method for ranking SA warnings. Based on the reported statements and the corresponding warning contexts, we train two BiLSTM models to capture the patterns associated with the TPs and FPs. After that, for a set of new warnings, DEFP can predict the likelihood to be TP of each warning and then rank them according to the predicted scores. By using DEFP, more actual vulnerabilities can be found in a given time. In order to evaluate the effectiveness of DEFP, we conducted experiments on 6,620 warnings in 10 real-world projects. Our experimental results show that using DEFP, developers can find +90% of actual vulnerabilities by investigating only 60% of the total warnings.