Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313270 - rename refactoring does not work on va_list local variables
Summary: rename refactoring does not work on va_list local variables
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 7.0   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 7.0   Edit
Assignee: Markus Schorn CLA
QA Contact: Emanuel Graf CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-17 21:51 EDT by Matt Hargett CLA
Modified: 2010-05-27 09:28 EDT (History)
1 user (show)

See Also:


Attachments
parser log for code with issue (15.13 KB, text/plain)
2010-05-19 19:15 EDT, Matt Hargett CLA
no flags Details
my eclipse project where renaming a function local va_list variable does a global function rename instead (1.41 MB, application/octet-stream)
2010-05-21 18:39 EDT, Matt Hargett CLA
no flags Details
testcase + fix (4.74 KB, patch)
2010-05-26 04:13 EDT, Markus Schorn CLA
mschorn.eclipse: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.