Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 313270

Summary: rename refactoring does not work on va_list local variables
Product: [Tools] CDT Reporter: Matt Hargett <matt>
Component: cdt-parserAssignee: Markus Schorn <mschorn.eclipse>
Status: RESOLVED FIXED QA Contact: Emanuel Graf <emanuel>
Severity: major    
Priority: P3 CC: yevshif
Version: 7.0   
Target Milestone: 7.0   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
parser log for code with issue
none
my eclipse project where renaming a function local va_list variable does a global function rename instead
none
testcase + fix mschorn.eclipse: iplog-

Description Matt Hargett CLA 2010-05-17 21:51:10 EDT
Build Identifier: 7.0.0.201005161106

Trying to rename a local variable with the va_list type (from stdarg.h) results in a "global function" rename operation, where all variables with that name being part of the rename target.

Reproducible: Always

Steps to Reproduce:
1. create a new C++ source file with this code:
#include <stdarg.h>
#include <stdio.h>

void foo(const char* name, ...) {
	va_list result;
	va_start(result, name);

	printf("%d\n", (intptr_t)(va_arg(result, intptr_t)));

	va_end(result);
}


int main() {
	foo("number", 2, 3, 4);

}

void bar() {
	int result = 1;
	printf("%d\n", result);
}

2. select the result variable in function foo()
3. hit alt+shift+r, enter "result2" for the new name, press enter to preview
4. press enter to continue

result:
in the changes to be performed, it includes both the local variables in the foo() and the bar() functions both named result. in a large project, this resulted in hundreds of candidates.

expected result:
should only see the local variable's context as candidate for the rename refactoring.
Comment 1 Markus Schorn CLA 2010-05-18 02:36:03 EDT
This works for me, please provide a parser log for the file:
Context menu of file in project explorer - Index - Create Parser Log.
Comment 2 Matt Hargett CLA 2010-05-19 19:14:51 EDT
attached the parser log for the code below. odd that the log says it can't resolve printf and intptr_t -- I can control click on them, and they go to the correct header files that are explicitly included. re-ordering the header includes doesn't fix that problem. Note that this is on Ubuntu 10.04, x86-64. I just installed the latest CDT build (201005191123) and still get the same results.

#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>

void foo(const char* name, ...) {
	va_list result;
	va_start(result, name);

	printf("%d\n", (intptr_t)(va_arg(result, intptr_t)));

	va_end(result);
}


int main() {
	foo("number", 2, 3, 4);

}

void bar() {
	int result = 1;
	printf("%d\n", result);
}
Comment 3 Matt Hargett CLA 2010-05-19 19:15:41 EDT
Created attachment 169243 [details]
parser log for code with issue
Comment 4 Markus Schorn CLA 2010-05-20 07:45:38 EDT
(In reply to comment #3)
> Created an attachment (id=169243) [details]
> parser log for code with issue

From the parser log it looks like the parser does not know 'intptr_t'. But even with that the rename works for me. 
To figure out what causes the issue, please try to do the refactoring with the self contained code below (it should work). Then replace e.g. 'typedef int intptr_t' with '#include <stdint.h>' or with whatever you find in stdint.h and check again.

// self contained example.

typedef int intptr_t;
int printf (const char*, ...);
void foo(const char* name, ...) {
	__builtin_va_list result;
    __builtin_va_start(result, name);

    printf("%d\n", (intptr_t)(__builtin_va_arg(result, intptr_t)));

    __builtin_va_end(result);
}

int main() {
    foo("number", 2, 3, 4);

}

void bar() {
    int result = 1;
    printf("%d\n", result);
}
Comment 5 Matt Hargett CLA 2010-05-21 18:37:48 EDT
With a brand new, empty project, it works.

In my cgreen project, it doesn't. I'm attaching an archive of the cgreen project. The eclipse project file (as generated by CMake) is src/cgreen-build/.project.
Comment 6 Matt Hargett CLA 2010-05-21 18:39:40 EDT
Created attachment 169565 [details]
my eclipse project where renaming a function local va_list variable does a global function rename instead
Comment 7 Markus Schorn CLA 2010-05-25 10:28:55 EDT
Thanks, I can reproduce the issue.
Comment 8 Markus Schorn CLA 2010-05-26 04:13:58 EDT
Created attachment 169942 [details]
testcase + fix
Comment 9 Markus Schorn CLA 2010-05-26 04:14:49 EDT
Fixed in 7.0 > 20100526.